PQ parsing using "best guess" strategy as default plus renamings

This commit is contained in:
Klaus Basan
2018-12-20 03:59:46 +01:00
committed by Mat Sutcliffe
parent 4e1835b80d
commit d89b217e9b
13 changed files with 22 additions and 22 deletions

View File

@@ -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)

View File

@@ -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) {}

View File

@@ -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>

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
}