diff options
author | Mitch Curtis <mitch.curtis@digia.com> | 2014-01-14 12:34:35 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-14 14:02:09 +0100 |
commit | 7f50eca469a24809d6d5812ee94b447966ff81f9 (patch) | |
tree | c7974606ee5079231f9a156ec6cd98c0451334d5 /src/qml/qml/qqmllocale.cpp | |
parent | 20f533671ab37be8a5868fecc64dc9d5e5e3ada0 (diff) |
Allow assignment of a QML Locale object to a C++ QLocale property.
Task-number: QTBUG-36125
Change-Id: I58454db0c47684aed3e95c52a8135fd5fd6bf2f9
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmllocale.cpp')
-rw-r--r-- | src/qml/qml/qqmllocale.cpp | 77 |
1 files changed, 14 insertions, 63 deletions
diff --git a/src/qml/qml/qqmllocale.cpp b/src/qml/qml/qqmllocale.cpp index 75a366a7af..625b3a3175 100644 --- a/src/qml/qml/qqmllocale.cpp +++ b/src/qml/qml/qqmllocale.cpp @@ -54,62 +54,6 @@ QT_BEGIN_NAMESPACE -class QQmlLocaleData : public QV4::Object -{ - Q_MANAGED -public: - QQmlLocaleData(QV4::ExecutionEngine *engine) - : QV4::Object(engine) - { - setVTable(&static_vtbl); - } - - QLocale locale; - - static QLocale *getThisLocale(QV4::CallContext *ctx) { - QQmlLocaleData *thisObject = ctx->callData->thisObject.asObject()->as<QQmlLocaleData>(); - if (!thisObject) { - ctx->throwTypeError(); - return 0; - } - return &thisObject->locale; - } - - static QV4::ReturnedValue method_currencySymbol(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dateTimeFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_timeFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dateFormat(QV4::CallContext *ctx); - static QV4::ReturnedValue method_monthName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_standaloneMonthName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_dayName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_standaloneDayName(QV4::CallContext *ctx); - - static QV4::ReturnedValue method_get_firstDayOfWeek(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_measurementSystem(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_textDirection(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_weekDays(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_uiLanguages(QV4::CallContext *ctx); - - static QV4::ReturnedValue method_get_name(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_nativeLanguageName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_nativeCountryName(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_decimalPoint(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_groupSeparator(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_percent(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_zeroDigit(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_negativeSign(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_positiveSign(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_exponential(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_amText(QV4::CallContext *ctx); - static QV4::ReturnedValue method_get_pmText(QV4::CallContext *ctx); - -private: - static void destroy(Managed *that) - { - static_cast<QQmlLocaleData *>(that)->~QQmlLocaleData(); - } -}; - DEFINE_MANAGED_VTABLE(QQmlLocaleData); #define GET_LOCALE_DATA_RESOURCE(OBJECT) \ @@ -857,14 +801,21 @@ QQmlLocale::~QQmlLocale() { } -QV4::ReturnedValue QQmlLocale::locale(QV8Engine *v8engine, const QString &locale) +QV4::ReturnedValue QQmlLocale::locale(QV8Engine *v8engine, const QString &localeName) +{ + QLocale qlocale; + if (!localeName.isEmpty()) + qlocale = localeName; + return wrap(v8engine, qlocale); +} + +QV4::ReturnedValue QQmlLocale::wrap(QV8Engine *engine, const QLocale &locale) { - QV8LocaleDataDeletable *d = localeV8Data(v8engine); - QV4::ExecutionEngine *engine = QV8Engine::getV4(v8engine); - QV4::Scope scope(engine); - QV4::Scoped<QQmlLocaleData> wrapper(scope, new (engine->memoryManager) QQmlLocaleData(engine)); - if (!locale.isEmpty()) - wrapper->locale = QLocale(locale); + QV8LocaleDataDeletable *d = localeV8Data(engine); + QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine); + QV4::Scope scope(v4); + QV4::Scoped<QQmlLocaleData> wrapper(scope, new (v4->memoryManager) QQmlLocaleData(v4)); + wrapper->locale = locale; QV4::ScopedObject p(scope, d->prototype.value()); wrapper->setPrototype(p.getPointer()); return wrapper.asReturnedValue(); |