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

The Ratio class is used to represent a ratio number (e.g. 13.37%) More...

#include <ratio.h>

+ Collaboration diagram for Ratio:

Public Member Functions

constexpr Ratio () noexcept
 Default Constructor. More...
 
constexpr Ratio (const Ratio &ratio) noexcept
 Copy Constructor. More...
 
constexpr Ratio (qint32 ppm) noexcept
 Constructor with a ratio in PPM. More...
 
 ~Ratio ()=default
 Destructor. More...
 
void setRatioPpm (qint32 ppm) noexcept
 Set the ratio in PPM. More...
 
void setRatioPercent (qreal percent) noexcept
 Set the ratio in percent. More...
 
void setRatioNormalized (qreal normalized) noexcept
 Set the ratio as a normalized number. More...
 
void setRatioNormalized (const QString &normalized)
 Set the ratio as a normalized number, represented in a QString. More...
 
qint32 toPpm () const noexcept
 Get the ratio in PPM. More...
 
qreal toPercent () const noexcept
 Get the ratio in percent. More...
 
qreal toNormalized () const noexcept
 Get the ratio as a normalized number. More...
 
QString toNormalizedString () const noexcept
 Get the ratio as a normalized QString. More...
 
Ratiooperator= (const Ratio &rhs)
 
Ratiooperator+= (const Ratio &rhs)
 
Ratiooperator-= (const Ratio &rhs)
 
Ratiooperator*= (const Ratio &rhs)
 
Ratiooperator*= (qint32 rhs)
 
Ratiooperator/= (const Ratio &rhs)
 
Ratiooperator/= (qint32 rhs)
 
Ratio operator+ (const Ratio &rhs) const
 
Ratio operator- () const
 
Ratio operator- (const Ratio &rhs) const
 
Ratio operator* (const Ratio &rhs) const
 
Ratio operator* (qint32 rhs) const
 
Ratio operator/ (const Ratio &rhs) const
 
Ratio operator/ (qint32 rhs) const
 
Ratio operator% (const Ratio &rhs) const
 
constexpr bool operator> (const Ratio &rhs) const
 
constexpr bool operator> (qint32 rhs) const
 
constexpr bool operator< (const Ratio &rhs) const
 
constexpr bool operator< (qint32 rhs) const
 
constexpr bool operator>= (const Ratio &rhs) const
 
constexpr bool operator>= (qint32 rhs) const
 
constexpr bool operator<= (const Ratio &rhs) const
 
constexpr bool operator<= (qint32 rhs) const
 
constexpr bool operator== (const Ratio &rhs) const
 
constexpr bool operator== (qint32 rhs) const
 
constexpr bool operator!= (const Ratio &rhs) const
 
constexpr bool operator!= (qint32 rhs) const
 
 operator bool () const
 

Static Public Member Functions

static Ratio fromPercent (qreal percent) noexcept
 Get a Ratio object with a specific ratio. More...
 
static Ratio fromNormalized (qreal normalized) noexcept
 Get a Ratio object with a specific ratio. More...
 
static Ratio fromNormalized (const QString &normalized)
 Get a Ratio object with a specific ratio. More...
 
static Ratio percent0 () noexcept
 
static Ratio percent50 () noexcept
 
static Ratio percent100 () noexcept
 

Static Private Member Functions

static qint32 normalizedStringToPpm (const QString &normalized)
 Convert a normalized ratio from a QString to an integer (in PPM) More...
 

Private Attributes

qint32 mPpm
 the ratio in PPM More...
 

Detailed Description

The Ratio class is used to represent a ratio number (e.g. 13.37%)

Author
ubruhin
Date
2017-07-10

Constructor & Destructor Documentation

constexpr Ratio ( )
inlinenoexcept

Default Constructor.

+ Here is the caller graph for this function:

constexpr Ratio ( const Ratio ratio)
inlinenoexcept

Copy Constructor.

Parameters
ratioAnother Ratio object
constexpr Ratio ( qint32  ppm)
inlineexplicitnoexcept

Constructor with a ratio in PPM.

Parameters
ppmThe ratio in PPM
~Ratio ( )
default

Destructor.

Member Function Documentation

void setRatioPpm ( qint32  ppm)
inlinenoexcept

Set the ratio in PPM.

Parameters
ppmThe ratio in PPM
void setRatioPercent ( qreal  percent)
inlinenoexcept

Set the ratio in percent.

Parameters
percentThe ratio in percent
Warning
If you want to set the ratio exactly to common values like 0%, 50% or 100%, you should not use this method. Please use setRatioPpm() instead because it is more accurate (no use of floating point numbers). Or you can also use the static methods percent0(), percent50() and so on.

+ Here is the caller graph for this function:

void setRatioNormalized ( qreal  normalized)
inlinenoexcept

Set the ratio as a normalized number.

Parameters
normalizedThe normalized ratio
Warning
If you want to set the ratio exactly to common values like 0%, 50% or 100%, you should not use this method. Please use setRatioPpm() instead because it is more accurate (no use of floating point numbers). Or you can also use the static methods percent0(), percent50() and so on.

+ Here is the caller graph for this function:

void setRatioNormalized ( const QString &  normalized)
inline

Set the ratio as a normalized number, represented in a QString.

This method is useful to read ratios from files (deserialization).

Parameters
normalizedSee fromNormalized(const QString&)
Exceptions
ExceptionIf the argument is invalid, an Exception will be thrown

+ Here is the call graph for this function:

qint32 toPpm ( ) const
inlinenoexcept

Get the ratio in PPM.

Returns
The ratio in PPM

+ Here is the caller graph for this function:

qreal toPercent ( ) const
inlinenoexcept

Get the ratio in percent.

Returns
The ratio in percent

+ Here is the caller graph for this function:

qreal toNormalized ( ) const
inlinenoexcept

Get the ratio as a normalized number.

Returns
The normalized ratio

+ Here is the caller graph for this function:

QString toNormalizedString ( ) const
noexcept

Get the ratio as a normalized QString.

Returns
The normalized ratio as a QString
Note
This method is useful to store ratios in files (serialization).

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ratio fromPercent ( qreal  percent)
staticnoexcept

Get a Ratio object with a specific ratio.

Parameters
percentSee setRatioPercent()
Returns
A new Ratio object with the specified ratio

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ratio fromNormalized ( qreal  normalized)
staticnoexcept

Get a Ratio object with a specific ratio.

Parameters
normalizedSee setRatioNormalized(qreal)
Returns
A new Ratio object with the specified ratio

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ratio fromNormalized ( const QString &  normalized)
static

Get a Ratio object with a specific ratio.

This method can be used to create a Ratio object from a QString which contains a normalized floating point number, like QString("0.1234") for 12.34 percent. 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 ppm.

Parameters
normalizedSee setRatioNormalized(const QString&)
Returns
A new Ratio object with the specified ratio
Exceptions
ExceptionIf the argument is invalid, an Exception will be thrown

+ Here is the call graph for this function:

static Ratio percent0 ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

static Ratio percent50 ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

static Ratio percent100 ( )
inlinestaticnoexcept

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Ratio& operator= ( const Ratio rhs)
inline
Ratio& operator+= ( const Ratio rhs)
inline
Ratio& operator-= ( const Ratio rhs)
inline
Ratio& operator*= ( const Ratio rhs)
inline
Ratio& operator*= ( qint32  rhs)
inline
Ratio& operator/= ( const Ratio rhs)
inline
Ratio& operator/= ( qint32  rhs)
inline
Ratio operator+ ( const Ratio rhs) const
inline

+ Here is the call graph for this function:

Ratio operator- ( ) const
inline

+ Here is the call graph for this function:

Ratio operator- ( const Ratio rhs) const
inline

+ Here is the call graph for this function:

Ratio operator* ( const Ratio rhs) const
inline

+ Here is the call graph for this function:

Ratio operator* ( qint32  rhs) const
inline

+ Here is the call graph for this function:

Ratio operator/ ( const Ratio rhs) const
inline

+ Here is the call graph for this function:

Ratio operator/ ( qint32  rhs) const
inline

+ Here is the call graph for this function:

Ratio operator% ( const Ratio rhs) const
inline

+ Here is the call graph for this function:

constexpr bool operator> ( const Ratio rhs) const
inline
constexpr bool operator> ( qint32  rhs) const
inline
constexpr bool operator< ( const Ratio rhs) const
inline
constexpr bool operator< ( qint32  rhs) const
inline
constexpr bool operator>= ( const Ratio rhs) const
inline
constexpr bool operator>= ( qint32  rhs) const
inline
constexpr bool operator<= ( const Ratio rhs) const
inline
constexpr bool operator<= ( qint32  rhs) const
inline
constexpr bool operator== ( const Ratio rhs) const
inline
constexpr bool operator== ( qint32  rhs) const
inline
constexpr bool operator!= ( const Ratio rhs) const
inline
constexpr bool operator!= ( qint32  rhs) const
inline
operator bool ( ) const
inlineexplicit
qint32 normalizedStringToPpm ( const QString &  normalized)
staticprivate

Convert a normalized ratio from a QString to an integer (in PPM)

This is a helper function for Ratio(const QString&) and fromNormalized(const QString&));.

Parameters
normalizedA 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("-0.1234") for -12.34 percent.
Returns
The ratio in PPM

+ Here is the caller graph for this function:

Member Data Documentation

qint32 mPpm
private

the ratio in PPM


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