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
qqmladaptormodel_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QQMLADAPTORMODEL_P_H
6#define QQMLADAPTORMODEL_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 <QtCore/qabstractitemmodel.h>
20
21#include <private/qqmldelegatemodel_p.h>
22#include <private/qqmlguard_p.h>
23#include <private/qqmllistaccessor_p.h>
24#include <private/qqmlnullablevalue_p.h>
25#include <private/qqmlpropertycache_p.h>
26#include <private/qtqmlglobal_p.h>
27#include <private/qtqmlmodelsglobal_p.h>
28
29#include <QtCore/qtyperevision.h>
30
32
33QT_BEGIN_NAMESPACE
34
35class QQmlEngine;
36
37class QQmlDelegateModelItem;
38class QQmlDelegateModelItemMetaType;
39
40class Q_QMLMODELS_EXPORT QQmlAdaptorModel : public QQmlGuard<QObject>
41{
42public:
43 class Accessors
44 {
45 public:
46 inline Accessors() {}
47 virtual ~Accessors();
48 virtual int rowCount(const QQmlAdaptorModel &) const { return 0; }
49 virtual int columnCount(const QQmlAdaptorModel &) const { return 0; }
50 virtual void cleanup(QQmlAdaptorModel &) const {}
51
52 virtual QVariant value(const QQmlAdaptorModel &, int, const QString &) const {
53 return QVariant(); }
54
55 virtual QQmlDelegateModelItem *createItem(
56 QQmlAdaptorModel &,
57 const QQmlRefPointer<QQmlDelegateModelItemMetaType> &,
58 int, int, int) { return nullptr; }
59
60 virtual bool notify(
61 const QQmlAdaptorModel &,
62 const QList<QQmlDelegateModelItem *> &,
63 int,
64 int,
65 const QList<int> &) const { return false; }
66 virtual void replaceWatchedRoles(
67 QQmlAdaptorModel &,
68 const QList<QByteArray> &,
69 const QList<QByteArray> &) const {}
70 virtual QVariant parentModelIndex(const QQmlAdaptorModel &) const {
71 return QVariant(); }
72 virtual QVariant modelIndex(const QQmlAdaptorModel &, int) const {
73 return QVariant(); }
74 virtual bool canFetchMore(const QQmlAdaptorModel &) const { return false; }
75 virtual void fetchMore(QQmlAdaptorModel &) const {}
76
77 QScopedPointer<QMetaObject, QScopedPointerPodDeleter> metaObject;
78 QQmlPropertyCache::ConstPtr propertyCache;
79 };
80
81 Accessors *accessors;
82 QPersistentModelIndex rootIndex;
83 QQmlListAccessor list;
84 // we need to ensure that a JS created model does not get gced, but cannot
85 // arbitrarily set the parent (using QQmlStrongJSQObjectReference) of QObject based models,
86 // as that causes issues with singletons
87 QV4::PersistentValue modelStrongReference;
88
89 QTypeRevision modelItemRevision = QTypeRevision::zero();
90 QQmlDelegateModel::DelegateModelAccess delegateModelAccess = QQmlDelegateModel::Qt5ReadWrite;
91
92 QQmlAdaptorModel();
93 ~QQmlAdaptorModel();
94
95 inline QVariant model() const { return list.list(); }
96 void setModel(const QVariant &variant);
97 void invalidateModel();
98
99 bool isValid() const;
100 int count() const;
101 int rowCount() const;
102 int columnCount() const;
103 int rowAt(int index) const;
104 int columnAt(int index) const;
105 int indexAt(int row, int column) const;
106
107 void useImportVersion(QTypeRevision revision);
108
109 inline bool adaptsAim() const { return qobject_cast<QAbstractItemModel *>(object()); }
110 inline QAbstractItemModel *aim() { return static_cast<QAbstractItemModel *>(object()); }
111 inline const QAbstractItemModel *aim() const { return static_cast<const QAbstractItemModel *>(object()); }
112
113 inline QVariant value(int index, const QString &role) const {
114 return accessors->value(*this, index, role); }
115 inline QQmlDelegateModelItem *createItem(
116 const QQmlRefPointer<QQmlDelegateModelItemMetaType> &metaType, int index)
117 {
118 return accessors->createItem(*this, metaType, index, rowAt(index), columnAt(index));
119 }
120 inline bool hasProxyObject() const {
121 switch (list.type()) {
122 case QQmlListAccessor::Instance:
123 case QQmlListAccessor::ListProperty:
124 case QQmlListAccessor::ObjectList:
125 case QQmlListAccessor::ObjectSequence:
126 return true;
127 default:
128 break;
129 }
130 return false;
131 }
132
133 inline bool notify(
134 const QList<QQmlDelegateModelItem *> &items,
135 int index,
136 int count,
137 const QList<int> &roles) const {
138 return accessors->notify(*this, items, index, count, roles); }
139 inline void replaceWatchedRoles(
140 const QList<QByteArray> &oldRoles, const QList<QByteArray> &newRoles) {
141 accessors->replaceWatchedRoles(*this, oldRoles, newRoles); }
142
143 inline QVariant modelIndex(int index) const { return accessors->modelIndex(*this, index); }
144 inline QVariant parentModelIndex() const { return accessors->parentModelIndex(*this); }
145 inline bool canFetchMore() const { return accessors->canFetchMore(*this); }
146 inline void fetchMore() { return accessors->fetchMore(*this); }
147
148private:
149 static void objectDestroyedImpl(QQmlGuardImpl *);
150
151 Accessors m_nullAccessors;
152};
153
154QT_END_NAMESPACE
155
156#endif
Combined button and popup list for selecting options.
QT_REQUIRE_CONFIG(qml_delegate_model)