diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-12-02 16:38:31 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-12-05 07:31:30 +0000 |
commit | ab7f591a6b18a0a2a03b760fbd6a7fbb53189c72 (patch) | |
tree | 0124b56839350bb882523651bd5cfd30022038a5 /src/qml/qml/qqmllocale.cpp | |
parent | 6ad3445f1e159d9beea936b66d267dcaacdc5d6c (diff) |
Locale: expose NumberOptions to QML
As we want to specify how DoubleValidator and fromLocaleString handle
number separators, we need to expose NumberOptions to QML.
The referenced bug report is still unsolved, as we we still lack a method
to change DoubleValidator's behavior and NumberOptions does not have a
value to ignore occurrences of separators at arbitray places.
Task-number: QTBUG-75110
Change-Id: I81f48439114cad12e0e977bab09b0aa4e240fbab
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmllocale.cpp')
-rw-r--r-- | src/qml/qml/qqmllocale.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index dca13ac8d4..139074c648 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -478,6 +478,23 @@ ReturnedValue QQmlLocaleData::method_get_firstDayOfWeek(const QV4::FunctionObjec RETURN_RESULT(fdow); } +ReturnedValue QQmlLocaleData::method_get_numberOptions(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { + QV4::Scope scope(b); + const QLocale *locale = getThisLocale(scope, thisObject); + if (!locale) + return Encode::undefined(); + int numberOptions = int(locale->numberOptions()); + RETURN_RESULT(numberOptions); +} + +ReturnedValue QQmlLocaleData::method_set_numberOptions(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *argv, int argc) { + QV4::Scope scope(b); + QLocale *locale = getThisLocale(scope, thisObject); + int const numberOptions = argc ? int(argv[0].toNumber()) : QLocale::DefaultNumberOptions; + locale->setNumberOptions(QLocale::NumberOptions {numberOptions}); + return Encode::undefined(); +} + ReturnedValue QQmlLocaleData::method_get_measurementSystem(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int) { QV4::Scope scope(b); @@ -701,6 +718,7 @@ QV4LocaleDataDeletable::QV4LocaleDataDeletable(QV4::ExecutionEngine *engine) o->defineAccessorProperty(QStringLiteral("amText"), QQmlLocaleData::method_get_amText, nullptr); o->defineAccessorProperty(QStringLiteral("measurementSystem"), QQmlLocaleData::method_get_measurementSystem, nullptr); o->defineAccessorProperty(QStringLiteral("exponential"), QQmlLocaleData::method_get_exponential, nullptr); + o->defineAccessorProperty(QStringLiteral("numberOptions"), QQmlLocaleData::method_get_numberOptions, QQmlLocaleData::method_set_numberOptions); prototype.set(engine, o); } @@ -873,6 +891,16 @@ ReturnedValue QQmlLocale::method_localeCompare(const QV4::FunctionObject *b, con */ /*! + \qmlproperty enumeration QtQml::Locale::NumberOption + + Holds a set of options for number-to-string and + string-to-number conversions. + + \sa Number::toLocaleString() + \sa Number::fromLocaleString() +*/ + +/*! \qmlproperty string QtQml::Locale::percent Holds the percent character of this locale. |