LibrePCB Developers Documentation
|
The Ratio class is used to represent a ratio number (e.g. 13.37%) More...
#include <ratio.h>
Public Member Functions | |
constexpr | Ratio () noexcept |
Default Constructor. | |
constexpr | Ratio (const Ratio &ratio) noexcept |
Copy Constructor. | |
constexpr | Ratio (qint32 ppm) noexcept |
Constructor with a ratio in PPM. | |
~Ratio ()=default | |
Destructor. | |
void | setRatioPpm (qint32 ppm) noexcept |
Set the ratio in PPM. | |
void | setRatioPercent (int percent) noexcept |
Set the ratio in percent. | |
void | setRatioPercent (qreal percent) noexcept |
Set the ratio in percent. | |
void | setRatioNormalized (qreal normalized) noexcept |
Set the ratio as a normalized number. | |
void | setRatioNormalized (const QString &normalized) |
Set the ratio as a normalized number, represented in a QString. | |
qint32 | toPpm () const noexcept |
Get the ratio in PPM. | |
qreal | toPercent () const noexcept |
Get the ratio in percent. | |
qreal | toNormalized () const noexcept |
Get the ratio as a normalized number. | |
QString | toNormalizedString () const noexcept |
Get the ratio as a normalized QString. | |
Ratio & | operator= (const Ratio &rhs) |
Ratio & | operator+= (const Ratio &rhs) |
Ratio & | operator-= (const Ratio &rhs) |
Ratio & | operator*= (const Ratio &rhs) |
Ratio & | operator*= (qint32 rhs) |
Ratio & | operator/= (const Ratio &rhs) |
Ratio & | operator/= (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 (int percent) noexcept |
Get a Ratio object with a specific ratio. | |
static Ratio | fromPercent (qreal percent) noexcept |
Get a Ratio object with a specific ratio. | |
static Ratio | fromNormalized (qreal normalized) noexcept |
Get a Ratio object with a specific ratio. | |
static Ratio | fromNormalized (const QString &normalized) |
Get a Ratio object with a specific ratio. | |
Static Private Member Functions | |
static qint32 | normalizedStringToPpm (const QString &normalized) |
Convert a normalized ratio from a QString to an integer (in PPM) | |
Private Attributes | |
qint32 | mPpm |
the ratio in PPM | |
The Ratio class is used to represent a ratio number (e.g. 13.37%)
|
inlineconstexprnoexcept |
Default Constructor.
Copy Constructor.
ratio | Another Ratio object |
|
inlineexplicitconstexprnoexcept |
Constructor with a ratio in PPM.
ppm | The ratio in PPM |
|
default |
Destructor.
|
inlinenoexcept |
Set the ratio in PPM.
ppm | The ratio in PPM |
|
inlinenoexcept |
Set the ratio in percent.
percent | The ratio in percent |
|
inlinenoexcept |
Set the ratio in percent.
percent | The ratio in percent |
|
inlinenoexcept |
Set the ratio as a normalized number.
normalized | The normalized ratio |
|
inline |
Set the ratio as a normalized number, represented in a QString.
This method is useful to read ratios from files (deserialization).
normalized | See fromNormalized(const QString&) |
|
inlinenoexcept |
Get the ratio in PPM.
|
inlinenoexcept |
Get the ratio in percent.
|
inlinenoexcept |
Get the ratio as a normalized number.
|
noexcept |
Get the ratio as a normalized QString.
|
staticnoexcept |
Get a Ratio object with a specific ratio.
percent | See setRatioPercent() |
|
staticnoexcept |
Get a Ratio object with a specific ratio.
percent | See setRatioPercent() |
|
staticnoexcept |
Get a Ratio object with a specific ratio.
normalized | See setRatioNormalized(qreal) |
|
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.
normalized | See setRatioNormalized(const QString&) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineexplicit |
|
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&));.
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. |
|
private |
the ratio in PPM