swift
Loading...
Searching...
No Matches
swift::misc::physical_quantities::CMeasurementUnit Class Reference

Base class for all units, such as meter, hertz. More...

#include <measurementunit.h>

Inheritance diagram for swift::misc::physical_quantities::CMeasurementUnit:
[legend]

Classes

struct  NilConverter
 Converter for default values, such as None, used with public constructor. More...
struct  IdentityConverter
 Concrete strategy pattern for converting unit that does nothing. More...
struct  LinearConverter
 Concrete strategy pattern for converting unit with linear conversion. More...
struct  AffineConverter
 Concrete strategy pattern for converting unit with offset linear conversion. More...
struct  SubdivisionConverter
 Concrete strategy pattern for converting unit with one subdivision conversion. More...
struct  SubdivisionConverter2
 Concrete strategy pattern for converting unit with two subdivision conversions. More...
struct  One
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Two
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Milli
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Centi
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Hecto
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Kilo
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Mega
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Giga
 Metapolicy that can be used to modify template parameters of converters. More...
struct  InEachHundred
 Metapolicy that can be used to modify template parameters of converters. More...
struct  Data
 Pimpl class. More...

Public Member Functions

 CMeasurementUnit (const Data &&)=delete
 Constructor saves the address of its argument, so forbid rvalues.
QString convertToQString (bool i18n=false) const
 Cast as QString.
void marshallToDbus (QDBusArgument &argument) const
 Marshall without begin/endStructure, for when composed within another object.
void unmarshallFromDbus (const QDBusArgument &)
 Unmarshall without begin/endStructure, for when composed within another object.
void marshalToDataStream (QDataStream &stream) const
 Marshal a value to a QDataStream.
void unmarshalFromDataStream (QDataStream &)
 Unmarshal a value from a QDataStream.
QString getName (bool i18n=false) const
 Name such as "meter".
QString getSymbol (bool i18n=false) const
 Unit name such as "m".
bool endsStringWithNameOrSymbol (const QString &candidate, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Does a string end with name or symbol? E.g. 3meter, 3m, 3deg.
double roundValue (double value, int digits=-1) const
 Rounded value.
double roundToEpsilon (double value) const
 Rounded to the nearest CMeasurementUnit::getEpsilon.
virtual QString makeRoundedQString (double value, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
 Rounded string utility method, virtual so units can have specialized formatting.
virtual QString makeRoundedQStringWithUnit (double value, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
 Value rounded with unit, e.g. "5.00m", "30kHz".
double getEpsilon () const
 Threshold for comparions.
int getDisplayDigits () const
 Display digits.
double convertFrom (double value, const CMeasurementUnit &unit) const
 Convert from other unit to this unit.
bool isEpsilon (double value) const
 Is given value <= epsilon?
bool isNull () const
 Is unit null?
Public Member Functions inherited from swift::misc::mixin::String< CMeasurementUnit >
QString toQString (bool i18n=false) const
 Cast as QString.
std::string toStdString (bool i18n=false) const
 To std string.
QString stringForStreaming () const
 String for streaming operators.
Public Member Functions inherited from swift::misc::mixin::Icon< CMeasurementUnit >
CIcons::CIcons::StandardIconUnknown16 toIcon () const
 As icon, not implemented by all classes.

Static Public Member Functions

template<class U>
static U unitFromSymbol (const QString &symbol, bool strict=true)
 Unit from symbol.
template<class U>
static const QStringList & allSymbols ()
 All symbols.
template<class U>
static const QStringList & allSymbolsLowerCase ()
 All symbols case insensitive.
template<class U>
static bool hasCaseSensitiveSymbols ()
 Are symbols case sensitive?
template<class U>
static bool isValidUnitSymbol (const QString &symbol)
 Valid unit symbol?
template<class U>
static bool isValidUnitSymbol (const QString &symbol, Qt::CaseSensitivity caseSensitivity)
 Valid unit symbol?
template<class U>
static bool containsValidUnitSymbol (const QString &candidate, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 Contains valid unit symbol?
template<class U>
static bool endWithValidUnitSymbol (const QString &candidate, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
 Ends with valid unit symbol?
static CMeasurementUnit None ()
 Dimensionless unit.

Protected Types

using ConverterFunction = double (*)(double)
 Pointer to function for converting between units.

Protected Member Functions

 CMeasurementUnit (const Data &data)
 Constructor.
 ~CMeasurementUnit ()=default
 Destructor.
 CMeasurementUnit (const CMeasurementUnit &)=default
 Copy constructor.
CMeasurementUnit & operator= (const CMeasurementUnit &)=default
 Copy assignment operator.

Static Protected Member Functions

template<int N>
static constexpr QLatin1String constQLatin1 (const char(&str)[N])
 Constant-initialize QLatin1String without using strlen.

Friends

bool operator== (const CMeasurementUnit &a, const CMeasurementUnit &b)
 Equal operator ==.
bool operator!= (const CMeasurementUnit &a, const CMeasurementUnit &b)
 Unequal operator !=.
size_t qHash (const CMeasurementUnit &unit)
 qHash overload, needed for storing value in a QSet.

Detailed Description

Base class for all units, such as meter, hertz.

Definition at line 36 of file measurementunit.h.

Member Typedef Documentation

◆ ConverterFunction

Pointer to function for converting between units.

Definition at line 44 of file measurementunit.h.

Constructor & Destructor Documentation

◆ CMeasurementUnit()

swift::misc::physical_quantities::CMeasurementUnit::CMeasurementUnit ( const Data & data)
inlineprotected

Constructor.

Definition at line 243 of file measurementunit.h.

Member Function Documentation

◆ allSymbols()

template<class U>
const QStringList & swift::misc::physical_quantities::CMeasurementUnit::allSymbols ( )
inlinestatic

All symbols.

Definition at line 400 of file measurementunit.h.

◆ allSymbolsLowerCase()

template<class U>
const QStringList & swift::misc::physical_quantities::CMeasurementUnit::allSymbolsLowerCase ( )
inlinestatic

All symbols case insensitive.

Definition at line 417 of file measurementunit.h.

◆ constQLatin1()

template<int N>
constexpr QLatin1String swift::misc::physical_quantities::CMeasurementUnit::constQLatin1 ( const char(&) str[N])
inlinestaticconstexprprotected

Constant-initialize QLatin1String without using strlen.

Definition at line 237 of file measurementunit.h.

◆ containsValidUnitSymbol()

template<class U>
bool swift::misc::physical_quantities::CMeasurementUnit::containsValidUnitSymbol ( const QString & candidate,
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive )
inlinestatic

Contains valid unit symbol?

Parameters
candidateto be tested
caseSensitivitycheck case sensitiv?

Definition at line 472 of file measurementunit.h.

◆ convertFrom()

double swift::misc::physical_quantities::CMeasurementUnit::convertFrom ( double value,
const CMeasurementUnit & unit ) const

Convert from other unit to this unit.

Definition at line 14 of file measurementunit.cpp.

◆ convertToQString()

QString swift::misc::physical_quantities::CMeasurementUnit::convertToQString ( bool i18n = false) const
inline

Cast as QString.

Definition at line 262 of file measurementunit.h.

◆ endsStringWithNameOrSymbol()

bool swift::misc::physical_quantities::CMeasurementUnit::endsStringWithNameOrSymbol ( const QString & candidate,
Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
inline

Does a string end with name or symbol? E.g. 3meter, 3m, 3deg.

Definition at line 312 of file measurementunit.h.

◆ endWithValidUnitSymbol()

template<class U>
bool swift::misc::physical_quantities::CMeasurementUnit::endWithValidUnitSymbol ( const QString & candidate,
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive )
inlinestatic

Ends with valid unit symbol?

Parameters
candidateto be tested
caseSensitivitycheck case sensitiv?

Definition at line 492 of file measurementunit.h.

◆ getDisplayDigits()

int swift::misc::physical_quantities::CMeasurementUnit::getDisplayDigits ( ) const
inline

Display digits.

Definition at line 341 of file measurementunit.h.

◆ getEpsilon()

double swift::misc::physical_quantities::CMeasurementUnit::getEpsilon ( ) const
inline

Threshold for comparions.

Definition at line 338 of file measurementunit.h.

◆ getName()

QString swift::misc::physical_quantities::CMeasurementUnit::getName ( bool i18n = false) const
inline

Name such as "meter".

Definition at line 300 of file measurementunit.h.

◆ getSymbol()

QString swift::misc::physical_quantities::CMeasurementUnit::getSymbol ( bool i18n = false) const
inline

Unit name such as "m".

Definition at line 306 of file measurementunit.h.

◆ hasCaseSensitiveSymbols()

template<class U>
bool swift::misc::physical_quantities::CMeasurementUnit::hasCaseSensitiveSymbols ( )
inlinestatic

Are symbols case sensitive?

Definition at line 434 of file measurementunit.h.

◆ isEpsilon()

bool swift::misc::physical_quantities::CMeasurementUnit::isEpsilon ( double value) const
inline

Is given value <= epsilon?

Definition at line 347 of file measurementunit.h.

◆ isNull()

bool swift::misc::physical_quantities::CMeasurementUnit::isNull ( ) const
inline

Is unit null?

Definition at line 355 of file measurementunit.h.

◆ isValidUnitSymbol() [1/2]

template<class U>
bool swift::misc::physical_quantities::CMeasurementUnit::isValidUnitSymbol ( const QString & symbol)
inlinestatic

Valid unit symbol?

Parameters
symbolto be tested

Definition at line 445 of file measurementunit.h.

◆ isValidUnitSymbol() [2/2]

template<class U>
bool swift::misc::physical_quantities::CMeasurementUnit::isValidUnitSymbol ( const QString & symbol,
Qt::CaseSensitivity caseSensitivity )
inlinestatic

Valid unit symbol?

Parameters
symbolto be tested
caseSensitivitycheck case sensitiv?

Definition at line 458 of file measurementunit.h.

◆ makeRoundedQString()

QString swift::misc::physical_quantities::CMeasurementUnit::makeRoundedQString ( double value,
int digits = -1,
bool withGroupSeparator = false,
bool i18n = false ) const
virtual

Rounded string utility method, virtual so units can have specialized formatting.

Note
default digits is CMeasurementUnit::getDisplayDigits

Definition at line 46 of file measurementunit.cpp.

◆ makeRoundedQStringWithUnit()

QString swift::misc::physical_quantities::CMeasurementUnit::makeRoundedQStringWithUnit ( double value,
int digits = -1,
bool withGroupSeparator = false,
bool i18n = false ) const
virtual

Value rounded with unit, e.g. "5.00m", "30kHz".

Note
default digits is CMeasurementUnit::getDisplayDigits

Reimplemented in CAngleUnit, swift::misc::physical_quantities::CAngleUnit, and swift::misc::physical_quantities::CTimeUnit.

Definition at line 22 of file measurementunit.cpp.

◆ marshallToDbus()

void swift::misc::physical_quantities::CMeasurementUnit::marshallToDbus ( QDBusArgument & argument) const
inline

Marshall without begin/endStructure, for when composed within another object.

Definition at line 265 of file measurementunit.h.

◆ marshalToDataStream()

void swift::misc::physical_quantities::CMeasurementUnit::marshalToDataStream ( QDataStream & stream) const
inline

Marshal a value to a QDataStream.

Definition at line 276 of file measurementunit.h.

◆ None()

CMeasurementUnit swift::misc::physical_quantities::CMeasurementUnit::None ( )
inlinestatic

Dimensionless unit.

Definition at line 501 of file measurementunit.h.

◆ roundToEpsilon()

double swift::misc::physical_quantities::CMeasurementUnit::roundToEpsilon ( double value) const

Rounded to the nearest CMeasurementUnit::getEpsilon.

Remarks
uses CMathUtils::roundEpsilon

Definition at line 37 of file measurementunit.cpp.

◆ roundValue()

double swift::misc::physical_quantities::CMeasurementUnit::roundValue ( double value,
int digits = -1 ) const

Rounded value.

Note
default digits is CMeasurementUnit::getDisplayDigits

Definition at line 28 of file measurementunit.cpp.

◆ unitFromSymbol()

template<class U>
U swift::misc::physical_quantities::CMeasurementUnit::unitFromSymbol ( const QString & symbol,
bool strict = true )
inlinestatic

Unit from symbol.

Parameters
symbolmust be a valid unit symbol (without i18n) or empty string (empty means default unit)
strictstrict check means if unit is not found, program terminates

Definition at line 367 of file measurementunit.h.

◆ unmarshalFromDataStream()

void swift::misc::physical_quantities::CMeasurementUnit::unmarshalFromDataStream ( QDataStream & )
inline

Unmarshal a value from a QDataStream.

Definition at line 279 of file measurementunit.h.

◆ unmarshallFromDbus()

void swift::misc::physical_quantities::CMeasurementUnit::unmarshallFromDbus ( const QDBusArgument & )
inline

Unmarshall without begin/endStructure, for when composed within another object.

Definition at line 268 of file measurementunit.h.

◆ operator!=

bool operator!= ( const CMeasurementUnit & a,
const CMeasurementUnit & b )
friend

Unequal operator !=.

Definition at line 294 of file measurementunit.h.

◆ operator==

bool operator== ( const CMeasurementUnit & a,
const CMeasurementUnit & b )
friend

Equal operator ==.

Definition at line 287 of file measurementunit.h.

◆ qHash

size_t qHash ( const CMeasurementUnit & unit)
friend

qHash overload, needed for storing value in a QSet.

Definition at line 297 of file measurementunit.h.


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