aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlmodels
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2020-01-14 01:01:06 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-01-14 11:24:11 +0100
commit8a22c92b55b5d015e372fe5be0633c3935af4218 (patch)
tree02ad52cf1e7c3ed35b10156dd250d3cc7f6b7068 /src/qmlmodels
parent3ca659657ccaf0d850e661c9312e0f98e153c9ff (diff)
parent3dc5b937c4e9acf83ee54e870390c22f341c29c8 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/imports/folderlistmodel/plugin.cpp src/imports/layouts/plugin.cpp src/imports/localstorage/plugin.cpp src/imports/models/plugin.cpp src/imports/particles/plugin.cpp src/imports/qtqml/plugin.cpp src/imports/qtquick2/plugin.cpp src/imports/shapes/plugin.cpp src/imports/statemachine/plugin.cpp src/imports/testlib/main.cpp src/imports/wavefrontmesh/plugin.cpp src/imports/window/plugin.cpp src/imports/workerscript/plugin.cpp src/qml/jsruntime/qv4sequenceobject.cpp src/qml/qml/qqmlengine.cpp src/qmlmodels/qqmlmodelsmodule.cpp src/qmlmodels/qqmlmodelsmodule_p.h src/qmlworkerscript/qqmlworkerscriptmodule.cpp src/qmlworkerscript/qqmlworkerscriptmodule_p.h src/quick/items/qquickitemsmodule.cpp Change-Id: I5f1fbc3d00e8f583d2c89afc5389de84d68633a7
Diffstat (limited to 'src/qmlmodels')
-rw-r--r--src/qmlmodels/qmlmodels.pro9
-rw-r--r--src/qmlmodels/qqmladaptormodel.cpp76
-rw-r--r--src/qmlmodels/qqmlmodelsmodule.cpp82
-rw-r--r--src/qmlmodels/qqmlmodelsmodule_p.h7
4 files changed, 51 insertions, 123 deletions
diff --git a/src/qmlmodels/qmlmodels.pro b/src/qmlmodels/qmlmodels.pro
index 78bf579903..8e9ca43434 100644
--- a/src/qmlmodels/qmlmodels.pro
+++ b/src/qmlmodels/qmlmodels.pro
@@ -12,8 +12,7 @@ HEADERS += \
$$PWD/qtqmlmodelsglobal.h
SOURCES += \
- $$PWD/qqmlchangeset.cpp \
- $$PWD/qqmlmodelsmodule.cpp
+ $$PWD/qqmlchangeset.cpp
qtConfig(qml-object-model) {
SOURCES += \
@@ -64,4 +63,10 @@ qtConfig(qml-delegate-model) {
$$PWD/qquickpackage_p.h
}
+QMLTYPES_FILENAME = plugins.qmltypes
+QMLTYPES_INSTALL_DIR = $$[QT_INSTALL_QML]/QtQml/Models.2
+QML_IMPORT_NAME = QtQml.Models
+IMPORT_VERSION = 2.$$QT_MINOR_VERSION
+CONFIG += qmltypes install_qmltypes install_metatypes
+
load(qt_module)
diff --git a/src/qmlmodels/qqmladaptormodel.cpp b/src/qmlmodels/qqmladaptormodel.cpp
index 012540244f..cf0d8fbb2f 100644
--- a/src/qmlmodels/qqmladaptormodel.cpp
+++ b/src/qmlmodels/qqmladaptormodel.cpp
@@ -199,12 +199,11 @@ public:
RETURN_RESULT(scope.engine->throwTypeError(QStringLiteral("Not a valid DelegateModel object")));
const QQmlAdaptorModel *const model = static_cast<QQmlDMCachedModelData *>(o->d()->item)->type->model;
- if (o->d()->item->index >= 0 && *model) {
- const QAbstractItemModel * const aim = model->aim();
- RETURN_RESULT(QV4::Encode(aim->hasChildren(aim->index(o->d()->item->index, 0, model->rootIndex))));
- } else {
- RETURN_RESULT(QV4::Encode(false));
+ if (o->d()->item->index >= 0) {
+ if (const QAbstractItemModel *const aim = model->aim())
+ RETURN_RESULT(QV4::Encode(aim->hasChildren(aim->index(o->d()->item->index, 0, model->rootIndex))));
}
+ RETURN_RESULT(QV4::Encode(false));
}
@@ -400,23 +399,24 @@ public:
bool hasModelChildren() const
{
- if (index >= 0 && *type->model) {
- const QAbstractItemModel * const model = type->model->aim();
- return model->hasChildren(model->index(row, column, type->model->rootIndex));
- } else {
- return false;
+ if (index >= 0) {
+ if (const QAbstractItemModel *const model = type->model->aim())
+ return model->hasChildren(model->index(row, column, type->model->rootIndex));
}
+ return false;
}
QVariant value(int role) const override
{
- return type->model->aim()->index(row, column, type->model->rootIndex).data(role);
+ if (const QAbstractItemModel *aim = type->model->aim())
+ return aim->index(row, column, type->model->rootIndex).data(role);
+ return QVariant();
}
void setValue(int role, const QVariant &value) override
{
- type->model->aim()->setData(
- type->model->aim()->index(row, column, type->model->rootIndex), value, role);
+ if (QAbstractItemModel *aim = type->model->aim())
+ aim->setData(aim->index(row, column, type->model->rootIndex), value, role);
}
QV4::ReturnedValue get() override
@@ -444,12 +444,16 @@ public:
int rowCount(const QQmlAdaptorModel &model) const override
{
- return model.aim()->rowCount(model.rootIndex);
+ if (const QAbstractItemModel *aim = model.aim())
+ return aim->rowCount(model.rootIndex);
+ return 0;
}
int columnCount(const QQmlAdaptorModel &model) const override
{
- return model.aim()->columnCount(model.rootIndex);
+ if (const QAbstractItemModel *aim = model.aim())
+ return aim->columnCount(model.rootIndex);
+ return 0;
}
void cleanup(QQmlAdaptorModel &) const override
@@ -464,39 +468,46 @@ public:
dataType->initializeMetaType(model);
}
- QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
- if (it != roleNames.end()) {
- return model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex).data(*it);
- } else if (role == QLatin1String("hasModelChildren")) {
- return QVariant(model.aim()->hasChildren(model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex)));
- } else {
- return QVariant();
+ if (const QAbstractItemModel *aim = model.aim()) {
+ QHash<QByteArray, int>::const_iterator it = roleNames.find(role.toUtf8());
+ if (it != roleNames.end()) {
+ return aim->index(model.rowAt(index), model.columnAt(index),
+ model.rootIndex).data(*it);
+ } else if (role == QLatin1String("hasModelChildren")) {
+ return QVariant(aim->hasChildren(aim->index(model.rowAt(index),
+ model.columnAt(index),
+ model.rootIndex)));
+ }
}
+ return QVariant();
}
QVariant parentModelIndex(const QQmlAdaptorModel &model) const override
{
- return model
- ? QVariant::fromValue(model.aim()->parent(model.rootIndex))
- : QVariant();
+ if (const QAbstractItemModel *aim = model.aim())
+ return QVariant::fromValue(aim->parent(model.rootIndex));
+ return QVariant();
}
QVariant modelIndex(const QQmlAdaptorModel &model, int index) const override
{
- return model
- ? QVariant::fromValue(model.aim()->index(model.rowAt(index), model.columnAt(index), model.rootIndex))
- : QVariant();
+ if (const QAbstractItemModel *aim = model.aim())
+ return QVariant::fromValue(aim->index(model.rowAt(index), model.columnAt(index),
+ model.rootIndex));
+ return QVariant();
}
bool canFetchMore(const QQmlAdaptorModel &model) const override
{
- return model && model.aim()->canFetchMore(model.rootIndex);
+ if (const QAbstractItemModel *aim = model.aim())
+ return aim->canFetchMore(model.rootIndex);
+ return false;
}
void fetchMore(QQmlAdaptorModel &model) const override
{
- if (model)
- model.aim()->fetchMore(model.rootIndex);
+ if (QAbstractItemModel *aim = model.aim())
+ aim->fetchMore(model.rootIndex);
}
QQmlDelegateModelItem *createItem(
@@ -516,7 +527,8 @@ public:
setModelDataType<QQmlDMAbstractItemModelData>(&builder, this);
const QByteArray propertyType = QByteArrayLiteral("QVariant");
- const QHash<int, QByteArray> names = model.aim()->roleNames();
+ const QAbstractItemModel *aim = model.aim();
+ const QHash<int, QByteArray> names = aim ? aim->roleNames() : QHash<int, QByteArray>();
for (QHash<int, QByteArray>::const_iterator it = names.begin(), cend = names.end(); it != cend; ++it) {
const int propertyId = propertyRoles.count();
propertyRoles.append(it.key());
diff --git a/src/qmlmodels/qqmlmodelsmodule.cpp b/src/qmlmodels/qqmlmodelsmodule.cpp
deleted file mode 100644
index 8bd9b179b3..0000000000
--- a/src/qmlmodels/qqmlmodelsmodule.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Research In Motion.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qqmlmodelsmodule_p.h"
-#include <private/qtqmlmodelsglobal_p.h>
-
-#if QT_CONFIG(qml_list_model)
-#include <private/qqmllistmodel_p.h>
-#include <private/qqmllistmodelworkeragent_p.h>
-#endif
-#if QT_CONFIG(qml_delegate_model)
-#include <private/qqmlabstractdelegatecomponent_p.h>
-#include <private/qqmldelegatemodel_p.h>
-#include <private/qquickpackage_p.h>
-#include <private/qqmlcomponentattached_p.h>
-#endif
-#if QT_CONFIG(qml_object_model)
-#include <private/qqmlobjectmodel_p.h>
-#include <private/qqmlinstantiator_p.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-void QQmlModelsModule::defineModule()
-{
- const char uri[] = "QtQml.Models";
-
-#if QT_CONFIG(qml_list_model)
- qmlRegisterTypesAndRevisions<QQmlListElement, QQmlListModel, QQmlListModelWorkerAgent>(uri, 2);
-#endif
-#if QT_CONFIG(qml_delegate_model)
- // TODO: Get rid of these. It's called DelegateModel and DelegateModelGroup these days.
- qmlRegisterType<QQmlDelegateModel>(uri, 2, 0, "VisualDataModel");
- qmlRegisterType<QQmlDelegateModelGroup>(uri, 2, 0, "VisualDataGroup");
-
- qmlRegisterTypesAndRevisions<QQmlDelegateModel, QQmlDelegateModelGroup, QQuickPackage, QQmlAbstractDelegateComponent>(uri, 2);
-#endif
-#if QT_CONFIG(qml_object_model)
- qmlRegisterTypesAndRevisions<QQmlObjectModel, QQmlInstantiator, QQmlInstanceModel>(uri, 2);
-#endif
-#if QT_CONFIG(itemmodel)
- qmlRegisterTypesAndRevisions<QItemSelectionModelForeign>(uri, 2);
-#endif
-}
-
-QT_END_NAMESPACE
diff --git a/src/qmlmodels/qqmlmodelsmodule_p.h b/src/qmlmodels/qqmlmodelsmodule_p.h
index c697b08bf7..e3e43f3922 100644
--- a/src/qmlmodels/qqmlmodelsmodule_p.h
+++ b/src/qmlmodels/qqmlmodelsmodule_p.h
@@ -61,13 +61,6 @@
QT_BEGIN_NAMESPACE
-class Q_QMLMODELS_PRIVATE_EXPORT QQmlModelsModule
-{
-public:
- static void defineModule();
- static void defineLabsModule();
-};
-
#if QT_CONFIG(itemmodel)
struct QItemSelectionModelForeign
{