mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
PQ parsing using "best guess" strategy as default plus renamings
This commit is contained in:
committed by
Mat Sutcliffe
parent
4e1835b80d
commit
d89b217e9b
@@ -125,7 +125,7 @@ namespace BlackMisc
|
||||
|
||||
void CAltitude::parseFromString(const QString &value)
|
||||
{
|
||||
this->parseFromString(value, CPqString::SeparatorsBestGuess);
|
||||
this->parseFromString(value, CPqString::SeparatorBestGuess);
|
||||
}
|
||||
|
||||
void CAltitude::parseFromString(const QString &value, CPqString::SeparatorMode mode)
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
//! Altitude as string
|
||||
CAltitude(const QString &altitudeAsString, PhysicalQuantities::CPqString::SeparatorMode mode = PhysicalQuantities::CPqString::SeparatorsBestGuess);
|
||||
CAltitude(const QString &altitudeAsString, PhysicalQuantities::CPqString::SeparatorMode mode = PhysicalQuantities::CPqString::SeparatorBestGuess);
|
||||
|
||||
//! Constructor by CLength
|
||||
CAltitude(const PhysicalQuantities::CLength &altitude, ReferenceDatum datum) : CLength(altitude), m_datum(datum) {}
|
||||
|
||||
@@ -448,7 +448,7 @@ namespace BlackMisc
|
||||
template <class MU, class PQ>
|
||||
void CPhysicalQuantity<MU, PQ>::parseFromString(const QString &value)
|
||||
{
|
||||
*this = CPqString::parse<PQ>(value, CPqString::SeparatorsCLocale);
|
||||
*this = CPqString::parse<PQ>(value, CPqString::SeparatorQtDefault);
|
||||
}
|
||||
|
||||
template <class MU, class PQ>
|
||||
|
||||
@@ -117,13 +117,13 @@ namespace BlackMisc
|
||||
double numberD = -1;
|
||||
switch (mode)
|
||||
{
|
||||
case SeparatorsLocale:
|
||||
case SeparatorLocale:
|
||||
numberD = QLocale::system().toDouble(number, &success);
|
||||
break;
|
||||
case SeparatorsCLocale:
|
||||
case SeparatorQtDefault:
|
||||
numberD = number.toDouble(&success);
|
||||
break;
|
||||
case SeparatorsBestGuess:
|
||||
case SeparatorBestGuess:
|
||||
numberD = number.toDouble(&success);
|
||||
if (!success) { numberD = QLocale::system().toDouble(number, &success); }
|
||||
break;
|
||||
|
||||
@@ -38,9 +38,9 @@ namespace BlackMisc
|
||||
//! Number separators / group separators
|
||||
enum SeparatorMode
|
||||
{
|
||||
SeparatorsCLocale, //!< 100,000.00
|
||||
SeparatorsLocale, //!< depending on QLocale, e.g. 100.000,00 in Germany
|
||||
SeparatorsBestGuess //!< try to figure out
|
||||
SeparatorQtDefault, //!< 100000.00 no group separator
|
||||
SeparatorLocale, //!< depending on QLocale, e.g. 100.000,00 in Germany
|
||||
SeparatorBestGuess //!< try to figure out
|
||||
};
|
||||
|
||||
//! Group and digit separator
|
||||
@@ -57,10 +57,10 @@ namespace BlackMisc
|
||||
CPqString(const QString &value) : m_string(value) {}
|
||||
|
||||
//! Parse a string value like "100m", "10.3Mhz"
|
||||
static CVariant parseToVariant(const QString &value, SeparatorMode mode = SeparatorsCLocale);
|
||||
static CVariant parseToVariant(const QString &value, SeparatorMode mode = SeparatorQtDefault);
|
||||
|
||||
//! Parse into concrete type
|
||||
template <class PQ> static PQ parse(const QString &value, SeparatorMode mode = SeparatorsCLocale)
|
||||
template <class PQ> static PQ parse(const QString &value, SeparatorMode mode = SeparatorQtDefault)
|
||||
{
|
||||
if (value.isEmpty()) {return PQ::null(); }
|
||||
if (value.contains("null", Qt::CaseInsensitive)) { return PQ::null(); }
|
||||
@@ -73,7 +73,7 @@ namespace BlackMisc
|
||||
}
|
||||
|
||||
//! Locale aware parsing
|
||||
static double parseNumber(const QString &number, bool &success, SeparatorMode mode = SeparatorsCLocale);
|
||||
static double parseNumber(const QString &number, bool &success, SeparatorMode mode = SeparatorBestGuess);
|
||||
|
||||
private:
|
||||
QString m_string;
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace BlackMisc
|
||||
const QString p = this->part(index);
|
||||
if (p.isEmpty()) { return false; }
|
||||
bool ok = false;
|
||||
CPqString::parseNumber(p, ok, CPqString::SeparatorsBestGuess);
|
||||
CPqString::parseNumber(p, ok, CPqString::SeparatorBestGuess);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace BlackMisc
|
||||
const QString p = this->part(index);
|
||||
if (p.isEmpty()) { return def; }
|
||||
bool ok = false;
|
||||
double d = CPqString::parseNumber(p, ok, CPqString::SeparatorsBestGuess);
|
||||
double d = CPqString::parseNumber(p, ok, CPqString::SeparatorBestGuess);
|
||||
return ok ? d : def;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user