mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
[PQ] Allow to provide a default unit for parsing, e.g. "0" -> "0ft"
This commit is contained in:
committed by
Mat Sutcliffe
parent
92fdbd3117
commit
9b031bb582
@@ -21,6 +21,7 @@
|
|||||||
#include "blackmisc/pq/acceleration.h"
|
#include "blackmisc/pq/acceleration.h"
|
||||||
#include "blackmisc/propertyindexvariantmap.h"
|
#include "blackmisc/propertyindexvariantmap.h"
|
||||||
#include "blackmisc/comparefunctions.h"
|
#include "blackmisc/comparefunctions.h"
|
||||||
|
#include "blackmisc/stringutils.h"
|
||||||
#include "blackmisc/dictionary.h"
|
#include "blackmisc/dictionary.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
#include "blackmisc/verify.h"
|
#include "blackmisc/verify.h"
|
||||||
@@ -419,7 +420,7 @@ namespace BlackMisc
|
|||||||
// there is no double qHash
|
// there is no double qHash
|
||||||
// also unit and rounding has to be considered
|
// also unit and rounding has to be considered
|
||||||
hashs << qHash(this->valueRoundedWithUnit(MU::defaultUnit()));
|
hashs << qHash(this->valueRoundedWithUnit(MU::defaultUnit()));
|
||||||
return BlackMisc::calculateHash(hashs, "PQ");
|
return calculateHash(hashs, "PQ");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class MU, class PQ>
|
template <class MU, class PQ>
|
||||||
@@ -449,6 +450,20 @@ namespace BlackMisc
|
|||||||
*this = CPqString::parse<PQ>(value, mode);
|
*this = CPqString::parse<PQ>(value, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class MU, class PQ>
|
||||||
|
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value, CPqString::SeparatorMode mode, const MU &defaultUnitIfMissing)
|
||||||
|
{
|
||||||
|
if (is09OnlyString(value))
|
||||||
|
{
|
||||||
|
const QString v = value + defaultUnitIfMissing.getName();
|
||||||
|
this->parseFromString(v, mode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->parseFromString(value, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class MU, class PQ>
|
template <class MU, class PQ>
|
||||||
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value)
|
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace BlackMisc
|
|||||||
*/
|
*/
|
||||||
template <class MU, class PQ> class CPhysicalQuantity :
|
template <class MU, class PQ> class CPhysicalQuantity :
|
||||||
public Mixin::DBusOperators<CPhysicalQuantity<MU, PQ>>,
|
public Mixin::DBusOperators<CPhysicalQuantity<MU, PQ>>,
|
||||||
public Mixin::DataStreamOperators<CPhysicalQuantity<MU, PQ>>,
|
public Mixin::DataStreamOperators<CPhysicalQuantity<MU, PQ>>,
|
||||||
public Mixin::JsonOperators<CPhysicalQuantity<MU, PQ>>,
|
public Mixin::JsonOperators<CPhysicalQuantity<MU, PQ>>,
|
||||||
public Mixin::Index<PQ>,
|
public Mixin::Index<PQ>,
|
||||||
public Mixin::MetaType<PQ>,
|
public Mixin::MetaType<PQ>,
|
||||||
@@ -255,11 +255,14 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
|
//! Parse value from string
|
||||||
|
void parseFromString(const QString &value);
|
||||||
|
|
||||||
//! Parse to string, with specified separator
|
//! Parse to string, with specified separator
|
||||||
void parseFromString(const QString &value, CPqString::SeparatorMode mode);
|
void parseFromString(const QString &value, CPqString::SeparatorMode mode);
|
||||||
|
|
||||||
//! Parse value from string
|
//! Parse to string, with specified separator
|
||||||
void parseFromString(const QString &value);
|
void parseFromString(const QString &value, CPqString::SeparatorMode mode, const MU &defaultUnitIfMissing);
|
||||||
|
|
||||||
//! Compare with other PQ
|
//! Compare with other PQ
|
||||||
int compare(const PQ &other) const { return compareImpl(*this->derived(), other); }
|
int compare(const PQ &other) const { return compareImpl(*this->derived(), other); }
|
||||||
|
|||||||
Reference in New Issue
Block a user