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 ReleaseFlags release(QObject *object, ReusableFlag reusable = NotReusable) override;
90 void dispose(QObject *object);
91 void cancel(int) override;
92
93 void drainReusableItemsPool(int maxPoolTime) override;
94 int poolSize() override { return m_reusableItemsPool.size(); }
95 void reuseItem(QQmlDelegateModelItem *item, int newModelIndex);
96
97 QQmlIncubator::Status incubationStatus(int index) override;
98
99 bool setRequiredProperty(int index, const QString &name, const QVariant &value) final;
100
101 QVariant variantValue(int, const QString &) override { Q_UNREACHABLE_RETURN(QVariant()); }
102 void setWatchedRoles(const QList<QByteArray> &) override { Q_UNREACHABLE(); }
103 int indexOf(QObject *, QObject *) const override { Q_UNREACHABLE_RETURN(0); }
104
105 QQmlDelegateModelItem *getModelItem(int index);
106
107signals:
108 void modelChanged();
109
110private:
111 enum DestructionMode {
112 Deferred,
113 Immediate
114 };
115
116 QQmlComponent *resolveDelegate(int index);
117
118 QQmlAdaptorModel m_adaptorModel;
119 QQmlAbstractDelegateComponent *m_delegateChooser = nullptr;
120 QQmlComponent *m_delegate = nullptr;
121 QPointer<QQmlContext> m_qmlContext;
122 QQmlRefPointer<QQmlDelegateModelItemMetaType> m_metaType;
123
124 QHash<int, QQmlDelegateModelItem *> m_modelItems;
125 QQmlReusableDelegateModelItemsPool m_reusableItemsPool;
126 QList<QQmlIncubator *> m_finishedIncubationTasks;
127
128 void incubateModelItem(QQmlDelegateModelItem *modelItem, QQmlIncubator::IncubationMode incubationMode);
129 void incubatorStatusChanged(QQmlTableInstanceModelIncubationTask *dmIncubationTask, QQmlIncubator::Status status);
130 void deleteIncubationTaskLater(QQmlIncubator *incubationTask);
131 void deleteAllFinishedIncubationTasks();
132 QQmlDelegateModelItem *resolveModelItem(int index);
133 void destroyModelItem(QQmlDelegateModelItem *modelItem, DestructionMode mode);
134
135 void dataChangedCallback(const QModelIndex &begin, const QModelIndex &end, const QList<int> &roles);
136 void modelAboutToBeResetCallback();
137 void forceSetModel(const QVariant &model);
138
139 static bool isDoneIncubating(QQmlDelegateModelItem *modelItem);
140 static void deleteModelItemLater(QQmlDelegateModelItem *modelItem);
141
142 friend class QQmlTableInstanceModelIncubationTask;
143};
144
145QT_END_NAMESPACE
146
147#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)