From b56273a77872ea0516767d4fbdb846a8b5103da4 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 10 Apr 2019 16:03:52 +0200 Subject: Add features for the remaining QML model types The table and object models should be configurable, too, and Package conceptually belongs to the delegate model. Change-Id: Id928f14c5b378b6e7ffcbb98039192fa7c375fa7 Reviewed-by: Simon Hausmann --- src/qmlmodels/configure.json | 13 ++++++++ src/qmlmodels/qmlmodels.pro | 54 +++++++++++++++++++------------- src/qmlmodels/qqmlinstantiator_p.h | 2 ++ src/qmlmodels/qqmlinstantiator_p_p.h | 2 ++ src/qmlmodels/qqmlmodelsmodule.cpp | 31 +++++++++++++----- src/qmlmodels/qqmlobjectmodel_p.h | 2 ++ src/qmlmodels/qqmltableinstancemodel_p.h | 2 ++ src/qmlmodels/qqmltablemodel_p.h | 2 ++ src/qmlmodels/qqmltablemodelcolumn_p.h | 2 ++ src/qmlmodels/qquickpackage_p.h | 3 ++ 10 files changed, 84 insertions(+), 29 deletions(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/configure.json b/src/qmlmodels/configure.json index 2aa8a50e69..bfe7d538ec 100644 --- a/src/qmlmodels/configure.json +++ b/src/qmlmodels/configure.json @@ -6,6 +6,12 @@ ], "features": { + "qml-object-model" : { + "label": "QML list model", + "purpose": "Provides the ObjectModel and Instantiator QML types.", + "section": "QML", + "output": [ "privateFeature" ] + }, "qml-list-model": { "label": "QML list model", "purpose": "Provides the ListModel QML type.", @@ -16,6 +22,13 @@ "label": "QML delegate model", "purpose": "Provides the DelegateModel QML type.", "section": "QML", + "condition": "features.qml-object-model", + "output": [ "privateFeature" ] + }, + "qml-table-model": { + "label": "QML table model", + "purpose": "Provides the TableModel QML type.", + "section": "QML", "output": [ "privateFeature" ] } }, diff --git a/src/qmlmodels/qmlmodels.pro b/src/qmlmodels/qmlmodels.pro index 84f87f8bb1..7d1d9bdf67 100644 --- a/src/qmlmodels/qmlmodels.pro +++ b/src/qmlmodels/qmlmodels.pro @@ -5,30 +5,36 @@ DEFINES += QT_NO_URL_CAST_FROM_STRING QT_NO_INTEGER_EVENT_COORDINATES QT_NO_FORE HEADERS += \ $$PWD/qqmlchangeset_p.h \ - $$PWD/qqmlinstantiator_p.h \ - $$PWD/qqmlinstantiator_p_p.h \ - $$PWD/qqmllistaccessor_p.h \ - $$PWD/qqmllistcompositor_p.h \ $$PWD/qqmlmodelsmodule_p.h \ - $$PWD/qqmlobjectmodel_p.h \ - $$PWD/qqmltableinstancemodel_p.h \ - $$PWD/qqmltablemodel_p.h \ - $$PWD/qqmltablemodelcolumn_p.h \ - $$PWD/qquickpackage_p.h \ $$PWD/qtqmlmodelsglobal_p.h \ - $$PWD/qtqmlmodelsglobal.h \ + $$PWD/qtqmlmodelsglobal.h SOURCES += \ $$PWD/qqmlchangeset.cpp \ - $$PWD/qqmlinstantiator.cpp \ - $$PWD/qqmllistaccessor.cpp \ - $$PWD/qqmllistcompositor.cpp \ - $$PWD/qqmlmodelsmodule.cpp \ - $$PWD/qqmlobjectmodel.cpp \ - $$PWD/qqmltableinstancemodel.cpp \ - $$PWD/qqmltablemodel.cpp \ - $$PWD/qqmltablemodelcolumn.cpp \ - $$PWD/qquickpackage.cpp + $$PWD/qqmlmodelsmodule.cpp + +qtConfig(qml-object-model) { + SOURCES += \ + $$PWD/qqmlinstantiator.cpp \ + $$PWD/qqmlobjectmodel.cpp + + HEADERS += \ + $$PWD/qqmlinstantiator_p.h \ + $$PWD/qqmlinstantiator_p_p.h \ + $$PWD/qqmlobjectmodel_p.h +} + +qtConfig(qml-table-model) { + SOURCES += \ + $$PWD/qqmltableinstancemodel.cpp \ + $$PWD/qqmltablemodel.cpp \ + $$PWD/qqmltablemodelcolumn.cpp + + HEADERS += \ + $$PWD/qqmltableinstancemodel_p.h \ + $$PWD/qqmltablemodel_p.h \ + $$PWD/qqmltablemodelcolumn_p.h +} qtConfig(qml-list-model) { SOURCES += \ @@ -45,13 +51,19 @@ qtConfig(qml-delegate-model) { SOURCES += \ $$PWD/qqmladaptormodel.cpp \ $$PWD/qqmldelegatemodel.cpp \ - $$PWD/qqmldelegatecomponent.cpp + $$PWD/qqmldelegatecomponent.cpp \ + $$PWD/qqmllistaccessor.cpp \ + $$PWD/qqmllistcompositor.cpp \ + $$PWD/qquickpackage.cpp HEADERS += \ $$PWD/qqmladaptormodel_p.h \ $$PWD/qqmldelegatemodel_p.h \ $$PWD/qqmldelegatemodel_p_p.h \ - $$PWD/qqmldelegatecomponent_p.h + $$PWD/qqmldelegatecomponent_p.h \ + $$PWD/qqmllistaccessor_p.h \ + $$PWD/qqmllistcompositor_p.h \ + $$PWD/qquickpackage_p.h } load(qt_module) diff --git a/src/qmlmodels/qqmlinstantiator_p.h b/src/qmlmodels/qqmlinstantiator_p.h index 8b00a1e033..87accc304f 100644 --- a/src/qmlmodels/qqmlinstantiator_p.h +++ b/src/qmlmodels/qqmlinstantiator_p.h @@ -55,6 +55,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_object_model); + QT_BEGIN_NAMESPACE class QQmlInstantiatorPrivate; diff --git a/src/qmlmodels/qqmlinstantiator_p_p.h b/src/qmlmodels/qqmlinstantiator_p_p.h index bf153d8723..33cc2613e5 100644 --- a/src/qmlmodels/qqmlinstantiator_p_p.h +++ b/src/qmlmodels/qqmlinstantiator_p_p.h @@ -57,6 +57,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_object_model); + QT_BEGIN_NAMESPACE class Q_QMLMODELS_PRIVATE_EXPORT QQmlInstantiatorPrivate : public QObjectPrivate diff --git a/src/qmlmodels/qqmlmodelsmodule.cpp b/src/qmlmodels/qqmlmodelsmodule.cpp index 989fec9b7d..2db5dd834f 100644 --- a/src/qmlmodels/qqmlmodelsmodule.cpp +++ b/src/qmlmodels/qqmlmodelsmodule.cpp @@ -39,19 +39,26 @@ #include "qqmlmodelsmodule_p.h" #include + +#if QT_CONFIG(itemmodel) #include +#endif #if QT_CONFIG(qml_list_model) #include #endif #if QT_CONFIG(qml_delegate_model) #include #include +#include #endif +#if QT_CONFIG(qml_object_model) #include +#include +#endif +#if QT_CONFIG(qml_table_model) #include #include -#include -#include +#endif QT_BEGIN_NAMESPACE @@ -60,8 +67,10 @@ QT_BEGIN_NAMESPACE void QQmlModelsModule::registerQmlTypes() { // Don't add anything here. These are only for backwards compatibility. +#if QT_CONFIG(qml_object_model) qmlRegisterType("QtQml", 2, 1, "Instantiator"); // Only available in >= 2.1 qmlRegisterType(); +#endif } void QQmlModelsModule::registerQuickTypes() @@ -70,18 +79,20 @@ void QQmlModelsModule::registerQuickTypes() const char uri[] = "QtQuick"; +#if QT_CONFIG(qml_object_model) qmlRegisterType(uri, 2, 1, "Instantiator"); qmlRegisterType(); + qmlRegisterType(uri, 2, 0, "VisualItemModel"); +#endif #if QT_CONFIG(qml_list_model) qmlRegisterType(uri, 2, 0, "ListElement"); qmlRegisterCustomType(uri, 2, 0, "ListModel", new QQmlListModelParser); #endif - qmlRegisterType(uri, 2, 0, "Package"); #if QT_CONFIG(qml_delegate_model) qmlRegisterType(uri, 2, 0, "VisualDataModel"); qmlRegisterType(uri, 2, 0, "VisualDataGroup"); + qmlRegisterType(uri, 2, 0, "Package"); #endif - qmlRegisterType(uri, 2, 0, "VisualItemModel"); } #endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -97,15 +108,17 @@ void QQmlModelsModule::defineModule() #if QT_CONFIG(qml_delegate_model) qmlRegisterType(uri, 2, 1, "DelegateModel"); qmlRegisterType(uri, 2, 1, "DelegateModelGroup"); + qmlRegisterType(uri, 2, 14, "Package"); #endif +#if QT_CONFIG(qml_object_model) qmlRegisterType(uri, 2, 1, "ObjectModel"); qmlRegisterType(uri, 2, 3, "ObjectModel"); - - qmlRegisterType(uri, 2, 2, "ItemSelectionModel"); - - qmlRegisterType(uri, 2, 14, "Package"); qmlRegisterType(uri, 2, 14, "Instantiator"); qmlRegisterType(); +#endif +#if QT_CONFIG(itemmodel) + qmlRegisterType(uri, 2, 2, "ItemSelectionModel"); +#endif } void QQmlModelsModule::defineLabsModule() @@ -117,8 +130,10 @@ void QQmlModelsModule::defineLabsModule() qmlRegisterType(uri, 1, 0, "DelegateChooser"); qmlRegisterType(uri, 1, 0, "DelegateChoice"); #endif +#if QT_CONFIG(qml_table_model) qmlRegisterType(uri, 1, 0, "TableModel"); qmlRegisterType(uri, 1, 0, "TableModelColumn"); +#endif } QT_END_NAMESPACE diff --git a/src/qmlmodels/qqmlobjectmodel_p.h b/src/qmlmodels/qqmlobjectmodel_p.h index 99bfd86269..78a5615ae2 100644 --- a/src/qmlmodels/qqmlobjectmodel_p.h +++ b/src/qmlmodels/qqmlobjectmodel_p.h @@ -56,6 +56,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_object_model); + QT_BEGIN_NAMESPACE class QObject; diff --git a/src/qmlmodels/qqmltableinstancemodel_p.h b/src/qmlmodels/qqmltableinstancemodel_p.h index 20331df5cc..ce5a37bc98 100644 --- a/src/qmlmodels/qqmltableinstancemodel_p.h +++ b/src/qmlmodels/qqmltableinstancemodel_p.h @@ -54,6 +54,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_table_model); + QT_BEGIN_NAMESPACE class QQmlTableInstanceModel; diff --git a/src/qmlmodels/qqmltablemodel_p.h b/src/qmlmodels/qqmltablemodel_p.h index 114b162e5c..b3c0cc2848 100644 --- a/src/qmlmodels/qqmltablemodel_p.h +++ b/src/qmlmodels/qqmltablemodel_p.h @@ -59,6 +59,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_table_model); + QT_BEGIN_NAMESPACE class Q_QMLMODELS_PRIVATE_EXPORT QQmlTableModel : public QAbstractTableModel, public QQmlParserStatus diff --git a/src/qmlmodels/qqmltablemodelcolumn_p.h b/src/qmlmodels/qqmltablemodelcolumn_p.h index d125f8bb16..0b6478ce38 100644 --- a/src/qmlmodels/qqmltablemodelcolumn_p.h +++ b/src/qmlmodels/qqmltablemodelcolumn_p.h @@ -56,6 +56,8 @@ #include #include +QT_REQUIRE_CONFIG(qml_table_model); + QT_BEGIN_NAMESPACE class Q_QMLMODELS_PRIVATE_EXPORT QQmlTableModelColumn : public QObject diff --git a/src/qmlmodels/qquickpackage_p.h b/src/qmlmodels/qquickpackage_p.h index 122c7fcb30..97f7818fee 100644 --- a/src/qmlmodels/qquickpackage_p.h +++ b/src/qmlmodels/qquickpackage_p.h @@ -52,6 +52,9 @@ // #include +#include + +QT_REQUIRE_CONFIG(qml_delegate_model); QT_BEGIN_NAMESPACE -- cgit v1.2.3 From fd6321c03e2d63997078bfa41332dbddefbb86b0 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 5 Apr 2019 09:59:10 +0200 Subject: Remove last traces of QV8Engine Change-Id: I59f738402d51e39188bbbca2ef1fbc8a61612372 Reviewed-by: Simon Hausmann --- src/qmlmodels/qqmladaptormodel.cpp | 2 +- src/qmlmodels/qqmldelegatemodel.cpp | 2 +- src/qmlmodels/qqmllistmodelworkeragent_p.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp index f991ae0a69..0bc67e1aad 100644 --- a/src/qmlmodels/qqmladaptormodel.cpp +++ b/src/qmlmodels/qqmladaptormodel.cpp @@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE -class QQmlAdaptorModelEngineData : public QV8Engine::Deletable +class QQmlAdaptorModelEngineData : public QV4::ExecutionEngine::Deletable { public: QQmlAdaptorModelEngineData(QV4::ExecutionEngine *v4); diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index 742c164508..2216e5fb50 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -123,7 +123,7 @@ DEFINE_OBJECT_VTABLE(QV4::DelegateModelGroupFunction); -class QQmlDelegateModelEngineData : public QV8Engine::Deletable +class QQmlDelegateModelEngineData : public QV4::ExecutionEngine::Deletable { public: QQmlDelegateModelEngineData(QV4::ExecutionEngine *v4); diff --git a/src/qmlmodels/qqmllistmodelworkeragent_p.h b/src/qmlmodels/qqmllistmodelworkeragent_p.h index f79c0c557a..1ef27cea3f 100644 --- a/src/qmlmodels/qqmllistmodelworkeragent_p.h +++ b/src/qmlmodels/qqmllistmodelworkeragent_p.h @@ -57,7 +57,7 @@ #include #include -#include +#include QT_REQUIRE_CONFIG(qml_list_model); -- cgit v1.2.3 From 7f7d87c68da4cb29b2b2b9c324c6863228da0c26 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 7 May 2019 12:47:33 +0200 Subject: Split CompiledData::CompilationUnit in two We need a CompilationUnit that only holds the data needed for compilation and another one that is executable by the runtime. Change-Id: I704d859ba028576a18460f5e3a59f210f64535d3 Reviewed-by: Simon Hausmann --- src/qmlmodels/qqmllistmodel.cpp | 18 ++++++++++-------- src/qmlmodels/qqmllistmodel_p.h | 10 +++++----- 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp index 5b5bcd8464..d1219d958a 100644 --- a/src/qmlmodels/qqmllistmodel.cpp +++ b/src/qmlmodels/qqmllistmodel.cpp @@ -314,7 +314,7 @@ QString StringOrTranslation::toString(const QQmlListModel *owner) const } if (!owner) return QString(); - return d.asT2()->valueAsString(owner->m_compilationUnit.data()); + return owner->m_compilationUnit->bindingValueAsString(d.asT2()); } QString StringOrTranslation::asString() const @@ -2676,7 +2676,7 @@ void QQmlListModel::sync() qmlWarning(this) << "List sync() can only be called from a WorkerScript"; } -bool QQmlListModelParser::verifyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding) +bool QQmlListModelParser::verifyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding) { if (binding->type >= QV4::CompiledData::Binding::Type_Object) { const quint32 targetObjectIndex = binding->value.objectIndex; @@ -2707,7 +2707,7 @@ bool QQmlListModelParser::verifyProperty(const QQmlRefPointertype == QV4::CompiledData::Binding::Type_Script) { - QString scriptStr = binding->valueAsScriptString(compilationUnit.data()); + QString scriptStr = compilationUnit->bindingValueAsScriptString(binding); if (!binding->isFunctionExpression() && !definesEmptyList(scriptStr)) { QByteArray script = scriptStr.toUtf8(); bool ok; @@ -2722,7 +2722,9 @@ bool QQmlListModelParser::verifyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex) +bool QQmlListModelParser::applyProperty( + const QQmlRefPointer &compilationUnit, + const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex) { const QString elementName = compilationUnit->stringAt(binding->propertyNameIndex); @@ -2759,7 +2761,7 @@ bool QQmlListModelParser::applyProperty(const QQmlRefPointerisTranslationBinding()) { value = QVariant::fromValue(binding); } else if (binding->evaluatesToString()) { - value = binding->valueAsString(compilationUnit.data()); + value = compilationUnit->bindingValueAsString(binding); } else if (binding->type == QV4::CompiledData::Binding::Type_Number) { value = binding->valueAsNumber(compilationUnit->constants); } else if (binding->type == QV4::CompiledData::Binding::Type_Boolean) { @@ -2767,7 +2769,7 @@ bool QQmlListModelParser::applyProperty(const QQmlRefPointertype == QV4::CompiledData::Binding::Type_Null) { value = QVariant::fromValue(nullptr); } else if (binding->type == QV4::CompiledData::Binding::Type_Script) { - QString scriptStr = binding->valueAsScriptString(compilationUnit.data()); + QString scriptStr = compilationUnit->bindingValueAsScriptString(binding); if (definesEmptyList(scriptStr)) { const ListLayout::Role &role = model->getOrCreateListRole(elementName); ListModel *emptyModel = new ListModel(role.subLayout, nullptr); @@ -2802,7 +2804,7 @@ bool QQmlListModelParser::applyProperty(const QQmlRefPointer &compilationUnit, const QList &bindings) +void QQmlListModelParser::verifyBindings(const QQmlRefPointer &compilationUnit, const QList &bindings) { listElementTypeName = QString(); // unknown @@ -2817,7 +2819,7 @@ void QQmlListModelParser::verifyBindings(const QQmlRefPointer &compilationUnit, const QList &bindings) +void QQmlListModelParser::applyBindings(QObject *obj, const QQmlRefPointer &compilationUnit, const QList &bindings) { QQmlListModel *rv = static_cast(obj); diff --git a/src/qmlmodels/qqmllistmodel_p.h b/src/qmlmodels/qqmllistmodel_p.h index 4aabd790a5..10d67c1c6f 100644 --- a/src/qmlmodels/qqmllistmodel_p.h +++ b/src/qmlmodels/qqmllistmodel_p.h @@ -137,7 +137,7 @@ private: mutable QQmlListModelWorkerAgent *m_agent; mutable QV4::ExecutionEngine *m_engine; - QQmlRefPointer m_compilationUnit; + QQmlRefPointer m_compilationUnit; bool m_mainThread; bool m_primary; @@ -188,13 +188,13 @@ public: QQmlListModelParser() : QQmlCustomParser(QQmlCustomParser::AcceptsSignalHandlers) {} - void verifyBindings(const QQmlRefPointer &compilationUnit, const QList &bindings) override; - void applyBindings(QObject *obj, const QQmlRefPointer &compilationUnit, const QList &bindings) override; + void verifyBindings(const QQmlRefPointer &compilationUnit, const QList &bindings) override; + void applyBindings(QObject *obj, const QQmlRefPointer &compilationUnit, const QList &bindings) override; private: - bool verifyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding); + bool verifyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding); // returns true if a role was set - bool applyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex); + bool applyProperty(const QQmlRefPointer &compilationUnit, const QV4::CompiledData::Binding *binding, ListModel *model, int outterElementIndex); static bool definesEmptyList(const QString &); -- cgit v1.2.3 From 540134d66dd0a235ace91ddc28940d2d88c24ac3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 10 May 2019 15:48:50 +0200 Subject: Move valueAsNumber into ExecutableCompilationUnit This reduces our dependence on QV4::Value in the devtools. Change-Id: I4b3f937bc08c16f7e2543fdc5cc34c0cfb121f8f Reviewed-by: Simon Hausmann --- src/qmlmodels/qqmllistmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qmlmodels') diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp index d1219d958a..c1684d955c 100644 --- a/src/qmlmodels/qqmllistmodel.cpp +++ b/src/qmlmodels/qqmllistmodel.cpp @@ -2763,7 +2763,7 @@ bool QQmlListModelParser::applyProperty( } else if (binding->evaluatesToString()) { value = compilationUnit->bindingValueAsString(binding); } else if (binding->type == QV4::CompiledData::Binding::Type_Number) { - value = binding->valueAsNumber(compilationUnit->constants); + value = compilationUnit->bindingValueAsNumber(binding); } else if (binding->type == QV4::CompiledData::Binding::Type_Boolean) { value = binding->valueAsBoolean(); } else if (binding->type == QV4::CompiledData::Binding::Type_Null) { -- cgit v1.2.3