Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmltableinstancemodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLTABLEINSTANCEMODEL_P_H
6#define QQMLTABLEINSTANCEMODEL_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQmlModels/private/qqmldelegatemodel_p.h>
20#include <QtQmlModels/private/qqmldelegatemodel_p_p.h>
21
22#include <QtCore/qpointer.h>
23
25
26QT_BEGIN_NAMESPACE
27
28class QQmlTableInstanceModel;
29class QQmlAbstractDelegateComponent;
30
32{
33public:
35 QQmlTableInstanceModel *tableInstanceModel
36 , QQmlDelegateModelItem* modelItemToIncubate
37 , IncubationMode mode)
38 : QQDMIncubationTask(nullptr, mode)
40 , tableInstanceModel(tableInstanceModel) {
41 clear();
42 }
43
44 void statusChanged(Status status) override;
45 void setInitialState(QObject *object) override;
46
48 QQmlTableInstanceModel *tableInstanceModel = nullptr;
49};
50
51class Q_QMLMODELS_EXPORT QQmlTableInstanceModel : public QQmlInstanceModel
52{
53 Q_OBJECT
54
55public:
56 QQmlTableInstanceModel(QQmlContext *qmlContext, QObject *parent = nullptr);
57 ~QQmlTableInstanceModel() override;
58
59 void useImportVersion(QTypeRevision version);
60
61 int count() const override { return m_adaptorModel.count(); }
62 int rows() const { return m_adaptorModel.rowCount(); }
63 int columns() const { return m_adaptorModel.columnCount(); }
64
65 bool isValid() const override { return true; }
66
67 bool canFetchMore() const { return m_adaptorModel.canFetchMore(); }
68 void fetchMore() { m_adaptorModel.fetchMore(); }
69
70 QVariant model() const;
71 void setModel(const QVariant &model);
72
73 QQmlComponent *delegate() const;
74 void setDelegate(QQmlComponent *);
75
76 QQmlDelegateModel::DelegateModelAccess delegateModelAccess() const
77 {
78 return m_adaptorModel.delegateModelAccess;
79 }
80 void setDelegateModelAccess(QQmlDelegateModel::DelegateModelAccess delegateModelAccess)
81 {
82 m_adaptorModel.delegateModelAccess = delegateModelAccess;
83 }
84
85 const QAbstractItemModel *abstractItemModel() const override;
86
87 QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) override;
88 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
89 void dispose(QObject *object);
90 void cancel(int) override;
91
92 void drainReusableItemsPool(int maxPoolTime) override;
93 int poolSize() override { return m_reusableItemsPool.size(); }
94 void reuseItem(QQmlDelegateModelItem *item, int newModelIndex);
95
96 QQmlIncubator::Status incubationStatus(int index) override;
97
98 bool setRequiredProperty(int index, const QString &name, const QVariant &value) final;
99
100 QVariant variantValue(int, const QString &) override { Q_UNREACHABLE_RETURN(QVariant()); }
101 void setWatchedRoles(const QList<QByteArray> &) override { Q_UNREACHABLE(); }
102 int indexOf(QObject *, QObject *) const override { Q_UNREACHABLE_RETURN(0); }
103
104 QQmlDelegateModelItem *getModelItem(int index);
105
106signals:
107 void modelChanged();
108
109private:
110 enum DestructionMode {
111 Deferred,
112 Immediate
113 };
114
115 QQmlComponent *resolveDelegate(int index);
116
117 QQmlAdaptorModel m_adaptorModel;
118 QQmlAbstractDelegateComponent *m_delegateChooser = nullptr;
119 QQmlComponent *m_delegate = nullptr;
120 QPointer<QQmlContext> m_qmlContext;
121 QQmlRefPointer<QQmlDelegateModelItemMetaType> m_metaType;
122
123 QHash<int, QQmlDelegateModelItem *> m_modelItems;
124 QQmlReusableDelegateModelItemsPool m_reusableItemsPool;
125 QList<QQmlIncubator *> m_finishedIncubationTasks;
126
127 void incubateModelItem(QQmlDelegateModelItem *modelItem, QQmlIncubator::IncubationMode incubationMode);
128 void incubatorStatusChanged(QQmlTableInstanceModelIncubationTask *dmIncubationTask, QQmlIncubator::Status status);
129 void deleteIncubationTaskLater(QQmlIncubator *incubationTask);
130 void deleteAllFinishedIncubationTasks();
131 QQmlDelegateModelItem *resolveModelItem(int index);
132 void destroyModelItem(QQmlDelegateModelItem *modelItem, DestructionMode mode);
133
134 void dataChangedCallback(const QModelIndex &begin, const QModelIndex &end, const QVector<int> &roles);
135 void modelAboutToBeResetCallback();
136 void forceSetModel(const QVariant &model);
137
138 static bool isDoneIncubating(QQmlDelegateModelItem *modelItem);
139 static void deleteModelItemLater(QQmlDelegateModelItem *modelItem);
140
141 friend class QQmlTableInstanceModelIncubationTask;
142};
143
144QT_END_NAMESPACE
145
146#endif // QQMLTABLEINSTANCEMODEL_P_H
void statusChanged(Status status) override
Called when the status of the incubator changes.
QQmlTableInstanceModelIncubationTask(QQmlTableInstanceModel *tableInstanceModel, QQmlDelegateModelItem *modelItemToIncubate, IncubationMode mode)
void setInitialState(QObject *object) override
Called after the object is first created, but before complex property bindings are evaluated and,...
QT_BEGIN_NAMESPACE const char * kModelItemTag
QT_REQUIRE_CONFIG(qml_table_model)