dialog-private: replace QJSValue with QQmlV4Handle in js functions
Change-Id: I1e16147a1930f717cddd246068c06728e76eddd9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
This commit is contained in:
parent
6b2118e00c
commit
b365471f0a
|
@ -12,6 +12,6 @@ HEADERS += \
|
|||
qquickfontlistmodel_p.h \
|
||||
qquickwritingsystemlistmodel_p.h
|
||||
|
||||
QT += quick-private gui-private core-private qml-private
|
||||
QT += gui-private core-private qml-private
|
||||
|
||||
load(qml_plugin)
|
||||
|
|
|
@ -41,13 +41,17 @@
|
|||
|
||||
#include "qquickfontlistmodel_p.h"
|
||||
#include <QtGui/qfontdatabase.h>
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QtQml/qqmlcontext.h>
|
||||
#include <QtQml/qqmlengine.h>
|
||||
#include <QtQml/qjsengine.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>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace QV4;
|
||||
|
||||
class QQuickFontListModelPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QQuickFontListModel)
|
||||
|
@ -202,35 +206,43 @@ bool QQuickFontListModel::proportionalFonts() const
|
|||
return d->options->testOption(QFontDialogOptions::ProportionalFonts);
|
||||
}
|
||||
|
||||
QJSValue QQuickFontListModel::get(int idx) const
|
||||
QQmlV4Handle QQuickFontListModel::get(int idx) const
|
||||
{
|
||||
Q_D(const QQuickFontListModel);
|
||||
|
||||
QQmlEngine *engine = qmlContext(this)->engine();
|
||||
|
||||
if (idx < 0 || idx >= count())
|
||||
return engine->newObject();
|
||||
return QQmlV4Handle(Value::undefinedValue());
|
||||
|
||||
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());
|
||||
QQmlEngine *engine = qmlContext(this)->engine();
|
||||
QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine);
|
||||
ExecutionEngine *v4engine = QV8Engine::getV4(v8engine);
|
||||
Object *o = v4engine->newObject();
|
||||
for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) {
|
||||
Property *p = o->insertMember(v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1]), PropertyAttributes());
|
||||
p->value = Value::fromReturnedValue(v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1)));
|
||||
}
|
||||
|
||||
return result;
|
||||
return QQmlV4Handle(Value::fromObject(o));
|
||||
}
|
||||
|
||||
QJSValue QQuickFontListModel::pointSizes()
|
||||
QQmlV4Handle QQuickFontListModel::pointSizes()
|
||||
{
|
||||
QQmlEngine *engine = qmlContext(this)->engine();
|
||||
QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine);
|
||||
ExecutionEngine *v4engine = QV8Engine::getV4(v8engine);
|
||||
Scope scope(v4engine);
|
||||
|
||||
QList<int> pss = QFontDatabase::standardSizes();
|
||||
int size = pss.size();
|
||||
|
||||
QJSValue result = engine->newArray(size);
|
||||
Scoped<QV4::ArrayObject> a(scope, v4engine->newArrayObject());
|
||||
a->arrayReserve(size);
|
||||
a->arrayDataLen = size;
|
||||
for (int i = 0; i < size; ++i)
|
||||
result.setProperty(i, pss.at(i));
|
||||
a->arrayData[i].value = Value::fromInt32(pss.at(i));
|
||||
a->setArrayLengthUnchecked(size);
|
||||
|
||||
return result;
|
||||
return QQmlV4Handle(ScopedValue(scope, a.asReturnedValue()));
|
||||
}
|
||||
|
||||
void QQuickFontListModel::classBegin()
|
||||
|
|
|
@ -43,10 +43,10 @@
|
|||
#define QQUICKFONTLISTMODEL_P_H
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/QAbstractListModel>
|
||||
#include <QtCore/qabstractitemmodel.h>
|
||||
#include <QtGui/qpa/qplatformdialoghelper.h>
|
||||
#include <QtQml/qqmlparserstatus.h>
|
||||
#include <QtQml/qjsvalue.h>
|
||||
#include <private/qv8engine_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -90,8 +90,8 @@ public:
|
|||
bool monospacedFonts() const;
|
||||
bool proportionalFonts() const;
|
||||
|
||||
Q_INVOKABLE QJSValue get(int index) const;
|
||||
Q_INVOKABLE QJSValue pointSizes();
|
||||
Q_INVOKABLE QQmlV4Handle get(int index) const;
|
||||
Q_INVOKABLE QQmlV4Handle pointSizes();
|
||||
|
||||
virtual void classBegin();
|
||||
virtual void componentComplete();
|
||||
|
|
|
@ -41,13 +41,17 @@
|
|||
|
||||
#include "qquickwritingsystemlistmodel_p.h"
|
||||
#include <QtGui/qfontdatabase.h>
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QtQml/qqmlcontext.h>
|
||||
#include <QtQml/qqmlengine.h>
|
||||
#include <QtQml/qjsengine.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>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
using namespace QV4;
|
||||
|
||||
class QQuickWritingSystemListModelPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QQuickWritingSystemListModel)
|
||||
|
@ -140,22 +144,23 @@ QStringList QQuickWritingSystemListModel::writingSystems() const
|
|||
return result;
|
||||
}
|
||||
|
||||
QJSValue QQuickWritingSystemListModel::get(int idx) const
|
||||
QQmlV4Handle QQuickWritingSystemListModel::get(int idx) const
|
||||
{
|
||||
Q_D(const QQuickWritingSystemListModel);
|
||||
|
||||
QQmlEngine *engine = qmlContext(this)->engine();
|
||||
|
||||
if (idx < 0 || idx >= count())
|
||||
return engine->newObject();
|
||||
return QQmlV4Handle(Value::undefinedValue());
|
||||
|
||||
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;
|
||||
QQmlEngine *engine = qmlContext(this)->engine();
|
||||
QV8Engine *v8engine = QQmlEnginePrivate::getV8Engine(engine);
|
||||
ExecutionEngine *v4engine = QV8Engine::getV4(v8engine);
|
||||
Object *o = v4engine->newObject();
|
||||
for (int ii = 0; ii < d->roleNames.keys().count(); ++ii) {
|
||||
Property *p = o->insertMember(v4engine->newIdentifier(d->roleNames[Qt::UserRole + ii + 1]), PropertyAttributes());
|
||||
p->value = Value::fromReturnedValue(v8engine->fromVariant(data(index(idx, 0), Qt::UserRole + ii + 1)));
|
||||
}
|
||||
|
||||
return QQmlV4Handle(Value::fromObject(o));
|
||||
}
|
||||
|
||||
void QQuickWritingSystemListModel::classBegin()
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
#define QQUICKWRITINGSYSTEMLISTMODEL_P_H
|
||||
|
||||
#include <QtCore/qstringlist.h>
|
||||
#include <QtCore/QAbstractListModel>
|
||||
#include <QtCore/qabstractitemmodel.h>
|
||||
#include <QtQml/qqmlparserstatus.h>
|
||||
#include <QtQml/qjsvalue.h>
|
||||
#include <private/qv8engine_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -79,7 +79,7 @@ public:
|
|||
|
||||
QStringList writingSystems() const;
|
||||
|
||||
Q_INVOKABLE QJSValue get(int index) const;
|
||||
Q_INVOKABLE QQmlV4Handle get(int index) const;
|
||||
|
||||
virtual void classBegin();
|
||||
virtual void componentComplete();
|
||||
|
|
Loading…
Reference in New Issue