Ref T268, compare for PQs

This commit is contained in:
Klaus Basan
2018-07-09 22:06:03 +02:00
parent ead1a93597
commit d489bed370
2 changed files with 15 additions and 4 deletions

View File

@@ -500,8 +500,13 @@ namespace BlackMisc
template <class MU, class PQ>
int CPhysicalQuantity<MU, PQ>::compareImpl(const PQ &a, const PQ &b)
{
if (a.isNull() > b.isNull()) { return -1; }
if (a.isNull() < b.isNull()) { return 1; }
// fetch "null" as we do not know how expensive it is
const bool aIsNull = a.isNull();
const bool bIsNull = b.isNull();
if (aIsNull && bIsNull) { return 0; }
if (aIsNull > bIsNull) { return -1; }
if (aIsNull < bIsNull) { return 1; }
if (a < b) { return -1; }
else if (a > b) { return 1; }

View File

@@ -228,6 +228,9 @@ namespace BlackMisc
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
int comparePropertyByIndex(const CPropertyIndex &index, const PQ &pq) const;
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
@@ -237,8 +240,8 @@ namespace BlackMisc
//! Parse value from string
void parseFromString(const QString &value);
//! Compare
int comparePropertyByIndex(const CPropertyIndex &index, const PQ &pq) const;
//! Compare with other PQ
int compare(const PQ &other) const { return compareImpl(*this->derived(), other); }
//! Maximum of 2 quantities
static const PQ &maxValue(const PQ &pq1, const PQ &pq2);
@@ -246,6 +249,9 @@ namespace BlackMisc
//! Minimum of 2 quantities
static const PQ &minValue(const PQ &pq1, const PQ &pq2);
//! Implementation of compare
static int compare(const PQ &a, const PQ &b) { return compareImpl(a, b); }
//! NULL PQ
static const PQ &null();