LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LengthUnit Class Referencefinal

The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful methods to make the life easier. More...

#include <lengthunit.h>

+ Collaboration diagram for LengthUnit:

Public Member Functions

 LengthUnit () noexcept
 Default constructor which uses millimeters as unit. More...
 
 LengthUnit (const LengthUnit &other) noexcept
 Copy constructor. More...
 
 ~LengthUnit () noexcept
 Destructor. More...
 
int getIndex () const noexcept
 Get the Index of the length unit of this object. More...
 
QString toStr () const noexcept
 Serialize this object into a string. More...
 
QString toStringTr () const noexcept
 Convert the length unit to a localized string. More...
 
QString toShortStringTr () const noexcept
 Convert the length unit to a localized string (short form) More...
 
qreal convertToUnit (const Length &length) const noexcept
 Convert a Length to this length unit. More...
 
QPointF convertToUnit (const Point &point) const noexcept
 Convert a Point to this length unit. More...
 
Length convertFromUnit (qreal length) const noexcept
 Convert a floating point number with this unit to a Length object. More...
 
Point convertFromUnit (const QPointF &point) const noexcept
 Convert floating point numbers with this unit to a Point object. More...
 
LengthUnitoperator= (const LengthUnit &rhs) noexcept
 
bool operator== (const LengthUnit &rhs) noexcept
 

Static Public Member Functions

static LengthUnit fromIndex (int index)
 Get the length unit of a specific index (to use with getIndex()) More...
 
static QList< LengthUnitgetAllUnits () noexcept
 Get all available length units. More...
 
static LengthUnit millimeters () noexcept
 
static LengthUnit micrometers () noexcept
 
static LengthUnit nanometers () noexcept
 
static LengthUnit inches () noexcept
 
static LengthUnit mils () noexcept
 

Private Types

enum  LengthUnit_t
 An enum which contains all available length units. More...
 

Private Member Functions

 LengthUnit (LengthUnit_t unit) noexcept
 Private Constructor to create a LengthUnit object with a specific unit. More...
 

Private Attributes

LengthUnit_t mUnit
 Holds the length unit of the object. More...
 

Detailed Description

The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful methods to make the life easier.

With this class, lengths (#Length) and points (#Point) can be converted to other units.

Note
Please note that the classes #Length and #Point do not need a length unit as they represent the values always in nanometers! The class LengthUnit is only needed to show these values in the unit which the user wants, and provides some useful methods to do this.
Warning
It's possible to convert lengths and points between all available units. But as the converting methods convertFromUnit() and convertToUnit() work always with floating point numbers, there is a little risk that the conversion is not lossless! Example: If you begin with 1mm and convert via other units back to millimeters, you may get 0,999mm or 1,001mm as result. So be careful on converting lengths and points between different units!
Author
ubruhin
Date
2014-10-07

Member Enumeration Documentation

enum LengthUnit_t
strongprivate

An enum which contains all available length units.

The enum items should be sorted (not alphabetical but by meaning) because the enum order will also define the order of these units in comboboxes and other lists/widgets.

Warning
The enum must begin with value 0 and end with _COUNT. Between these values the enum must not contain unused indexes! This is neccessary for getIndex() and fromIndex().
Enumerator
Millimeters 
Micrometers 
Nanometers 
Inches 
Mils 
_COUNT 

count of units, must be the last entry of the enum

Constructor & Destructor Documentation

LengthUnit ( )
inlinenoexcept

Default constructor which uses millimeters as unit.

+ Here is the caller graph for this function:

LengthUnit ( const LengthUnit other)
inlinenoexcept

Copy constructor.

Parameters
otherAnother LengthUnit object
~LengthUnit ( )
inlinenoexcept

Destructor.

LengthUnit ( LengthUnit_t  unit)
inlineexplicitprivatenoexcept

Private Constructor to create a LengthUnit object with a specific unit.

Parameters
unitThe length unit of the new object

Member Function Documentation

int getIndex ( ) const
inlinenoexcept

Get the Index of the length unit of this object.

This method is useful in combination with getAllUnits() to create lists of all available length units (QListWidget, QComboBox, ...). With this method you are able to get the index of this unit in the QList returned by getAllUnits().

Warning
The index of an unit can change between different application versions! So you must never save/load such an index to/from files. Use #toString() and #fromString() instead for this purpose.
Returns
The index
See Also
fromIndex(), getAllUnits()

+ Here is the caller graph for this function:

QString toStr ( ) const
noexcept

Serialize this object into a string.

Returns
This object as a string

+ Here is the caller graph for this function:

QString toStringTr ( ) const
noexcept

Convert the length unit to a localized string.

This method uses the application's locale settings to translate the name of the length unit to the user's language.

Returns
The unit as a localized string (like "Millimeters" or "Millimeter")

+ Here is the caller graph for this function:

QString toShortStringTr ( ) const
noexcept

Convert the length unit to a localized string (short form)

Returns
The unit as a localized short string (like "mm", "μm" or "″")
qreal convertToUnit ( const Length length) const
noexcept

Convert a Length to this length unit.

This method calls the method Length::to*() (* = the unit of this object)

Parameters
lengthThe length to convert (the Length object will not be modified)
Returns
The specified length in the unit of this object
Warning
As this method always returns a floating point number, there is a little risk that the conversion is not lossless. So be careful with it.

+ Here is the caller graph for this function:

QPointF convertToUnit ( const Point point) const
noexcept

Convert a Point to this length unit.

This method calls the method Point::to*QPointF() (* = the unit of this object)

Parameters
pointThe point to convert (the Point object will not be modified)
Returns
The specified point in the unit of this object
Warning
As this method always returns floating point numbers, there is a little risk that the conversion is not lossless. So be careful with it.
Length convertFromUnit ( qreal  length) const
noexcept

Convert a floating point number with this unit to a Length object.

This method calls the method Length::from*() (* = the unit of this object)

Parameters
lengthA length in the unit of this object
Returns
A Length object with the converted length
Warning
As this method always uses floating point numbers, there is a little risk that the conversion is not lossless. So be careful with it.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Point convertFromUnit ( const QPointF &  point) const
noexcept

Convert floating point numbers with this unit to a Point object.

This method calls the method Point::from*() (* = the unit of this object)

Parameters
pointA point in the unit of this object
Returns
A Point object with the converted point
Warning
As this method always uses floating point numbers, there is a little risk that the conversion is not lossless. So be careful with it.

+ Here is the call graph for this function:

LengthUnit fromIndex ( int  index)
static

Get the length unit of a specific index (to use with getIndex())

Parameters
indexThe index of the unit in the list of getAllUnits(). This number equals to the number returned by getIndex().
Returns
The LengthUnit object with the specified index
Exceptions
ExceptionIf index was invalid
See Also
getIndex(), getAllUnits()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

QList< LengthUnit > getAllUnits ( )
staticnoexcept

Get all available length units.

This method returns a list of all available length units. The index of the objects in the list equals to the value from getIndex() of them.

Returns
A list of all available length units
See Also
getIndex(), fromIndex()

+ Here is the caller graph for this function:

static LengthUnit millimeters ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LengthUnit micrometers ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LengthUnit nanometers ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LengthUnit inches ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static LengthUnit mils ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

LengthUnit& operator= ( const LengthUnit rhs)
inlinenoexcept
bool operator== ( const LengthUnit rhs)
inlinenoexcept

Member Data Documentation

LengthUnit_t mUnit
private

Holds the length unit of the object.


The documentation for this class was generated from the following files: