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;
30class QTypeRevision;
31
33{
34public:
36 QQmlTableInstanceModel *tableInstanceModel
37 , QQmlDelegateModelItem* modelItemToIncubate
38 , IncubationMode mode)
39 : QQDMIncubationTask(nullptr, mode)
41 , tableInstanceModel(tableInstanceModel) {
42 clear();
43 }
44
45 void statusChanged(Status status) override;
46 void setInitialState(QObject *object) override;
47
49 QQmlTableInstanceModel *tableInstanceModel = nullptr;
50};
51
52class Q_QMLMODELS_EXPORT QQmlTableInstanceModel : public QQmlInstanceModel
53{
54 Q_OBJECT
55
56public:
57 QQmlTableInstanceModel(QQmlContext *qmlContext, QObject *parent = nullptr);
58 ~QQmlTableInstanceModel() override;
59
60 void useImportVersion(QTypeRevision version);
61
62 int count() const override { return m_adaptorModel.count(); }
63 int rows() const { return m_adaptorModel.rowCount(); }
64 int columns() const { return m_adaptorModel.columnCount(); }
65
66 bool isValid() const override { return true; }
67
68 bool canFetchMore() const { return m_adaptorModel.canFetchMore(); }
69 void fetchMore() { m_adaptorModel.fetchMore(); }
70
71 QVariant model() const;
72 void setModel(const QVariant &model);
73
74 QQmlComponent *delegate() const;
75 void setDelegate(QQmlComponent *);
76
77 QQmlDelegateModel::DelegateModelAccess delegateModelAccess() const
78 {
79 return m_adaptorModel.delegateModelAccess;
80 }
81 void setDelegateModelAccess(QQmlDelegateModel::DelegateModelAccess delegateModelAccess)
82 {
83 m_adaptorModel.delegateModelAccess = delegateModelAccess;
84 }
85
86 const QAbstractItemModel *abstractItemModel() const override;
87
88 QObject *object(int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) override;
89 QObject *incubateModelItemIfNeeded(QQmlDelegateModelItem *modelItem, QQmlIncubator::IncubationMode incubationMode);
90 void restoreFromReleasedItemsCache(QQmlDelegateModelItem *item, int newFlatIndex);
91 void commitReleasedItems();
92 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
93 void dispose(QObject *object);
94 void cancel(int) override;
95
96 void drainReusableItemsPool(int maxPoolTime) override;
97 int poolSize() override { return m_reusableItemsPool.size(); }
98 void reuseItem(QQmlDelegateModelItem *item, int newModelIndex);
99
100 QQmlIncubator::Status incubationStatus(int index) override;
101
102 bool setRequiredProperty(int index, const QString &name, const QVariant &value) final;
103
104 QVariant variantValue(int, const QString &) override { Q_UNREACHABLE_RETURN(QVariant()); }
105 void setWatchedRoles(const QList<QByteArray> &) override { Q_UNREACHABLE(); }
106 int indexOf(QObject *, QObject *) const override { Q_UNREACHABLE_RETURN(0); }
107
108 QQmlDelegateModelItem *getModelItem(int index);
109
110signals:
111 void modelChanged();
112
113private:
114 enum DestructionMode {
115 Deferred,
116 Immediate
117 };
118
119 QQmlComponent *resolveDelegate(int index);
120
121 QQmlAdaptorModel m_adaptorModel;
122 QQmlAbstractDelegateComponent *m_delegateChooser = nullptr;
123 QQmlComponent *m_delegate = nullptr;
124 QPointer<QQmlContext> m_qmlContext;
125 QQmlRefPointer<QQmlDelegateModelItemMetaType> m_metaType;
126
127 QHash<int, QQmlDelegateModelItem *> m_modelItems;
128 QQmlReusableDelegateModelItemsPool m_reusableItemsPool;
129 QList<QQmlDelegateModelItem *> m_releasedItems;
130 QList<QQmlIncubator *> m_finishedIncubationTasks;
131
132 void incubateModelItem(QQmlDelegateModelItem *modelItem, QQmlIncubator::IncubationMode incubationMode);
133 void incubatorStatusChanged(QQmlTableInstanceModelIncubationTask *dmIncubationTask, QQmlIncubator::Status status);
134 void deleteIncubationTaskLater(QQmlIncubator *incubationTask);
135 void deleteAllFinishedIncubationTasks();
136 QQmlDelegateModelItem *resolveModelItem(int flatIndex, const QModelIndex &modelIndex);
137 void destroyModelItem(QQmlDelegateModelItem *modelItem, DestructionMode mode);
138
139 void dataChangedCallback(const QModelIndex &begin, const QModelIndex &end, const QList<int> &roles);
140 void modelAboutToBeResetCallback();
141 void forceSetModel(const QVariant &model);
142
143 static bool isDoneIncubating(QQmlDelegateModelItem *modelItem);
144 static void deleteModelItemLater(QQmlDelegateModelItem *modelItem);
145
146 friend class QQmlTableInstanceModelIncubationTask;
147};
148
149QT_END_NAMESPACE
150
151#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,...
\inmodule QtCore
Combined button and popup list for selecting options.
QT_BEGIN_NAMESPACE const char * kModelItemTag
QT_REQUIRE_CONFIG(qml_table_model)