LibrePCB Developers Documentation

The Length class is used to represent a length (for example 12.75 millimeters) More...
#include <length.h>
Public Member Functions  
constexpr  Length () noexcept 
Default Constructor. More...  
constexpr  Length (const Length &length) noexcept 
Copy Constructor. More...  
constexpr  Length (LengthBase_t nanometers) noexcept 
Constructor with length in nanometers. More...  
~Length ()=default  
Destructor. More...  
void  setLengthNm (LengthBase_t nanometers) noexcept 
Set the length in nanometers. More...  
void  setLengthMm (qreal millimeters) 
Set the length in millimeters. More...  
void  setLengthMm (const QString &millimeters) 
Set the length in millimeters, represented in a QString. More...  
void  setLengthInch (qreal inches) 
Set the length in inches. More...  
void  setLengthMil (qreal mils) 
Set the length in mils (1/1000 inch) More...  
void  setLengthPx (qreal pixels) 
Set the length in pixels (from QGraphics* objects) More...  
LengthBase_t  toNm () const noexcept 
Get the length in nanometers. More...  
QString  toNmString () const noexcept 
Get the length in nanometers as a QString. More...  
qreal  toMm () const noexcept 
Get the length in millimeters. More...  
QString  toMmString () const noexcept 
Get the length in millimeters as a QString. More...  
qreal  toInch () const noexcept 
Get the length in inches. More...  
qreal  toMil () const noexcept 
Get the length in mils (1/1000 inches) More...  
qreal  toPx () const noexcept 
Get the length in pixels (for QGraphics* objects) More...  
Length  abs () const noexcept 
Get a Length object with absolute value (mNanometers >= 0) More...  
Length &  makeAbs () noexcept 
Make the length absolute (mNanometers >= 0) More...  
Length  mappedToGrid (const Length &gridInterval) const noexcept 
Get a Length object which is mapped to a specific grid interval. More...  
Length &  mapToGrid (const Length &gridInterval) noexcept 
Map this Length object to a specific grid interval. More...  
Length  scaled (qreal factor) const noexcept 
Get a Length object which is scaled with a specific factor. More...  
Length &  scale (qreal factor) noexcept 
Scale this Length object with a specific factor. More...  
Length &  operator= (const Length &rhs) 
Length &  operator+= (const Length &rhs) 
Length &  operator= (const Length &rhs) 
Length &  operator*= (const Length &rhs) 
Length &  operator*= (LengthBase_t rhs) 
Length &  operator/= (const Length &rhs) 
Length &  operator/= (LengthBase_t rhs) 
Length  operator+ (const Length &rhs) const 
Length  operator () const 
Length  operator (const Length &rhs) const 
Length  operator* (const Length &rhs) const 
Length  operator* (LengthBase_t rhs) const 
Length  operator/ (const Length &rhs) const 
Length  operator/ (LengthBase_t rhs) const 
Length  operator% (const Length &rhs) const 
constexpr bool  operator> (const Length &rhs) const 
constexpr bool  operator> (LengthBase_t rhs) const 
constexpr bool  operator< (const Length &rhs) const 
constexpr bool  operator< (LengthBase_t rhs) const 
constexpr bool  operator>= (const Length &rhs) const 
constexpr bool  operator>= (LengthBase_t rhs) const 
constexpr bool  operator<= (const Length &rhs) const 
constexpr bool  operator<= (LengthBase_t rhs) const 
constexpr bool  operator== (const Length &rhs) const 
constexpr bool  operator== (LengthBase_t rhs) const 
constexpr bool  operator!= (const Length &rhs) const 
constexpr bool  operator!= (LengthBase_t rhs) const 
Static Public Member Functions  
static Length  fromMm (qreal millimeters, const Length &gridInterval=Length(0)) 
Get a Length object with a specific length and map it to a specific grid. More...  
static Length  fromMm (const QString &millimeters, const Length &gridInterval=Length(0)) 
Get a Length object with a specific length and map it to a specific grid. More...  
static Length  fromInch (qreal inches, const Length &gridInterval=Length(0)) 
Get a Length object with a specific length and map it to a specific grid. More...  
static Length  fromMil (qreal mils, const Length &gridInterval=Length(0)) 
Get a Length object with a specific length and map it to a specific grid. More...  
static Length  fromPx (qreal pixels, const Length &gridInterval=Length(0)) 
Get a Length object with a specific length and map it to a specific grid. More...  
Private Member Functions  
void  setLengthFromFloat (qreal nanometers) 
Set the length from a floating point number in nanometers. More...  
Static Private Member Functions  
static LengthBase_t  mapNmToGrid (LengthBase_t nanometers, const Length &gridInterval) noexcept 
Map a length in nanometers to a grid interval in nanometers. More...  
static LengthBase_t  mmStringToNm (const QString &millimeters) 
Convert a length from a QString (in millimeters) to an integer (in nanometers) More...  
Private Attributes  
LengthBase_t  mNanometers 
the length in nanometers More...  
Static Private Attributes  
static constexpr LengthBase_t  sNmPerInch = 25400000 
1 inch = 25.4mm More...  
static constexpr LengthBase_t  sNmPerMil = 25400 
1 inch = 25.4mm More...  
static constexpr LengthBase_t  sPixelsPerInch 
72 dpi for the QGraphics* objects More...  
static constexpr qreal  sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch 
static constexpr qreal  sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch 
The Length class is used to represent a length (for example 12.75 millimeters)
This class is used to represent ALL length values in Symbols, Schematics, Footprints, Layouts and so on. You should never use another length type, like integer or float! It's very important to have a consistent length type over the whole project.
All lengths are stored in the integer base type LengthBase_t. The internal unit is always nanometers, but this class provides also some converting methods to other units. Read the documentation of LengthBase_t for more details.

inlinenoexcept 
Default Constructor.
The length will be initialized with zero nanometers.
Copy Constructor.
length  Another Length object 

inlinenoexcept 
Constructor with length in nanometers.
nanometers  The length in nanometers 

default 
Destructor.

inlinenoexcept 
Set the length in nanometers.
nanometers  The length in nanometers 

inline 
Set the length in millimeters.
millimeters  The length in millimeters 
RangeError  If the argument is out of range, a RangeError exception will be thrown 

inline 
Set the length in millimeters, represented in a QString.
millimeters  The length in millimeters in a QString with locale "C" 
Exception  If the string is not valid or the number is out of range, an Exception will be thrown 

inline 
Set the length in inches.
inches  The length in inches 
RangeError  If the argument is out of range, a RangeError exception will be thrown 

inline 
Set the length in mils (1/1000 inch)
mils  The length in mils 
RangeError  If the argument is out of range, a RangeError exception will be thrown 

inline 
Set the length in pixels (from QGraphics* objects)
pixels  The length in pixels, from a QGraphics* object 
RangeError  If the argument is out of range, a RangeError exception will be thrown 

inlinenoexcept 
Get the length in nanometers.

inlinenoexcept 
Get the length in nanometers as a QString.

inlinenoexcept 
Get the length in millimeters.

noexcept 
Get the length in millimeters as a QString.

inlinenoexcept 
Get the length in inches.

inlinenoexcept 
Get the length in mils (1/1000 inches)

inlinenoexcept 
Get the length in pixels (for QGraphics* objects)

noexcept 
Get a Length object with absolute value (mNanometers >= 0)

noexcept 
Make the length absolute (mNanometers >= 0)
Get a Length object which is mapped to a specific grid interval.
gridInterval  The grid interval in nanometers (e.g. 2540000 for 2.54mm). If this parameter is zero, this method will do nothing. 
Map this Length object to a specific grid interval.
gridInterval  The grid interval in nanometers (e.g. 2540000 for 2.54mm). If this parameter is zero, this method will do nothing. 

noexcept 
Get a Length object which is scaled with a specific factor.
factor  The scale factor (1.0 does nothing) 

noexcept 
Scale this Length object with a specific factor.
factor  The scale factor (1.0 does nothing) 
Get a Length object with a specific length and map it to a specific grid.
millimeters  See setLengthMm(qreal) 
gridInterval  See mapToGrid() 
RangeError  If the argument is out of range, a RangeError exception will be thrown 
Get a Length object with a specific length and map it to a specific grid.
This method can be used to create a Length object from a QString which contains a floating point number in millimeters, like QString("123.456") for 123.456 millimeters. The string must not depend on the locale settings (see QLocale), it have always to represent a number in the "C" locale. The maximum count of decimals after the decimal point is 6, because the 6th decimal represents one nanometer.
millimeters  See setLengthMm(const QString&) 
gridInterval  See mapToGrid() 
Get a Length object with a specific length and map it to a specific grid.
inches  See setLengthInch() 
gridInterval  See mapToGrid() 
RangeError  If the argument is out of range, a RangeError exception will be thrown 
Get a Length object with a specific length and map it to a specific grid.
mils  See setLengthMil() 
gridInterval  See mapToGrid() 
RangeError  If the argument is out of range, a RangeError exception will be thrown 
Get a Length object with a specific length and map it to a specific grid.
pixels  See setLengthPx() 
gridInterval  See mapToGrid() 
RangeError  If the argument is out of range, a RangeError exception will be thrown 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

inline 

private 
Set the length from a floating point number in nanometers.
This is a helper method for the setLength*() methods.
nanometers  A floating point number in nanometers. 

staticprivatenoexcept 
Map a length in nanometers to a grid interval in nanometers.
This is a helper function for mapToGrid().
nanometers  The length we want to map to the grid 
gridInterval  The grid interval 

staticprivate 
Convert a length from a QString (in millimeters) to an integer (in nanometers)
This is a helper function for Length(const QString&) and setLengthMm().
millimeters  A QString which contains a floating point number with maximum six decimals after the decimal point. The locale of the string have to be "C"! Example: QString("1234.56") for 1234.56mm 

private 
the length in nanometers

staticprivate 
1 inch = 25.4mm

staticprivate 
1 inch = 25.4mm

staticprivate 
72 dpi for the QGraphics* objects

staticprivate 

staticprivate 