 LibrePCB Developers Documentation
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 percent1 () noexcept

static Ratio percent5 () noexcept

static Ratio percent10 () 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%)

## ◆ Ratio() [1/3]

 constexpr Ratio ( )
inlinenoexcept

Default Constructor. Here is the caller graph for this function:

## ◆ Ratio() [2/3]

 constexpr Ratio ( const Ratio & ratio )
inlinenoexcept

Copy Constructor.

Parameters
 ratio Another Ratio object

## ◆ Ratio() [3/3]

 constexpr Ratio ( qint32 ppm )
inlineexplicitnoexcept

Constructor with a ratio in PPM.

Parameters
 ppm The ratio in PPM Here is the call graph for this function:

## ◆ ~Ratio()

 ~Ratio ( )
default

Destructor. Here is the caller graph for this function:

## ◆ setRatioPpm()

 void setRatioPpm ( qint32 ppm )
inlinenoexcept

Set the ratio in PPM.

Parameters
 ppm The ratio in PPM

## ◆ setRatioPercent()

 void setRatioPercent ( qreal percent )
inlinenoexcept

Set the ratio in percent.

Parameters
 percent The 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:

## ◆ setRatioNormalized() [1/2]

 void setRatioNormalized ( qreal normalized )
inlinenoexcept

Set the ratio as a normalized number.

Parameters
 normalized The 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:

## ◆ setRatioNormalized() [2/2]

 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
 normalized See fromNormalized(const QString&)
Exceptions
 Exception If the argument is invalid, an Exception will be thrown Here is the call graph for this function:

## ◆ toPpm()

 qint32 toPpm ( ) const
inlinenoexcept

Get the ratio in PPM.

Returns
The ratio in PPM Here is the caller graph for this function:

## ◆ toPercent()

 qreal toPercent ( ) const
inlinenoexcept

Get the ratio in percent.

Returns
The ratio in percent Here is the caller graph for this function:

## ◆ toNormalized()

 qreal toNormalized ( ) const
inlinenoexcept

Get the ratio as a normalized number.

Returns
The normalized ratio Here is the call graph for this function:

## ◆ toNormalizedString()

 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:

## ◆ fromPercent()

 Ratio fromPercent ( qreal percent )
staticnoexcept

Get a Ratio object with a specific ratio.

Parameters
 percent See 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:

## ◆ fromNormalized() [1/2]

 Ratio fromNormalized ( qreal normalized )
staticnoexcept

Get a Ratio object with a specific ratio.

Parameters
 normalized See 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:

## ◆ fromNormalized() [2/2]

 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
 normalized See setRatioNormalized(const QString&)
Returns
A new Ratio object with the specified ratio
Exceptions
 Exception If the argument is invalid, an Exception will be thrown Here is the call graph for this function:

## ◆ percent0()

 static Ratio percent0 ( )
inlinestaticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ percent1()

 static Ratio percent1 ( )
inlinestaticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ percent5()

 static Ratio percent5 ( )
inlinestaticnoexcept Here is the call graph for this function:

## ◆ percent10()

 static Ratio percent10 ( )
inlinestaticnoexcept Here is the call graph for this function:

## ◆ percent50()

 static Ratio percent50 ( )
inlinestaticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ percent100()

 static Ratio percent100 ( )
inlinestaticnoexcept Here is the call graph for this function: Here is the caller graph for this function:

## ◆ operator=()

 Ratio& operator= ( const Ratio & rhs )
inline

## ◆ operator+=()

 Ratio& operator+= ( const Ratio & rhs )
inline

## ◆ operator-=()

 Ratio& operator-= ( const Ratio & rhs )
inline

## ◆ operator*=() [1/2]

 Ratio& operator*= ( const Ratio & rhs )
inline

## ◆ operator*=() [2/2]

 Ratio& operator*= ( qint32 rhs )
inline

## ◆ operator/=() [1/2]

 Ratio& operator/= ( const Ratio & rhs )
inline

## ◆ operator/=() [2/2]

 Ratio& operator/= ( qint32 rhs )
inline

## ◆ operator+()

 Ratio operator+ ( const Ratio & rhs ) const
inline Here is the call graph for this function:

## ◆ operator-() [1/2]

 Ratio operator- ( ) const
inline Here is the call graph for this function:

## ◆ operator-() [2/2]

 Ratio operator- ( const Ratio & rhs ) const
inline Here is the call graph for this function:

## ◆ operator*() [1/2]

 Ratio operator* ( const Ratio & rhs ) const
inline Here is the call graph for this function:

## ◆ operator*() [2/2]

 Ratio operator* ( qint32 rhs ) const
inline Here is the call graph for this function:

## ◆ operator/() [1/2]

 Ratio operator/ ( const Ratio & rhs ) const
inline Here is the call graph for this function:

## ◆ operator/() [2/2]

 Ratio operator/ ( qint32 rhs ) const
inline Here is the call graph for this function:

## ◆ operator%()

 Ratio operator% ( const Ratio & rhs ) const
inline Here is the call graph for this function:

## ◆ operator>() [1/2]

 constexpr bool operator> ( const Ratio & rhs ) const
inline

## ◆ operator>() [2/2]

 constexpr bool operator> ( qint32 rhs ) const
inline

## ◆ operator<() [1/2]

 constexpr bool operator< ( const Ratio & rhs ) const
inline

## ◆ operator<() [2/2]

 constexpr bool operator< ( qint32 rhs ) const
inline

## ◆ operator>=() [1/2]

 constexpr bool operator>= ( const Ratio & rhs ) const
inline

## ◆ operator>=() [2/2]

 constexpr bool operator>= ( qint32 rhs ) const
inline

## ◆ operator<=() [1/2]

 constexpr bool operator<= ( const Ratio & rhs ) const
inline

## ◆ operator<=() [2/2]

 constexpr bool operator<= ( qint32 rhs ) const
inline

## ◆ operator==() [1/2]

 constexpr bool operator== ( const Ratio & rhs ) const
inline

## ◆ operator==() [2/2]

 constexpr bool operator== ( qint32 rhs ) const
inline

## ◆ operator!=() [1/2]

 constexpr bool operator!= ( const Ratio & rhs ) const
inline

## ◆ operator!=() [2/2]

 constexpr bool operator!= ( qint32 rhs ) const
inline

## ◆ operator bool()

 operator bool ( ) const
inlineexplicit Here is the call graph for this function:

## ◆ normalizedStringToPpm()

 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
 normalized 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("-0.1234") for -12.34 percent.
Returns
The ratio in PPM Here is the caller graph for this function:

## ◆ mPpm

 qint32 mPpm
private

the ratio in PPM

The documentation for this class was generated from the following files:
• /__w/1/s/libs/librepcb/core/types/ratio.h
• /__w/1/s/libs/librepcb/core/types/ratio.cpp