From 21301c1dbb00f4a2cd991e520423ed039b297ffb Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 20 Mar 2018 09:44:30 -0500 Subject: Simplify handling of function expressions as signal handlers Change-Id: I4bfa05b4619c248119c78d05e64270e6627f6065 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlboundsignal.cpp | 12 ++++++++++++ src/qml/qml/qqmlobjectcreator.cpp | 8 -------- src/qml/types/qqmlconnections.cpp | 7 ------- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'src/qml') diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index 060706ac50..d5117c8cec 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -110,6 +110,12 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, m_index(index), m_target(target) { + // If the function is marked as having a nested function, then the user wrote: + // onSomeSignal: function() { /*....*/ } + // So take that nested function: + if (auto closure = function->nestedFunction()) + function = closure; + setupFunction(scope, function); init(ctxt, scopeObject); } @@ -122,6 +128,12 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, // It's important to call init first, because m_index gets remapped in case of cloned signals. init(ctxt, scope); + // If the function is marked as having a nested function, then the user wrote: + // onSomeSignal: function() { /*....*/ } + // So take that nested function: + if (auto closure = runtimeFunction->nestedFunction()) + runtimeFunction = closure; + QV4::ExecutionEngine *engine = ctxt->engine->handle(); QList signalParameters = QMetaObjectPrivate::signal(m_target->metaObject(), m_index).parameterNames(); diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 7c36f59035..7051fb51da 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -879,14 +879,6 @@ bool QQmlObjectCreator::setPropertyBinding(const QQmlPropertyData *bindingProper if (binding->type == QV4::CompiledData::Binding::Type_Script || binding->containsTranslations()) { if (binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression) { QV4::Function *runtimeFunction = compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]; - - // When a user writes the following: - // onSignal: function() { doSomethingUsefull } - // then do not run the binding that returns the closure, but run the closure - // instead. - if (auto closure = runtimeFunction->nestedFunction()) - runtimeFunction = closure; - int signalIndex = _propertyCache->methodIndexToSignalIndex(bindingProperty->coreIndex()); QQmlBoundSignal *bs = new QQmlBoundSignal(_bindingTarget, signalIndex, _scopeObject, engine); QQmlBoundSignalExpression *expr = new QQmlBoundSignalExpression(_bindingTarget, signalIndex, diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp index d1a7aa9b6f..2ae3df6ebb 100644 --- a/src/qml/types/qqmlconnections.cpp +++ b/src/qml/types/qqmlconnections.cpp @@ -289,13 +289,6 @@ void QQmlConnections::connectSignals() signal->setEnabled(d->enabled); auto f = d->compilationUnit->runtimeFunctions[binding->value.compiledScriptIndex]; - - // If the function is marked as having a nested function, then the user wrote: - // onSomeSignal: function() { /*....*/ } - // So take that nested function: - if (auto closure = f->nestedFunction()) - f = closure; - QQmlBoundSignalExpression *expression = ctxtdata ? new QQmlBoundSignalExpression(target, signalIndex, ctxtdata, this, f) : nullptr; -- cgit v1.2.3 From 8629682663adb0de5f91d2bd545b5d68e6afb7cd Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 18 Dec 2017 17:40:48 +0100 Subject: Add a feature for DelegateModel Change-Id: Ia24767b33a20bd70096bbb8b4f27729c788eb331 Reviewed-by: Oswald Buddenhagen --- src/qml/configure.json | 9 ++++++++- src/qml/qml/qqmlengine.cpp | 4 ++++ src/qml/types/qqmldelegatemodel_p.h | 2 ++ src/qml/types/qqmldelegatemodel_p_p.h | 2 ++ src/qml/types/qqmlinstantiator.cpp | 27 ++++++++++++++++++++++----- src/qml/types/qqmlinstantiator_p_p.h | 4 ++++ src/qml/types/qqmlmodelsmodule.cpp | 4 ++++ src/qml/types/types.pri | 12 +++++++++--- src/qml/util/qqmladaptormodel_p.h | 2 ++ src/qml/util/util.pri | 10 ++++++++-- 10 files changed, 65 insertions(+), 11 deletions(-) (limited to 'src/qml') diff --git a/src/qml/configure.json b/src/qml/configure.json index b744ea6948..681cecea99 100644 --- a/src/qml/configure.json +++ b/src/qml/configure.json @@ -39,6 +39,12 @@ "features.xmlstreamwriter" ], "output": [ "privateFeature" ] + }, + "qml-delegate-model": { + "label": "QML delegate model", + "purpose": "Provides the DelegateModel QML type.", + "section": "QML", + "output": [ "privateFeature" ] } }, @@ -47,7 +53,8 @@ "section": "Qt QML", "entries": [ "qml-network", - "qml-debug" + "qml-debug", + "qml-delegate-model" ] } ] diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index 49f25e89fe..ebd354d003 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -88,7 +88,9 @@ #include #include #include +#if QT_CONFIG(qml_delegate_model) #include +#endif #include #include #include @@ -240,8 +242,10 @@ void QQmlEnginePrivate::registerQtQuick2Types(const char *uri, int versionMajor, qmlRegisterCustomType(uri, versionMajor, versionMinor, "ListModel", new QQmlListModelParser); // Now in QtQml.Models, here for compatibility qmlRegisterType(uri, versionMajor, versionMinor, "WorkerScript"); qmlRegisterType(uri, versionMajor, versionMinor, "Package"); +#if QT_CONFIG(qml_delegate_model) qmlRegisterType(uri, versionMajor, versionMinor, "VisualDataModel"); qmlRegisterType(uri, versionMajor, versionMinor, "VisualDataGroup"); +#endif qmlRegisterType(uri, versionMajor, versionMinor, "VisualItemModel"); } diff --git a/src/qml/types/qqmldelegatemodel_p.h b/src/qml/types/qqmldelegatemodel_p.h index b894df8f82..b0786cd088 100644 --- a/src/qml/types/qqmldelegatemodel_p.h +++ b/src/qml/types/qqmldelegatemodel_p.h @@ -62,6 +62,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_delegate_model); + QT_BEGIN_NAMESPACE class QQmlChangeSet; diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index 68b987a5fa..18980cfd7c 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -60,6 +60,8 @@ // We mean it. // +QT_REQUIRE_CONFIG(qml_delegate_model); + QT_BEGIN_NAMESPACE typedef QQmlListCompositor Compositor; diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp index 213bef7879..030758fa3b 100644 --- a/src/qml/types/qqmlinstantiator.cpp +++ b/src/qml/types/qqmlinstantiator.cpp @@ -44,7 +44,9 @@ #include #include #include +#if QT_CONFIG(qml_delegate_model) #include +#endif QT_BEGIN_NAMESPACE @@ -53,7 +55,9 @@ QQmlInstantiatorPrivate::QQmlInstantiatorPrivate() , effectiveReset(false) , active(true) , async(false) +#if QT_CONFIG(qml_delegate_model) , ownModel(false) +#endif , requestedIndex(-1) , model(QVariant(1)) , instanceModel(nullptr) @@ -198,6 +202,7 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo q->countChanged(); } +#if QT_CONFIG(qml_delegate_model) void QQmlInstantiatorPrivate::makeModel() { Q_Q(QQmlInstantiator); @@ -209,6 +214,7 @@ void QQmlInstantiatorPrivate::makeModel() if (componentComplete) delegateModel->componentComplete(); } +#endif /*! @@ -349,6 +355,7 @@ void QQmlInstantiator::setDelegate(QQmlComponent* c) d->delegate = c; emit delegateChanged(); +#if QT_CONFIG(qml_delegate_model) if (!d->ownModel) return; @@ -356,6 +363,7 @@ void QQmlInstantiator::setDelegate(QQmlComponent* c) dModel->setDelegate(c); if (d->componentComplete) d->regenerate(); +#endif } /*! @@ -398,12 +406,15 @@ void QQmlInstantiator::setModel(const QVariant &v) QObject *object = qvariant_cast(v); QQmlInstanceModel *vim = nullptr; if (object && (vim = qobject_cast(object))) { +#if QT_CONFIG(qml_delegate_model) if (d->ownModel) { delete d->instanceModel; prevModel = nullptr; d->ownModel = false; } +#endif d->instanceModel = vim; +#if QT_CONFIG(qml_delegate_model) } else if (v != QVariant(0)){ if (!d->ownModel) d->makeModel(); @@ -413,6 +424,7 @@ void QQmlInstantiator::setModel(const QVariant &v) dataModel->setModel(v); d->effectiveReset = false; } +#endif } if (d->instanceModel != prevModel) { @@ -423,10 +435,12 @@ void QQmlInstantiator::setModel(const QVariant &v) //disconnect(prevModel, SIGNAL(initItem(int,QObject*)), this, SLOT(initItem(int,QObject*))); } - connect(d->instanceModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), - this, SLOT(_q_modelUpdated(QQmlChangeSet,bool))); - connect(d->instanceModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(_q_createdItem(int,QObject*))); - //connect(d->instanceModel, SIGNAL(initItem(int,QObject*)), this, SLOT(initItem(int,QObject*))); + if (d->instanceModel) { + connect(d->instanceModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), + this, SLOT(_q_modelUpdated(QQmlChangeSet,bool))); + connect(d->instanceModel, SIGNAL(createdItem(int,QObject*)), this, SLOT(_q_createdItem(int,QObject*))); + //connect(d->instanceModel, SIGNAL(initItem(int,QObject*)), this, SLOT(initItem(int,QObject*))); + } } d->regenerate(); @@ -476,10 +490,13 @@ void QQmlInstantiator::componentComplete() { Q_D(QQmlInstantiator); d->componentComplete = true; +#if QT_CONFIG(qml_delegate_model) if (d->ownModel) { static_cast(d->instanceModel)->componentComplete(); d->regenerate(); - } else { + } else +#endif + { QVariant realModel = d->model; d->model = QVariant(0); setModel(realModel); //If realModel == d->model this won't do anything, but that's fine since the model's 0 diff --git a/src/qml/types/qqmlinstantiator_p_p.h b/src/qml/types/qqmlinstantiator_p_p.h index 9edaecf7a8..a5a4d1a32d 100644 --- a/src/qml/types/qqmlinstantiator_p_p.h +++ b/src/qml/types/qqmlinstantiator_p_p.h @@ -69,7 +69,9 @@ public: void clear(); void regenerate(); +#if QT_CONFIG(qml_delegate_model) void makeModel(); +#endif void _q_createdItem(int, QObject *); void _q_modelUpdated(const QQmlChangeSet &, bool); QObject *modelObject(int index, bool async); @@ -78,7 +80,9 @@ public: bool effectiveReset:1; bool active:1; bool async:1; +#if QT_CONFIG(qml_delegate_model) bool ownModel:1; +#endif int requestedIndex; QVariant model; QQmlInstanceModel *instanceModel; diff --git a/src/qml/types/qqmlmodelsmodule.cpp b/src/qml/types/qqmlmodelsmodule.cpp index c36e26a525..e217b63c6f 100644 --- a/src/qml/types/qqmlmodelsmodule.cpp +++ b/src/qml/types/qqmlmodelsmodule.cpp @@ -40,7 +40,9 @@ #include "qqmlmodelsmodule_p.h" #include #include +#if QT_CONFIG(qml_delegate_model) #include +#endif #include QT_BEGIN_NAMESPACE @@ -51,8 +53,10 @@ void QQmlModelsModule::defineModule() qmlRegisterType(uri, 2, 1, "ListElement"); qmlRegisterCustomType(uri, 2, 1, "ListModel", new QQmlListModelParser); +#if QT_CONFIG(qml_delegate_model) qmlRegisterType(uri, 2, 1, "DelegateModel"); qmlRegisterType(uri, 2, 1, "DelegateModelGroup"); +#endif qmlRegisterType(uri, 2, 1, "ObjectModel"); qmlRegisterType(uri, 2, 3, "ObjectModel"); diff --git a/src/qml/types/types.pri b/src/qml/types/types.pri index e85ab5982b..8bcbd6e544 100644 --- a/src/qml/types/types.pri +++ b/src/qml/types/types.pri @@ -1,7 +1,6 @@ SOURCES += \ $$PWD/qqmlbind.cpp \ $$PWD/qqmlconnections.cpp \ - $$PWD/qqmldelegatemodel.cpp \ $$PWD/qqmllistmodel.cpp \ $$PWD/qqmllistmodelworkeragent.cpp \ $$PWD/qqmlmodelsmodule.cpp \ @@ -14,8 +13,6 @@ SOURCES += \ HEADERS += \ $$PWD/qqmlbind_p.h \ $$PWD/qqmlconnections_p.h \ - $$PWD/qqmldelegatemodel_p.h \ - $$PWD/qqmldelegatemodel_p_p.h \ $$PWD/qqmllistmodel_p.h \ $$PWD/qqmllistmodel_p_p.h \ $$PWD/qqmllistmodelworkeragent_p.h \ @@ -27,6 +24,15 @@ HEADERS += \ $$PWD/qqmlinstantiator_p.h \ $$PWD/qqmlinstantiator_p_p.h +qtConfig(qml-delegate-model) { + SOURCES += \ + $$PWD/qqmldelegatemodel.cpp + + HEADERS += \ + $$PWD/qqmldelegatemodel_p.h \ + $$PWD/qqmldelegatemodel_p_p.h +} + qtConfig(animation) { SOURCES += \ $$PWD/qqmltimer.cpp diff --git a/src/qml/util/qqmladaptormodel_p.h b/src/qml/util/qqmladaptormodel_p.h index 8f773efa20..b152a886a5 100644 --- a/src/qml/util/qqmladaptormodel_p.h +++ b/src/qml/util/qqmladaptormodel_p.h @@ -57,6 +57,8 @@ #include +QT_REQUIRE_CONFIG(qml_delegate_model); + QT_BEGIN_NAMESPACE class QQmlEngine; diff --git a/src/qml/util/util.pri b/src/qml/util/util.pri index a9c5ffe9b7..bebb271f1b 100644 --- a/src/qml/util/util.pri +++ b/src/qml/util/util.pri @@ -2,12 +2,18 @@ SOURCES += \ $$PWD/qqmlchangeset.cpp \ $$PWD/qqmllistaccessor.cpp \ $$PWD/qqmllistcompositor.cpp \ - $$PWD/qqmladaptormodel.cpp \ $$PWD/qqmlpropertymap.cpp HEADERS += \ $$PWD/qqmlchangeset_p.h \ $$PWD/qqmllistaccessor_p.h \ $$PWD/qqmllistcompositor_p.h \ - $$PWD/qqmladaptormodel_p.h \ $$PWD/qqmlpropertymap.h + +qtConfig(qml-delegate-model) { + SOURCES += \ + $$PWD/qqmladaptormodel.cpp + + HEADERS += \ + $$PWD/qqmladaptormodel_p.h +} -- cgit v1.2.3 From 214fbaa57b73296a0a191b5ff2b1fbc8bf0aaa7a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 26 Feb 2018 09:16:06 +0100 Subject: add qmlRegisterModule to all QML plugins (QUIP 99) Now it should always be possible to do import QtQuick.Module x.m where x is the module's major version and m is Qt's minor version. [ChangeLog][QtQuick][Important Behavior Changes] In Qt 5.11 and newer versions, QML plugin modules are available with the same minor version as the Qt release minor version number. For example it's possible to import QtQuick.Window 2.11 or import QtQuick.Layouts 1.11 even though there haven't been any API changes in these modules for Qt 5.11, and the maximum possible import version will automatically increment in future Qt versions. This is intended to reduce confusion. Change-Id: I0d28ed04d186bcdd5acde95b8ed0b66c1c4697e3 Reviewed-by: J-P Nurmi --- src/qml/qml/qqmlengine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/qml') diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index ebd354d003..54a7c5130d 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -257,6 +257,9 @@ void QQmlEnginePrivate::defineQtQuick2Module() // register the QtQuick2 types which are implemented in the QtQml module. registerQtQuick2Types("QtQuick",2,0); qmlRegisterUncreatableType("QtQuick", 2, 0, "Locale", QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); + + // Auto-increment the import to stay in sync with ALL future QtQuick minor versions from 5.11 onward + qmlRegisterModule("QtQuick", 2, QT_VERSION_MINOR); } bool QQmlEnginePrivate::designerMode() @@ -956,6 +959,9 @@ void QQmlEnginePrivate::init() registerBaseTypes("QtQml", 2, 0); // import which provides language building blocks. qmlRegisterUncreatableType("QtQml", 2, 2, "Locale", QQmlEngine::tr("Locale cannot be instantiated. Use Qt.locale()")); + // Auto-increment the import to stay in sync with ALL future QtQml minor versions from 5.11 onward + qmlRegisterModule("QtQml", 2, QT_VERSION_MINOR); + QQmlData::init(); baseModulesUninitialized = false; } -- cgit v1.2.3