diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-01-08 13:41:07 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-08 14:28:58 +0100 |
commit | 06178e0d0f18d15635fbcf23e179e4fbdf8c68a8 (patch) | |
tree | 790f1122900cc1a101be5a6c54f93e4209992da3 /src/dialogs/Private | |
parent | c549c7795884d1e858aa7963a550b74c76a2f02d (diff) | |
download | qtquickcontrols-06178e0d0f18d15635fbcf23e179e4fbdf8c68a8.tar.gz |
Revert "dialog-private: replace QJSValue with QQmlV4Handle in js functions"
This reverts commit b365471f0abc79f08bf0d852aea3be0a601c6901.
We need to be able to change the internal API in QtQml, which is difficult if
other modules are using it. It's much easier here to simply use QJSValue.
Change-Id: Ibbc078d8deffcf4f5a96a4cfe50c836d6653d666
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'src/dialogs/Private')
-rw-r--r-- | src/dialogs/Private/Private.pro | 2 | ||||
-rw-r--r-- | src/dialogs/Private/qquickfontlistmodel.cpp | 49 | ||||
-rw-r--r-- | src/dialogs/Private/qquickfontlistmodel_p.h | 8 | ||||
-rw-r--r-- | src/dialogs/Private/qquickwritingsystemlistmodel.cpp | 34 | ||||
-rw-r--r-- | src/dialogs/Private/qquickwritingsystemlistmodel_p.h | 6 |
5 files changed, 38 insertions, 61 deletions
diff --git a/src/dialogs/Private/Private.pro b/src/dialogs/Private/Private.pro index 7f04617e..1302089b 100644 --- a/src/dialogs/Private/Private.pro +++ b/src/dialogs/Private/Private.pro @@ -12,6 +12,6 @@ HEADERS += \ qquickfontlistmodel_p.h \ qquickwritingsystemlistmodel_p.h -QT += gui-private core-private qml-private +QT += gui-private core-private qml load(qml_plugin) diff --git a/src/dialogs/Private/qquickfontlistmodel.cpp b/src/dialogs/Private/qquickfontlistmodel.cpp index e3601f20..7e2ba5a9 100644 --- a/src/dialogs/Private/qquickfontlistmodel.cpp +++ b/src/dialogs/Private/qquickfontlistmodel.cpp @@ -42,16 +42,11 @@ #include "qquickfontlistmodel_p.h" #include <QtGui/qfontdatabase.h> #include <QtQml/qqmlcontext.h> -#include <private/qqmlengine_p.h> -#include <private/qv8engine_p.h> -#include <private/qv4value_p.h> -#include <private/qv4engine_p.h> -#include <private/qv4object_p.h> +#include <QtQml/qqml.h> +#include <QtQml/qqmlengine.h> QT_BEGIN_NAMESPACE -using namespace QV4; - class QQuickFontListModelPrivate { Q_DECLARE_PUBLIC(QQuickFontListModel) @@ -206,45 +201,35 @@ bool QQuickFontListModel::proportionalFonts() const return d->options->testOption(QFontDialogOptions::ProportionalFonts); } -QQmlV4Handle QQuickFontListModel::get(int idx) const +QJSValue QQuickFontListModel::get(int idx) const { Q_D(const QQuickFontListModel); + QJSEngine *engine = qmlEngine(this); + if (idx < 0 || idx >= count()) - return QQmlV4Handle(Encode::undefined()); - - QQmlEngine *engine = qmlContext(this)->engine(); - QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); - ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); - Scope scope(v4engine); - ScopedObject o(scope, v4engine->newObject()); - ScopedString s(scope); - for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) { - Property *p = o->insertMember((s = v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1])), PropertyAttributes()); - p->value = v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1)); - } + return engine->newObject(); + + QJSValue result = engine->newObject(); + int count = d->roleNames.keys().count(); + for (int i = 0; i < count; ++i) + result.setProperty(QString(d->roleNames[Qt::UserRole + i + 1]), data(index(idx, 0), Qt::UserRole + i + 1).toString()); - return QQmlV4Handle(o); + return result; } -QQmlV4Handle QQuickFontListModel::pointSizes() +QJSValue QQuickFontListModel::pointSizes() { - QQmlEngine *engine = qmlContext(this)->engine(); - QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); - ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); - Scope scope(v4engine); + QJSEngine *engine = qmlEngine(this); QList<int> pss = QFontDatabase::standardSizes(); int size = pss.size(); - Scoped<QV4::ArrayObject> a(scope, v4engine->newArrayObject()); - a->arrayReserve(size); - a->arrayData.length = size; + QJSValue result = engine->newArray(size); for (int i = 0; i < size; ++i) - a->arrayData.data[i].value = Primitive::fromInt32(pss.at(i)); - a->setArrayLengthUnchecked(size); + result.setProperty(i, pss.at(i)); - return QQmlV4Handle(ScopedValue(scope, a.asReturnedValue())); + return result; } void QQuickFontListModel::classBegin() diff --git a/src/dialogs/Private/qquickfontlistmodel_p.h b/src/dialogs/Private/qquickfontlistmodel_p.h index 3e2e7f71..4f86bc77 100644 --- a/src/dialogs/Private/qquickfontlistmodel_p.h +++ b/src/dialogs/Private/qquickfontlistmodel_p.h @@ -43,10 +43,10 @@ #define QQUICKFONTLISTMODEL_P_H #include <QtCore/qstringlist.h> -#include <QtCore/qabstractitemmodel.h> +#include <QtCore/QAbstractListModel> #include <QtGui/qpa/qplatformdialoghelper.h> #include <QtQml/qqmlparserstatus.h> -#include <private/qv8engine_p.h> +#include <QtQml/qjsvalue.h> QT_BEGIN_NAMESPACE @@ -90,8 +90,8 @@ public: bool monospacedFonts() const; bool proportionalFonts() const; - Q_INVOKABLE QQmlV4Handle get(int index) const; - Q_INVOKABLE QQmlV4Handle pointSizes(); + Q_INVOKABLE QJSValue get(int index) const; + Q_INVOKABLE QJSValue pointSizes(); virtual void classBegin(); virtual void componentComplete(); diff --git a/src/dialogs/Private/qquickwritingsystemlistmodel.cpp b/src/dialogs/Private/qquickwritingsystemlistmodel.cpp index f2b4ff8b..b4dcf631 100644 --- a/src/dialogs/Private/qquickwritingsystemlistmodel.cpp +++ b/src/dialogs/Private/qquickwritingsystemlistmodel.cpp @@ -42,16 +42,11 @@ #include "qquickwritingsystemlistmodel_p.h" #include <QtGui/qfontdatabase.h> #include <QtQml/qqmlcontext.h> -#include <private/qqmlengine_p.h> -#include <private/qv8engine_p.h> -#include <private/qv4value_p.h> -#include <private/qv4engine_p.h> -#include <private/qv4object_p.h> +#include <QtQml/qqml.h> +#include <QtQml/qqmlengine.h> QT_BEGIN_NAMESPACE -using namespace QV4; - class QQuickWritingSystemListModelPrivate { Q_DECLARE_PUBLIC(QQuickWritingSystemListModel) @@ -144,25 +139,22 @@ QStringList QQuickWritingSystemListModel::writingSystems() const return result; } -QQmlV4Handle QQuickWritingSystemListModel::get(int idx) const +QJSValue QQuickWritingSystemListModel::get(int idx) const { Q_D(const QQuickWritingSystemListModel); + QJSEngine *engine = qmlEngine(this); + if (idx < 0 || idx >= count()) - return QQmlV4Handle(Encode::undefined()); - - QQmlEngine *engine = qmlContext(this)->engine(); - QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine); - ExecutionEngine *v4engine = QV8Engine::getV4(v8engine); - Scope scope(v4engine); - ScopedObject o(scope, v4engine->newObject()); - ScopedString s(scope); - for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) { - Property *p = o->insertMember((s = v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1])), PropertyAttributes()); - p->value = v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1)); - } + return engine->newObject(); + + QJSValue result = engine->newObject(); + int count = d->roleNames.keys().count(); + for (int i = 0; i < count; ++i) + result.setProperty(QString(d->roleNames[Qt::UserRole + i + 1]), data(index(idx, 0), Qt::UserRole + i + 1).toString()); + + return result; - return QQmlV4Handle(o); } void QQuickWritingSystemListModel::classBegin() diff --git a/src/dialogs/Private/qquickwritingsystemlistmodel_p.h b/src/dialogs/Private/qquickwritingsystemlistmodel_p.h index 31058bbf..120dd8a6 100644 --- a/src/dialogs/Private/qquickwritingsystemlistmodel_p.h +++ b/src/dialogs/Private/qquickwritingsystemlistmodel_p.h @@ -43,9 +43,9 @@ #define QQUICKWRITINGSYSTEMLISTMODEL_P_H #include <QtCore/qstringlist.h> -#include <QtCore/qabstractitemmodel.h> +#include <QtCore/QAbstractListModel> #include <QtQml/qqmlparserstatus.h> -#include <private/qv8engine_p.h> +#include <QtQml/qjsvalue.h> QT_BEGIN_NAMESPACE @@ -79,7 +79,7 @@ public: QStringList writingSystems() const; - Q_INVOKABLE QQmlV4Handle get(int index) const; + Q_INVOKABLE QJSValue get(int index) const; virtual void classBegin(); virtual void componentComplete(); |