diff options
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmlbind.cpp | 58 | ||||
-rw-r--r-- | src/qml/types/qqmlbind_p.h | 5 | ||||
-rw-r--r-- | src/qml/types/qqmlconnections.cpp | 11 | ||||
-rw-r--r-- | src/qml/types/qqmlconnections_p.h | 2 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 71 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel_p_p.h | 9 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 39 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p.h | 4 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 15 | ||||
-rw-r--r-- | src/qml/types/qquickworkerscript.cpp | 30 |
10 files changed, 157 insertions, 87 deletions
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp index ed9a8533c0..a545fe57ca 100644 --- a/src/qml/types/qqmlbind.cpp +++ b/src/qml/types/qqmlbind.cpp @@ -51,6 +51,7 @@ #include <QtCore/qfile.h> #include <QtCore/qdebug.h> +#include <QtCore/qtimer.h> #include <private/qobject_p.h> @@ -59,16 +60,18 @@ QT_BEGIN_NAMESPACE class QQmlBindPrivate : public QObjectPrivate { public: - QQmlBindPrivate() : componentComplete(true), obj(0) {} + QQmlBindPrivate() : obj(0), componentComplete(true), delayed(false), pendingEval(false) {} ~QQmlBindPrivate() { } QQmlNullableValue<bool> when; - bool componentComplete; QPointer<QObject> obj; QString propName; QQmlNullableValue<QVariant> value; QQmlProperty prop; QQmlAbstractBinding::Ptr prevBind; + bool componentComplete:1; + bool delayed:1; + bool pendingEval:1; void validate(QObject *binding) const; }; @@ -281,7 +284,43 @@ void QQmlBind::setValue(const QVariant &v) { Q_D(QQmlBind); d->value = v; - eval(); + prepareEval(); +} + +/*! + \qmlproperty bool QtQml::Binding::delayed + \since 5.8 + + This property holds whether the binding should be delayed. + + A delayed binding will not immediately update the target, but rather wait + until the event queue has been cleared. This can be used as an optimization, + or to prevent intermediary values from being assigned. + + \code + Binding { + target: contactName; property: 'text' + value: givenName + " " + familyName; when: list.ListView.isCurrentItem + delayed: true + } + \endcode +*/ +bool QQmlBind::delayed() const +{ + Q_D(const QQmlBind); + return d->delayed; +} + +void QQmlBind::setDelayed(bool delayed) +{ + Q_D(QQmlBind); + if (d->delayed == delayed) + return; + + d->delayed = delayed; + + if (!d->delayed) + eval(); } void QQmlBind::setTarget(const QQmlProperty &p) @@ -307,9 +346,22 @@ void QQmlBind::componentComplete() eval(); } +void QQmlBind::prepareEval() +{ + Q_D(QQmlBind); + if (d->delayed) { + if (!d->pendingEval) + QTimer::singleShot(0, this, &QQmlBind::eval); + d->pendingEval = true; + } else { + eval(); + } +} + void QQmlBind::eval() { Q_D(QQmlBind); + d->pendingEval = false; if (!d->prop.isValid() || d->value.isNull || !d->componentComplete) return; diff --git a/src/qml/types/qqmlbind_p.h b/src/qml/types/qqmlbind_p.h index 581995af56..77939a40bc 100644 --- a/src/qml/types/qqmlbind_p.h +++ b/src/qml/types/qqmlbind_p.h @@ -68,6 +68,7 @@ class Q_AUTOTEST_EXPORT QQmlBind : public QObject, public QQmlPropertyValueSourc Q_PROPERTY(QString property READ property WRITE setProperty) Q_PROPERTY(QVariant value READ value WRITE setValue) Q_PROPERTY(bool when READ when WRITE setWhen) + Q_PROPERTY(bool delayed READ delayed WRITE setDelayed REVISION 8) public: QQmlBind(QObject *parent=0); @@ -85,12 +86,16 @@ public: QVariant value() const; void setValue(const QVariant &); + bool delayed() const; + void setDelayed(bool); + protected: virtual void setTarget(const QQmlProperty &); virtual void classBegin(); virtual void componentComplete(); private: + void prepareEval(); void eval(); }; diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp index 597e1bfa86..755345cc1b 100644 --- a/src/qml/types/qqmlconnections.cpp +++ b/src/qml/types/qqmlconnections.cpp @@ -44,7 +44,6 @@ #include <private/qqmlboundsignal_p.h> #include <qqmlcontext.h> #include <private/qqmlcontext_p.h> -#include <private/qqmlcompiler_p.h> #include <qqmlinfo.h> #include <QtCore/qdebug.h> @@ -67,7 +66,7 @@ public: bool ignoreUnknownSignals; bool componentcomplete; - QQmlRefPointer<QQmlCompiledData> cdata; + QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit; QList<const QV4::CompiledData::Binding *> bindings; }; @@ -258,11 +257,11 @@ void QQmlConnectionsParser::verifyBindings(const QV4::CompiledData::Unit *qmlUni } } -void QQmlConnectionsParser::applyBindings(QObject *object, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings) +void QQmlConnectionsParser::applyBindings(QObject *object, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) { QQmlConnectionsPrivate *p = static_cast<QQmlConnectionsPrivate *>(QObjectPrivate::get(object)); - p->cdata = cdata; + p->compilationUnit = compilationUnit; p->bindings = bindings; } @@ -278,7 +277,7 @@ void QQmlConnections::connectSignals() QQmlData *ddata = QQmlData::get(this); QQmlContextData *ctxtdata = ddata ? ddata->outerContext : 0; - const QV4::CompiledData::Unit *qmlUnit = d->cdata->compilationUnit->data; + const QV4::CompiledData::Unit *qmlUnit = d->compilationUnit->data; foreach (const QV4::CompiledData::Binding *binding, d->bindings) { Q_ASSERT(binding->type == QV4::CompiledData::Binding::Type_Script); QString propName = qmlUnit->stringAt(binding->propertyNameIndex); @@ -291,7 +290,7 @@ void QQmlConnections::connectSignals() QQmlBoundSignalExpression *expression = ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, - ctxtdata, this, d->cdata->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]) : 0; + ctxtdata, this, d->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]) : 0; signal->takeExpression(expression); d->boundsignals += signal; } else { diff --git a/src/qml/types/qqmlconnections_p.h b/src/qml/types/qqmlconnections_p.h index ff128a0ca6..d454affba8 100644 --- a/src/qml/types/qqmlconnections_p.h +++ b/src/qml/types/qqmlconnections_p.h @@ -99,7 +99,7 @@ class QQmlConnectionsParser : public QQmlCustomParser { public: virtual void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &props); - virtual void applyBindings(QObject *object, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings); + virtual void applyBindings(QObject *object, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings); }; diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 405242767f..9b58ec35f8 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -48,7 +48,6 @@ #include <private/qqmlengine_p.h> #include <private/qqmlcomponent_p.h> #include <private/qqmlincubator_p.h> -#include <private/qqmlcompiler_p.h> #include <private/qv4value_p.h> #include <private/qv4functionobject_p.h> @@ -63,21 +62,26 @@ namespace QV4 { namespace Heap { struct DelegateModelGroupFunction : FunctionObject { - DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)); + void init(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)); - uint flag; QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg); + uint flag; }; struct QQmlDelegateModelGroupChange : Object { - QQmlDelegateModelGroupChange() {} + void init() { Object::init(); } - QQmlChangeSet::Change change; + QQmlChangeSet::ChangeData change; }; struct QQmlDelegateModelGroupChangeArray : Object { - QQmlDelegateModelGroupChangeArray(const QVector<QQmlChangeSet::Change> &changes); - QVector<QQmlChangeSet::Change> changes; + void init(const QVector<QQmlChangeSet::Change> &changes); + void destroy() { + delete changes; + Object::destroy(); + } + + QVector<QQmlChangeSet::Change> *changes; }; @@ -92,25 +96,25 @@ struct DelegateModelGroupFunction : QV4::FunctionObject return scope->engine()->memoryManager->allocObject<DelegateModelGroupFunction>(scope, flag, code); } - static QV4::ReturnedValue call(const QV4::Managed *that, QV4::CallData *callData) + static void call(const QV4::Managed *that, QV4::Scope &scope, QV4::CallData *callData) { - QV4::ExecutionEngine *v4 = static_cast<const DelegateModelGroupFunction *>(that)->engine(); - QV4::Scope scope(v4); QV4::Scoped<DelegateModelGroupFunction> f(scope, static_cast<const DelegateModelGroupFunction *>(that)); QV4::Scoped<QQmlDelegateModelItemObject> o(scope, callData->thisObject); - if (!o) - return v4->throwTypeError(QStringLiteral("Not a valid VisualData object")); + if (!o) { + scope.result = scope.engine->throwTypeError(QStringLiteral("Not a valid VisualData object")); + return; + } QV4::ScopedValue v(scope, callData->argument(0)); - return f->d()->code(o->d()->item, f->d()->flag, v); + scope.result = f->d()->code(o->d()->item, f->d()->flag, v); } }; -Heap::DelegateModelGroupFunction::DelegateModelGroupFunction(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)) - : QV4::Heap::FunctionObject(scope, QStringLiteral("DelegateModelGroupFunction")) - , flag(flag) - , code(code) +void Heap::DelegateModelGroupFunction::init(QV4::ExecutionContext *scope, uint flag, QV4::ReturnedValue (*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)) { + QV4::Heap::FunctionObject::init(scope, QStringLiteral("DelegateModelGroupFunction")); + this->flag = flag; + this->code = code; } } @@ -235,10 +239,8 @@ void QQmlDelegateModelPrivate::init() } QQmlDelegateModel::QQmlDelegateModel() -: QQmlInstanceModel(*(new QQmlDelegateModelPrivate(0))) + : QQmlDelegateModel(nullptr, nullptr) { - Q_D(QQmlDelegateModel); - d->init(); } QQmlDelegateModel::QQmlDelegateModel(QQmlContext *ctxt, QObject *parent) @@ -1671,7 +1673,7 @@ void QQmlDelegateModelItemMetaType::initializeMetaObject() int notifierId = 0; for (int i = 0; i < groupNames.count(); ++i, ++notifierId) { - QString propertyName = QStringLiteral("in") + groupNames.at(i); + QString propertyName = QLatin1String("in") + groupNames.at(i); propertyName.replace(2, 1, propertyName.at(2).toUpper()); builder.addSignal("__" + propertyName.toUtf8() + "Changed()"); QMetaPropertyBuilder propertyBuilder = builder.addProperty( @@ -1679,7 +1681,7 @@ void QQmlDelegateModelItemMetaType::initializeMetaObject() propertyBuilder.setWritable(true); } for (int i = 0; i < groupNames.count(); ++i, ++notifierId) { - const QString propertyName = groupNames.at(i) + QStringLiteral("Index"); + const QString propertyName = groupNames.at(i) + QLatin1String("Index"); builder.addSignal("__" + propertyName.toUtf8() + "Changed()"); QMetaPropertyBuilder propertyBuilder = builder.addProperty( propertyName.toUtf8(), "int", notifierId); @@ -1727,7 +1729,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype() proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); for (int i = 2; i < groupNames.count(); ++i) { - QString propertyName = QStringLiteral("in") + groupNames.at(i); + QString propertyName = QLatin1String("in") + groupNames.at(i); propertyName.replace(2, 1, propertyName.at(2).toUpper()); s = v4->newString(propertyName); p->setGetter((f = QV4::DelegateModelGroupFunction::create(global, i + 1, QQmlDelegateModelItem::get_member))); @@ -1735,7 +1737,7 @@ void QQmlDelegateModelItemMetaType::initializePrototype() proto->insertMember(s, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable); } for (int i = 2; i < groupNames.count(); ++i) { - const QString propertyName = groupNames.at(i) + QStringLiteral("Index"); + const QString propertyName = groupNames.at(i) + QLatin1String("Index"); s = v4->newString(propertyName); p->setGetter((f = QV4::DelegateModelGroupFunction::create(global, i + 1, QQmlDelegateModelItem::get_index))); p->setSetter(0); @@ -1868,9 +1870,10 @@ QV4::ReturnedValue QQmlDelegateModelItem::get_index(QQmlDelegateModelItem *thisI DEFINE_OBJECT_VTABLE(QQmlDelegateModelItemObject); -QV4::Heap::QQmlDelegateModelItemObject::~QQmlDelegateModelItemObject() +void QV4::Heap::QQmlDelegateModelItemObject::destroy() { item->Dispose(); + Object::destroy(); } @@ -1935,9 +1938,10 @@ void QQmlDelegateModelItem::incubateObject( QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine); QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component); - incubatorPriv->compiledData = componentPriv->cc; - incubatorPriv->compiledData->addref(); - incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->cc, componentPriv->creationContext)); + incubatorPriv->compilationUnit = componentPriv->compilationUnit; + incubatorPriv->compilationUnit->addref(); + incubatorPriv->enginePriv = enginePriv; + incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext)); incubatorPriv->subComponentToCreate = componentPriv->start; enginePriv->incubate(*incubationTask, forContext); @@ -2336,7 +2340,7 @@ QQmlDelegateModelGroup::QQmlDelegateModelGroup(QObject *parent) QQmlDelegateModelGroup::QQmlDelegateModelGroup( const QString &name, QQmlDelegateModel *model, int index, QObject *parent) - : QObject(*new QQmlDelegateModelGroupPrivate, parent) + : QQmlDelegateModelGroup(parent) { Q_D(QQmlDelegateModelGroup); d->name = name; @@ -3258,8 +3262,8 @@ public: return engine->memoryManager->allocObject<QQmlDelegateModelGroupChangeArray>(changes); } - quint32 count() const { return d()->changes.count(); } - const QQmlChangeSet::Change &at(int index) const { return d()->changes.at(index); } + quint32 count() const { return d()->changes->count(); } + const QQmlChangeSet::Change &at(int index) const { return d()->changes->at(index); } static QV4::ReturnedValue getIndexed(const QV4::Managed *m, uint index, bool *hasProperty) { @@ -3301,9 +3305,10 @@ public: } }; -QV4::Heap::QQmlDelegateModelGroupChangeArray::QQmlDelegateModelGroupChangeArray(const QVector<QQmlChangeSet::Change> &changes) - : changes(changes) +void QV4::Heap::QQmlDelegateModelGroupChangeArray::init(const QVector<QQmlChangeSet::Change> &changes) { + Object::init(); + this->changes = new QVector<QQmlChangeSet::Change>(changes); QV4::Scope scope(internalClass->engine); QV4::ScopedObject o(scope, this); o->setArrayType(QV4::Heap::ArrayData::Custom); diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index bf9fd99f19..6cb82fddfc 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -160,8 +160,8 @@ protected: namespace QV4 { namespace Heap { struct QQmlDelegateModelItemObject : Object { - inline QQmlDelegateModelItemObject(QQmlDelegateModelItem *item); - ~QQmlDelegateModelItemObject(); + inline void init(QQmlDelegateModelItem *item); + void destroy(); QQmlDelegateModelItem *item; }; @@ -174,9 +174,10 @@ struct QQmlDelegateModelItemObject : QV4::Object V4_NEEDS_DESTROY }; -QV4::Heap::QQmlDelegateModelItemObject::QQmlDelegateModelItemObject(QQmlDelegateModelItem *item) - : item(item) +void QV4::Heap::QQmlDelegateModelItemObject::init(QQmlDelegateModelItem *item) { + Object::init(); + this->item = item; } diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 7be345459d..2ba164f721 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -42,7 +42,6 @@ #include <private/qqmlopenmetaobject_p.h> #include <private/qqmljsast_p.h> #include <private/qqmljsengine_p.h> -#include <private/qqmlcompiler_p.h> #include <private/qqmlcustomparser_p.h> #include <private/qqmlengine_p.h> @@ -82,13 +81,16 @@ static bool isMemoryUsed(const char *mem) static QString roleTypeName(ListLayout::Role::DataType t) { - QString result; - const char *roleTypeNames[] = { "String", "Number", "Bool", "List", "QObject", "VariantMap", "DateTime" }; + static const QString roleTypeNames[] = { + QStringLiteral("String"), QStringLiteral("Number"), QStringLiteral("Bool"), + QStringLiteral("List"), QStringLiteral("QObject"), QStringLiteral("VariantMap"), + QStringLiteral("DateTime") + }; if (t > ListLayout::Role::Invalid && t < ListLayout::Role::MaxDataType) - result = QString::fromLatin1(roleTypeNames[t]); + return roleTypeNames[t]; - return result; + return QString(); } const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::DataType type) @@ -1478,8 +1480,7 @@ void DynamicRoleModelNode::updateValues(const QVariantMap &object, QVector<int> const QByteArray &keyUtf8 = key.toUtf8(); QQmlListModel *existingModel = qobject_cast<QQmlListModel *>(m_meta->value(keyUtf8).value<QObject *>()); - if (existingModel) - delete existingModel; + delete existingModel; if (m_meta->setValue(keyUtf8, value)) roles << roleIndex; @@ -1495,8 +1496,7 @@ DynamicRoleModelNodeMetaObject::~DynamicRoleModelNodeMetaObject() { for (int i=0 ; i < count() ; ++i) { QQmlListModel *subModel = qobject_cast<QQmlListModel *>(value(i).value<QObject *>()); - if (subModel) - delete subModel; + delete subModel; } } @@ -1507,8 +1507,7 @@ void DynamicRoleModelNodeMetaObject::propertyWrite(int index) QVariant v = value(index); QQmlListModel *model = qobject_cast<QQmlListModel *>(v.value<QObject *>()); - if (model) - delete model; + delete model; } void DynamicRoleModelNodeMetaObject::propertyWritten(int index) @@ -2019,15 +2018,7 @@ void QQmlListModel::setDynamicRoles(bool enableDynamicRoles) */ int QQmlListModel::count() const { - int count; - - if (m_dynamicRoles) - count = m_modelObjects.count(); - else { - count = m_listModel->elementCount(); - } - - return count; + return m_dynamicRoles ? m_modelObjects.count() : m_listModel->elementCount(); } /*! @@ -2039,7 +2030,7 @@ int QQmlListModel::count() const */ void QQmlListModel::clear() { - int cleared = count(); + const int cleared = count(); emitItemsAboutToBeRemoved(0, cleared); @@ -2449,7 +2440,7 @@ bool QQmlListModelParser::verifyProperty(const QV4::CompiledData::Unit *qmlUnit, listElementTypeName = objName; // cache right name for next time } - if (!qmlUnit->stringAt(target->idIndex).isEmpty()) { + if (!qmlUnit->stringAt(target->idNameIndex).isEmpty()) { error(target->locationOfIdProperty, QQmlListModel::tr("ListElement: cannot use reserved \"id\" property")); return false; } @@ -2556,13 +2547,13 @@ void QQmlListModelParser::verifyBindings(const QV4::CompiledData::Unit *qmlUnit, } } -void QQmlListModelParser::applyBindings(QObject *obj, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings) +void QQmlListModelParser::applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) { QQmlListModel *rv = static_cast<QQmlListModel *>(obj); rv->m_engine = QV8Engine::getV4(qmlEngine(rv)); - const QV4::CompiledData::Unit *qmlUnit = cdata->compilationUnit->data; + const QV4::CompiledData::Unit *qmlUnit = compilationUnit->data; bool setRoles = false; diff --git a/src/qml/types/qqmllistmodel_p.h b/src/qml/types/qqmllistmodel_p.h index b35a5a1224..220b0e54b5 100644 --- a/src/qml/types/qqmllistmodel_p.h +++ b/src/qml/types/qqmllistmodel_p.h @@ -187,8 +187,8 @@ public: QQmlListModelParser() : QQmlCustomParser(QQmlCustomParser::AcceptsSignalHandlers) {} - virtual void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings); - virtual void applyBindings(QObject *obj, QQmlCompiledData *cdata, const QList<const QV4::CompiledData::Binding *> &bindings); + void verifyBindings(const QV4::CompiledData::Unit *qmlUnit, const QList<const QV4::CompiledData::Binding *> &bindings) Q_DECL_OVERRIDE; + void applyBindings(QObject *obj, QV4::CompiledData::CompilationUnit *compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) Q_DECL_OVERRIDE; private: bool verifyProperty(const QV4::CompiledData::Unit *qmlUnit, const QV4::CompiledData::Binding *binding); diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index 5e5ad6dcb4..5ff8b9671f 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -164,11 +164,13 @@ namespace QV4 { namespace Heap { struct ModelObject : public QObjectWrapper { - ModelObject(QObject *object, QQmlListModel *model, int elementIndex) - : QObjectWrapper(object) - , m_model(model) - , m_elementIndex(elementIndex) - {} + void init(QObject *object, QQmlListModel *model, int elementIndex) + { + QObjectWrapper::init(object); + m_model = model; + m_elementIndex = elementIndex; + } + void destroy() { QObjectWrapper::destroy(); } QQmlListModel *m_model; int m_elementIndex; }; @@ -182,6 +184,7 @@ struct ModelObject : public QObjectWrapper static void advanceIterator(Managed *m, ObjectIterator *it, Value *name, uint *index, Property *p, PropertyAttributes *attributes); V4_OBJECT2(ModelObject, QObjectWrapper) + V4_NEEDS_DESTROY }; } // namespace QV4 @@ -201,7 +204,7 @@ public: explicit Role(const Role *other); ~Role(); - // This enum must be kept in sync with the roleTypeNames variable in qdeclarativelistmodel.cpp + // This enum must be kept in sync with the roleTypeNames variable in qqmllistmodel.cpp enum DataType { Invalid = -1, diff --git a/src/qml/types/qquickworkerscript.cpp b/src/qml/types/qquickworkerscript.cpp index e819e4ee7d..78e7776c9b 100644 --- a/src/qml/types/qquickworkerscript.cpp +++ b/src/qml/types/qquickworkerscript.cpp @@ -52,10 +52,12 @@ #include <QtCore/qwaitcondition.h> #include <QtCore/qfile.h> #include <QtCore/qdatetime.h> -#include <QtNetwork/qnetworkaccessmanager.h> #include <QtQml/qqmlinfo.h> #include <QtQml/qqmlfile.h> +#if QT_CONFIG(qml_network) +#include <QtNetwork/qnetworkaccessmanager.h> #include "qqmlnetworkaccessmanagerfactory.h" +#endif #include <private/qv8engine_p.h> #include <private/qv4serialize_p.h> @@ -141,7 +143,10 @@ public: ~WorkerEngine(); void init(); + +#if QT_CONFIG(qml_network) virtual QNetworkAccessManager *networkAccessManager(); +#endif QQuickWorkerScriptEnginePrivate *p; @@ -150,7 +155,9 @@ public: QV4::PersistentValue onmessage; private: QV4::PersistentValue createsend; +#if QT_CONFIG(qml_network) QNetworkAccessManager *accessManager; +#endif }; WorkerEngine *workerEngine; @@ -194,14 +201,19 @@ private: }; QQuickWorkerScriptEnginePrivate::WorkerEngine::WorkerEngine(QQuickWorkerScriptEnginePrivate *parent) -: QV8Engine(0), p(parent), accessManager(0) +: QV8Engine(0), p(parent) +#if QT_CONFIG(qml_network) +, accessManager(0) +#endif { m_v4Engine->v8Engine = this; } QQuickWorkerScriptEnginePrivate::WorkerEngine::~WorkerEngine() { +#if QT_CONFIG(qml_network) delete accessManager; +#endif } void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() @@ -239,7 +251,8 @@ void QQuickWorkerScriptEnginePrivate::WorkerEngine::init() QV4::ScopedCallData callData(scope, 1); callData->args[0] = function; callData->thisObject = global(); - createsend.set(scope.engine, createsendconstructor->call(callData)); + createsendconstructor->call(scope, callData); + createsend.set(scope.engine, scope.result.asReturnedValue()); } // Requires handle and context scope @@ -252,16 +265,16 @@ QV4::ReturnedValue QQuickWorkerScriptEnginePrivate::WorkerEngine::sendFunction(i QV4::Scope scope(v4); QV4::ScopedFunctionObject f(scope, createsend.value()); - QV4::ScopedValue v(scope); QV4::ScopedCallData callData(scope, 1); callData->args[0] = QV4::Primitive::fromInt32(id); callData->thisObject = global(); - v = f->call(callData); + f->call(scope, callData); if (scope.hasException()) - v = scope.engine->catchException(); - return v->asReturnedValue(); + scope.result = scope.engine->catchException(); + return scope.result.asReturnedValue(); } +#if QT_CONFIG(qml_network) QNetworkAccessManager *QQuickWorkerScriptEnginePrivate::WorkerEngine::networkAccessManager() { if (!accessManager) { @@ -273,6 +286,7 @@ QNetworkAccessManager *QQuickWorkerScriptEnginePrivate::WorkerEngine::networkAcc } return accessManager; } +#endif QQuickWorkerScriptEnginePrivate::QQuickWorkerScriptEnginePrivate(QQmlEngine *engine) : workerEngine(0), qmlengine(engine), m_nextId(0) @@ -366,7 +380,7 @@ void QQuickWorkerScriptEnginePrivate::processMessage(int id, const QByteArray &d callData->thisObject = workerEngine->global(); callData->args[0] = qmlContext->d()->qml; // ### callData->args[1] = value; - f->call(callData); + f->call(scope, callData); if (scope.hasException()) { QQmlError error = scope.engine->catchExceptionAsQmlError(); reportScriptException(script, error); |