6 #ifndef SWIFT_MISC_PQ_PHYSICALQUANTITY_H
7 #define SWIFT_MISC_PQ_PHYSICALQUANTITY_H
9 #include <QDBusArgument>
10 #include <QJsonObject>
26 namespace swift::misc::physical_quantities
28 template <
class MU,
class PQ>
29 class CPhysicalQuantity;
33 #define SWIFT_TEMPLATE_PQ_MIXINS(MU, PQ, Extern, Export) \
34 namespace swift::misc::physical_quantities \
38 namespace swift::misc::private_ns \
40 Extern template struct Export CValueObjectMetaInfo<physical_quantities::PQ>; \
41 Extern template struct Export MetaTypeHelper<physical_quantities::PQ>; \
43 namespace swift::misc::mixin \
45 Extern template class Export \
46 DBusOperators<physical_quantities::CPhysicalQuantity<physical_quantities::MU, physical_quantities::PQ>>; \
47 Extern template class Export DataStreamOperators< \
48 physical_quantities::CPhysicalQuantity<physical_quantities::MU, physical_quantities::PQ>>; \
49 Extern template class Export \
50 JsonOperators<physical_quantities::CPhysicalQuantity<physical_quantities::MU, physical_quantities::PQ>>; \
51 Extern template class Export Index<physical_quantities::PQ>; \
52 Extern template class Export MetaType<physical_quantities::PQ>; \
53 Extern template class Export String<physical_quantities::PQ>; \
54 Extern template class Export \
55 Icon<physical_quantities::CPhysicalQuantity<physical_quantities::MU, physical_quantities::PQ>>; \
69 #if defined(Q_OS_WIN) && defined(Q_CC_GNU)
70 # define SWIFT_DECLARE_PQ_MIXINS(MU, PQ)
71 # define SWIFT_DEFINE_PQ_MIXINS(MU, PQ)
72 #elif defined(Q_OS_WIN) && defined(Q_CC_CLANG)
73 # define SWIFT_DECLARE_PQ_MIXINS(MU, PQ) SWIFT_TEMPLATE_PQ_MIXINS(MU, PQ, extern, )
74 # define SWIFT_DEFINE_PQ_MIXINS(MU, PQ) SWIFT_TEMPLATE_PQ_MIXINS(MU, PQ, , SWIFT_MISC_EXPORT)
76 # define SWIFT_DECLARE_PQ_MIXINS(MU, PQ) SWIFT_TEMPLATE_PQ_MIXINS(MU, PQ, extern, )
77 # define SWIFT_DEFINE_PQ_MIXINS(MU, PQ) SWIFT_TEMPLATE_PQ_MIXINS(MU, PQ, , )
90 namespace swift::misc::physical_quantities
105 template <
class MU,
class PQ>
116 friend int compare(
const PQ &a,
const PQ &b) {
return compareImpl(a, b); }
122 IndexUnit = CPropertyIndexRef::GlobalIndexCPhysicalQuantity,
124 IndexValueRounded0DigitsWithUnit,
125 IndexValueRounded1DigitsWithUnit,
126 IndexValueRounded2DigitsWithUnit,
127 IndexValueRounded3DigitsWithUnit,
128 IndexValueRounded6DigitsWithUnit
157 double value(MU unit)
const;
160 double value()
const;
195 bool i18n =
false)
const;
199 QString
valueRoundedWithUnit(
int digits = -1,
bool withGroupSeparator =
false,
bool i18n =
false)
const;
224 friend PQ
operator*(
double factor,
const PQ &other) {
return other * factor; }
312 friend size_t qHash(
const PQ &pq) {
return pq.getValueHash(); }
315 QJsonObject
toJson()
const;
342 int compare(
const PQ &other)
const {
return compareImpl(*this->derived(), other); }
345 static const PQ &
maxValue(
const PQ &pq1,
const PQ &pq2);
348 static const PQ &
minValue(
const PQ &pq1,
const PQ &pq2);
351 static int compare(
const PQ &a,
const PQ &b) {
return compareImpl(a, b); }
354 static const PQ &
null();
374 using UnitClass = MU;
377 static int compareImpl(
const PQ &,
const PQ &);
386 PQ
const *derived()
const;
Non-owning reference to a CPropertyIndex with a subset of its features.
Tag type signifying overloaded marshalling methods that preserve data at the expense of size.
CRTP class template which will generate marshalling operators for a derived class with its own marsha...
CRTP class template to generate non-member QDataStream streaming operators.
CRTP class template from which a derived class can inherit icon-related functions.
CRTP class template from which a derived class can inherit property indexing functions.
CRTP class template which will generate marshalling operators for a derived class with its own marsha...
CRTP class template from which a derived class can inherit string streaming operations.
A physical quantity such as "5m", "20s", "1500ft/s".
double value() const
Value in current unit.
CPhysicalQuantity & operator+=(const CPhysicalQuantity &other)
Plus operator +=.
bool isNegativeWithEpsilonConsidered() const
Value <= 0 epsilon considered.
void setValueSameUnit(double value)
Change value without changing unit.
QString convertToQString(bool i18n=false) const
Cast as QString.
void parseFromString(const QString &value)
Parse value from string.
void unmarshallFromDbus(const QDBusArgument &argument)
Unmarshall without begin/endStructure, for when composed within another object.
static PQ parsedFromString(const QString &value, CPqString::SeparatorMode mode=CPqString::SeparatorBestGuess)
Parsed from given string.
PQ switchedUnit(const MU &newUnit) const
Return copy with switched unit.
friend PQ operator-(const PQ &a, const PQ &b)
Minus operator -.
const MU & getUnit() const
Unit.
PQ operator-() const
Unary operator -.
PQ operator/(double divide) const
Operator /.
PQ & switchUnit(const MU &newUnit)
Change unit, and convert value to maintain the same quantity.
QString valueIntegerAsString() const
As integer value in current unit.
void setUnitBySymbol(const QString &unitName)
Set unit by string.
friend PQ operator+(const PQ &a, const PQ &b)
Plus operator +.
size_t getValueHash() const
qHash overload, needed for storing value in a QSet.
bool isInteger() const
Is value an integer.
friend bool operator>=(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Greater equal operator >=.
QJsonObject toJson() const
Cast to JSON object.
bool isNull() const
Is quantity null?
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static const PQ & minValue(const PQ &pq1, const PQ &pq2)
Minimum of 2 quantities.
int comparePropertyByIndex(CPropertyIndexRef index, const PQ &pq) const
Compare for index.
CPhysicalQuantity & operator-=(const CPhysicalQuantity &other)
Minus operator-=.
void unmarshalFromDataStream(QDataStream &stream)
Unmarshal a value from a QDataStream.
CPhysicalQuantity(double value, MU unit)
Constructor with double.
QString valueIntegerAsString(MU unit) const
As integer value.
QString valueRoundedAsString(MU unit, int digits=-1) const
Rounded value in given unit.
void roundToEpsilon()
Round current value in current unit to epsilon.
void addValueSameUnit(double value)
Add to the value in the current unit.
friend PQ operator*(double factor, const PQ &other)
Operator to support commutative multiplication.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setUnit(const MU &unit)
Simply set unit, do no calclulate conversion.
QString getUnitSymbol() const
Unit.
friend int compare(const PQ &a, const PQ &b)
Return negative, zero, or positive if a is less than, equal to, or greater than b.
void substractValueSameUnit(double value)
Substract from the value in the current unit.
CPhysicalQuantity & operator/=(double divide)
Divide operator /=.
friend bool operator<=(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Less equal operator <=.
static int compare(const PQ &a, const PQ &b)
Implementation of compare.
void marshalToDataStream(QDataStream &stream) const
Marshal a value to a QDataStream.
friend bool operator<(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Less operator <.
friend size_t qHash(const PQ &pq)
qHash overload, needed for storing value in a QSet.
int valueInteger() const
As integer value in current unit.
void convertFromJson(const QJsonObject &json)
Assign from JSON object.
void setCurrentUnitValue(double value)
Set value in current unit.
const PQ & makePositive()
Make value always positive.
friend bool operator>(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Greater operator >
static const PQ & maxValue(const PQ &pq1, const PQ &pq2)
Maximum of 2 quantities.
void marshallToDbus(QDBusArgument &argument) const
Marshall without begin/endStructure, for when composed within another object.
friend bool operator==(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Equal operator ==.
CPhysicalQuantity & operator*=(double multiply)
Multiply operator *=.
int compare(const PQ &other) const
Compare with other PQ.
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
bool isPositiveWithEpsilonConsidered() const
Value >= 0 epsilon considered.
double valueRounded(MU unit, int digits=-1) const
Rounded value in given unit.
PQ abs() const
Absolute value (always >=0)
const PQ & makeNegative()
Make value always negative.
friend bool operator!=(const CPhysicalQuantity &a, const CPhysicalQuantity &b)
Not equal operator !=.
PQ operator*(double multiply) const
Operator *.
bool isZeroEpsilonConsidered() const
Quantity value <= epsilon.
SeparatorMode
Number separators / group separators.
@ SeparatorBestGuess
try to figure out
#define SWIFT_DECLARE_PQ_MIXINS(MU, PQ)
Explicit template declaration of mixins for a CPhysicalQuantity subclass to be placed near the top of...
#define SWIFT_MISC_EXPORT_DECLARE_TEMPLATE
Export explicit template declaration.