5#ifndef QQMLDATAMODEL_P_H
6#define QQMLDATAMODEL_P_H
19#include <private/qtqmlmodelsglobal_p.h>
20#include <private/qqmllistcompositor_p.h>
21#include <private/qqmlobjectmodel_p.h>
22#include <private/qqmlincubator_p.h>
24#include <QtCore/qabstractitemmodel.h>
25#include <QtCore/qstringlist.h>
33class QQmlDelegateModelGroup;
38class Q_QMLMODELS_EXPORT
QQmlDelegateModel :
public QQmlInstanceModel,
public QQmlParserStatus
41 Q_DECLARE_PRIVATE(QQmlDelegateModel)
43 Q_PROPERTY(QVariant model READ model WRITE setModel NOTIFY modelChanged)
44 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate NOTIFY delegateChanged)
45 Q_PROPERTY(QString filterOnGroup READ filterGroup WRITE setFilterGroup NOTIFY filterGroupChanged RESET resetFilterGroup)
46 Q_PROPERTY(QQmlDelegateModelGroup *items READ items CONSTANT)
47 Q_PROPERTY(QQmlDelegateModelGroup *persistedItems READ persistedItems CONSTANT)
48 Q_PROPERTY(QQmlListProperty<QQmlDelegateModelGroup> groups READ groups CONSTANT)
49 Q_PROPERTY(QObject *parts READ parts CONSTANT)
50 Q_PROPERTY(QVariant rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
51 Q_PROPERTY(DelegateModelAccess delegateModelAccess READ delegateModelAccess
52 WRITE setDelegateModelAccess NOTIFY delegateModelAccessChanged REVISION(6, 10) FINAL)
53 Q_CLASSINFO(
"DefaultProperty",
"delegate")
54 QML_NAMED_ELEMENT(DelegateModel)
55 QML_ADDED_IN_VERSION(2, 1)
56 QML_ATTACHED(QQmlDelegateModelAttached)
57 Q_INTERFACES(QQmlParserStatus)
60 enum DelegateModelAccess : quint8 {
65 Q_ENUM(DelegateModelAccess)
68 QQmlDelegateModel(QQmlContext *, QObject *parent=
nullptr);
71 void classBegin() override;
72 void componentComplete() override;
74 QVariant model()
const;
75 void setModel(
const QVariant &);
77 QQmlComponent *delegate()
const;
78 void setDelegate(QQmlComponent *);
80 QVariant rootIndex()
const;
81 void setRootIndex(
const QVariant &root);
83 DelegateModelAccess delegateModelAccess()
const;
84 void setDelegateModelAccess(DelegateModelAccess delegateModelAccess);
86 Q_INVOKABLE QVariant modelIndex(
int idx)
const;
87 Q_INVOKABLE QVariant parentModelIndex()
const;
89 int count()
const override;
90 bool isValid()
const override {
return delegate() !=
nullptr; }
91 QObject *object(
int index, QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::AsynchronousIfNested) override;
92 ReleaseFlags release(QObject *object, ReusableFlag reusableFlag = NotReusable) override;
93 void cancel(
int index) override;
94 QVariant variantValue(
int index,
const QString &role) override;
95 void setWatchedRoles(
const QList<QByteArray> &roles) override;
96 QQmlIncubator::Status incubationStatus(
int index) override;
98 void drainReusableItemsPool(
int maxPoolTime) override;
99 int poolSize() override;
101 int indexOf(QObject *object, QObject *objectContext)
const override;
103 QString filterGroup()
const;
104 void setFilterGroup(
const QString &group);
105 void resetFilterGroup();
107 QQmlDelegateModelGroup *items();
108 QQmlDelegateModelGroup *persistedItems();
109 QQmlListProperty<QQmlDelegateModelGroup> groups();
112 const QAbstractItemModel *abstractItemModel()
const override;
114 bool event(QEvent *) override;
116 static QQmlDelegateModelAttached *qmlAttachedProperties(QObject *obj);
118 template<
typename View,
typename ViewPrivate>
119 static QQmlDelegateModel *createForView(View *q, ViewPrivate *d)
121 Q_ASSERT(d->model.isNull());
122 QQmlDelegateModel *delegateModel =
new QQmlDelegateModel(qmlContext(q), q);
123 d->model = delegateModel;
125 if (d->componentComplete)
126 delegateModel->componentComplete();
127 return delegateModel;
130 template<
typename View,
typename ViewPrivate>
131 static void applyDelegateModelAccessChangeOnView(View *q, ViewPrivate *d)
133 if (d->explicitDelegateModelAccess) {
134 qmlWarning(q) <<
"Explicitly set delegateModelAccess is externally overridden";
135 d->explicitDelegateModelAccess =
false;
138 Q_EMIT q->delegateModelAccessChanged();
141 template<
typename View,
typename ViewPrivate>
142 static void applyDelegateChangeOnView(View *q, ViewPrivate *d)
144 if (d->explicitDelegate) {
145 qmlWarning(q) <<
"Explicitly set delegate is externally overridden";
146 d->explicitDelegate =
false;
149 Q_EMIT q->delegateChanged();
153 void filterGroupChanged();
154 void defaultGroupsChanged();
155 void rootIndexChanged();
156 void delegateChanged();
157 Q_REVISION(6, 10)
void delegateModelAccessChanged();
158 Q_REVISION(6, 10)
void modelChanged();
161 void _q_itemsChanged(
int index,
int count,
const QVector<
int> &roles);
162 void _q_itemsInserted(
int index,
int count);
163 void _q_itemsRemoved(
int index,
int count);
164 void _q_itemsMoved(
int from,
int to,
int count);
165 void _q_modelAboutToBeReset();
166 void _q_rowsInserted(
const QModelIndex &,
int,
int);
167 void _q_columnsInserted(
const QModelIndex &,
int,
int);
168 void _q_columnsRemoved(
const QModelIndex &,
int,
int);
169 void _q_columnsMoved(
const QModelIndex &,
int,
int,
const QModelIndex &,
int);
170 void _q_rowsAboutToBeRemoved(
const QModelIndex &parent,
int begin,
int end);
171 void _q_rowsRemoved(
const QModelIndex &,
int,
int);
172 void _q_rowsMoved(
const QModelIndex &,
int,
int,
const QModelIndex &,
int);
173 void _q_dataChanged(
const QModelIndex&,
const QModelIndex&,
const QVector<
int> &);
174 void _q_layoutChanged(
const QList<QPersistentModelIndex>&, QAbstractItemModel::LayoutChangeHint);
177 void handleModelReset();
178 bool isDescendantOf(
const QPersistentModelIndex &desc,
const QList<QPersistentModelIndex> &parents)
const;
180 Q_DISABLE_COPY(QQmlDelegateModel)
187 Q_PROPERTY(
int count READ count NOTIFY countChanged)
188 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
189 Q_PROPERTY(
bool includeByDefault READ defaultInclude WRITE setDefaultInclude NOTIFY defaultIncludeChanged)
190 QML_NAMED_ELEMENT(DelegateModelGroup)
191 QML_ADDED_IN_VERSION(2, 1)
193 QQmlDelegateModelGroup(QObject *parent =
nullptr);
194 QQmlDelegateModelGroup(
const QString &name, QQmlDelegateModel *model,
int compositorType, QObject *parent =
nullptr);
195 ~QQmlDelegateModelGroup();
197 QString name()
const;
198 void setName(
const QString &name);
202 bool defaultInclude()
const;
203 void setDefaultInclude(
bool include);
205 Q_INVOKABLE QJSValue get(
int index);
208 void insert(QQmlV4FunctionPtr);
209 void create(QQmlV4FunctionPtr);
210 void resolve(QQmlV4FunctionPtr);
211 void remove(QQmlV4FunctionPtr);
212 void addGroups(QQmlV4FunctionPtr);
213 void removeGroups(QQmlV4FunctionPtr);
214 void setGroups(QQmlV4FunctionPtr);
215 void move(QQmlV4FunctionPtr);
220 void defaultIncludeChanged();
221 void changed(
const QJSValue &removed,
const QJSValue &inserted);
223 Q_DECLARE_PRIVATE(QQmlDelegateModelGroup)
227class QQmlDelegateModelAttachedMetaObject;
231 Q_PROPERTY(QQmlDelegateModel *model READ model CONSTANT FINAL)
258 void setGroups(
const QStringList &groups);
271 void setInGroup(QQmlListCompositor::Group group,
bool inGroup);
279 friend class QQmlDelegateModelAttachedMetaObject;
292 , concrete(model ? Unknown : InstanceModel)
297 , concrete(DelegateModel)
302 model = instanceModel;
303 concrete = model ? Unknown : InstanceModel;
309 model = delegateModel;
310 concrete = DelegateModel;
318 return static_cast<QQmlDelegateModel *>(model);
325 QQmlDelegateModel *result = qobject_cast<QQmlDelegateModel *>(model);
326 concrete = result ? DelegateModel : InstanceModel;
341 QQmlInstanceModel *model =
nullptr;
342 ConcreteType concrete = InstanceModel;
void initializeRequiredProperties(QQmlDelegateModelItem *modelItemToIncubate, QObject *object, QQmlDelegateModel::DelegateModelAccess access)
QPointer< QObject > proxiedObject
QQmlRefPointer< QQmlContextData > proxyContext
void statusChanged(Status) override
Called when the status of the incubator changes.
void setInitialState(QObject *) override
Called after the object is first created, but before complex property bindings are evaluated and,...
int index[QQmlListCompositor::MaximumGroupCount]
QQmlDelegateModelItem * incubating
QQDMIncubationTask(QQmlDelegateModelPrivate *l, IncubationMode mode)
QQmlDelegateModelPrivate * vdm
QQmlDelegateModelAttached(QQmlDelegateModelItem *cacheItem, QObject *parent)
void setCacheItem(QQmlDelegateModelItem *item)
void setInItems(bool inItems)
void emitUnresolvedChanged()
void setGroups(const QStringList &groups)
bool isUnresolved() const
\qmlattachedproperty bool QtQml.Models::DelegateModel::isUnresolved
void emitChanges()
\qmlattachedproperty bool QtQml.Models::DelegateModel::inItems
int m_previousIndex[QQmlListCompositor::MaximumGroupCount]
int m_currentIndex[QQmlListCompositor::MaximumGroupCount]
void setInPersistedItems(bool inPersisted)
~QQmlDelegateModelAttached()
QQmlDelegateModel * model() const
\qmlattachedproperty model QtQml.Models::DelegateModel::model
QStringList groups() const
\qmlattachedproperty stringlist QtQml.Models::DelegateModel::groups
int persistedItemsIndex() const
QQmlDelegateModelItem * m_cacheItem
bool inPersistedItems() const
~QQmlDelegateModelEngineData()
QV4::PersistentValue changeProto
QV4::ReturnedValue array(QV4::ExecutionEngine *engine, const QVector< QQmlChangeSet::Change > &changes)
QQmlDelegateModelEngineData(QV4::ExecutionEngine *v4)
virtual void initPackage(int, QQuickPackage *)
virtual void destroyingPackage(QQuickPackage *)
virtual ~QQmlDelegateModelGroupEmitter()
virtual void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset)=0
virtual void createdPackage(int, QQuickPackage *)
QIntrusiveListNode emitterNode
bool parseIndex(const QV4::Value &value, int *index, Compositor::Group *group) const
void createdPackage(int index, QQuickPackage *package)
QPointer< QQmlDelegateModel > model
bool parseGroupArgs(QQmlV4FunctionPtr args, Compositor::Group *group, int *index, int *count, int *groups) const
bool isChangedConnected()
void initPackage(int index, QQuickPackage *package)
void emitModelUpdated(bool reset)
QQmlDelegateModelGroupEmitterList emitters
void destroyingPackage(QQuickPackage *package)
void emitChanges(QV4::ExecutionEngine *engine)
void disableStructuredModelData()
QQDMIncubationTask * incubationTask
static QV4::ReturnedValue set_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg)
void childContextObjectDestroyed(QObject *childContextObject)
virtual void setValue(const QString &role, const QVariant &value)
virtual QV4::ReturnedValue get()
static QV4::ReturnedValue get_member(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &)
static QV4::ReturnedValue get_index(QQmlDelegateModelItem *thisItem, uint flag, const QV4::Value &arg)
static QV4::ReturnedValue get_groups(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
int groupIndex(Compositor::Group group)
QDynamicMetaObjectData * exchangeMetaObject(QDynamicMetaObjectData *metaObject)
virtual bool resolveIndex(const QQmlAdaptorModel &, int)
bool useStructuredModelData
QQmlRefPointer< QQmlDelegateModelItemMetaType > metaType
static QQmlDelegateModelItem * dataForObject(QObject *object)
static QV4::ReturnedValue get_model(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
bool isReferenced() const
virtual void setModelIndex(int idx, int newRow, int newColumn, bool alwaysEmit=false)
virtual QQmlRefPointer< QQmlContextData > initProxy()
bool isObjectReferenced() const
QQmlRefPointer< QQmlContextData > contextData
QQmlDelegateModelAttached * attached() const
static QV4::ReturnedValue set_groups(const QV4::FunctionObject *, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
QPointer< QObject > object
Q_REVISION(2, 12) void rowChanged()
void objectDestroyed(QObject *)
QList< QQmlPartsModel * > models
QQmlDelegateModel * model
void setInitialState(QQDMIncubationTask *incubationTask, QObject *o)
void removeCacheItem(QQmlDelegateModelItem *cacheItem)
QVariant variantValue(Compositor::Group group, int index, const QString &name)
bool m_incubatorCleanupScheduled
void emitCreatedPackage(QQDMIncubationTask *incubationTask, QQuickPackage *package)
QList< QQDMIncubationTask * > m_finishedIncubating
void connectModel(QQmlAdaptorModel *model)
QList< QQmlDelegateModelItem * > m_cache
QQmlDelegateModelParts * m_parts
static qsizetype group_count(QQmlListProperty< QQmlDelegateModelGroup > *property)
QList< QByteArray > m_watchedRoles
QQmlAbstractDelegateComponent * m_delegateChooser
void itemsRemoved(const QVector< Compositor::Remove > &removes)
QPointer< QQmlContext > m_context
void emitCreatedItem(QQDMIncubationTask *incubationTask, QObject *item)
void emitInitItem(QQDMIncubationTask *incubationTask, QObject *item)
static void group_append(QQmlListProperty< QQmlDelegateModelGroup > *property, QQmlDelegateModelGroup *group)
QQmlStrongJSQObjectReference< QQmlComponent > m_delegate
void emitDestroyingItem(QObject *item)
void addCacheItem(QQmlDelegateModelItem *item, Compositor::iterator it)
QQmlRefPointer< QQmlDelegateModelItemMetaType > m_cacheMetaType
void reuseItem(QQmlDelegateModelItem *item, int newModelIndex, int newGroups)
void drainReusableItemsPool(int maxPoolTime)
QQmlDelegateModelGroup * m_persistedItems
static QQmlDelegateModelGroup * group_at(QQmlListProperty< QQmlDelegateModelGroup > *property, qsizetype index)
QQmlDelegateModelGroupEmitterList m_pendingParts
void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset) override
QQmlDelegateModelGroup * m_cacheItems
QObject * object(Compositor::Group group, int index, QQmlIncubator::IncubationMode incubationMode)
void destroyCacheItem(QQmlDelegateModelItem *cacheItem)
void connectToAbstractItemModel()
int adaptorModelCount() const
InsertionResult insert(Compositor::insert_iterator &before, const QV4::Value &object, int groups)
void itemsRemoved(const QVector< Compositor::Remove > &removes, QVarLengthArray< QVector< QQmlChangeSet::Change >, Compositor::MaximumGroupCount > *translatedRemoves, QHash< int, QList< QQmlDelegateModelItem * > > *movedItems=nullptr)
void setGroups(Compositor::iterator from, int count, Compositor::Group group, int groupFlags)
void itemsInserted(const QVector< Compositor::Insert > &inserts, QVarLengthArray< QVector< QQmlChangeSet::Change >, Compositor::MaximumGroupCount > *translatedInserts, QHash< int, QList< QQmlDelegateModelItem * > > *movedItems=nullptr)
void delegateChanged(bool add=true, bool remove=true)
QQmlListCompositor m_compositor
QQmlDelegateModelGroup * m_items
void releaseIncubator(QQDMIncubationTask *incubationTask)
bool m_waitingToFetchMore
void incubatorStatusChanged(QQDMIncubationTask *incubationTask, QQmlIncubator::Status status)
void emitInitPackage(QQDMIncubationTask *incubationTask, QQuickPackage *package)
void addGroups(Compositor::iterator from, int count, Compositor::Group group, int groupFlags)
void emitDestroyingPackage(QQuickPackage *package)
void requestMoreIfNecessary()
QQmlComponent * resolveDelegate(int index)
QMetaObject::Connection m_delegateChooserChanged
QQmlDelegateModelGroup * m_groups[Compositor::MaximumGroupCount]
void itemsChanged(const QVector< Compositor::Change > &changes)
void removeGroups(Compositor::iterator from, int count, Compositor::Group group, int groupFlags)
void itemsInserted(const QVector< Compositor::Insert > &inserts)
void disconnectFromAbstractItemModel()
QQmlReusableDelegateModelItemsPool m_reusableItemsPool
void itemsMoved(const QVector< Compositor::Remove > &removes, const QVector< Compositor::Insert > &inserts)
QQmlAdaptorModel m_adaptorModel
~QQmlDelegateModelPrivate()
QQmlListCompositor::Group m_compositorGroup
static QQmlDelegateModelPrivate * get(QQmlDelegateModel *m)
void emitModelUpdated(const QQmlChangeSet &changeSet, bool reset) override
QVariant variantValue(int index, const QString &role) override
int count() const override
QObject * object(int index, QQmlIncubator::IncubationMode incubationMode=QQmlIncubator::AsynchronousIfNested) override
QList< QByteArray > watchedRoles() const
void updateFilterGroup(Compositor::Group group, const QQmlChangeSet &changeSet)
void setFilterGroup(const QString &group)
QQmlIncubator::Status incubationStatus(int index) override
int indexOf(QObject *item, QObject *objectContext) const override
void destroyingPackage(QQuickPackage *package) override
void setWatchedRoles(const QList< QByteArray > &roles) override
ReleaseFlags release(QObject *item, ReusableFlag reusable=NotReusable) override
void createdPackage(int index, QQuickPackage *package) override
void initPackage(int index, QQuickPackage *package) override
QString filterGroup() const
bool isValid() const override
bool insertItem(QQmlDelegateModelItem *modelItem)
void reuseItem(QQmlDelegateModelItem *item, int newModelIndex)
void drain(int maxPoolTime, std::function< void(QQmlDelegateModelItem *cacheItem)> releaseItem)
QQmlDelegateModelItem * takeItem(const QQmlComponent *delegate, int newIndexHint)
QT_REQUIRE_CONFIG(animation)
QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcEventDispatcher)
QT_REQUIRE_CONFIG(qml_delegate_model)
static bool isDoneIncubating(QQmlIncubator::Status status)
DEFINE_OBJECT_VTABLE(QQmlDelegateModelGroupChange)
DEFINE_OBJECT_VTABLE(QV4::DelegateModelGroupFunction)
DEFINE_OBJECT_VTABLE(QQmlDelegateModelItemObject)
static void incrementIndexes(QQmlDelegateModelItem *cacheItem, int count, const int *deltas)
DEFINE_OBJECT_VTABLE(QQmlDelegateModelGroupChangeArray)
QQmlDelegateModelGroupEmitterList::iterator GroupEmitterListIt
QIntrusiveList< QQmlDelegateModelGroupEmitter, &QQmlDelegateModelGroupEmitter::emitterNode > QQmlDelegateModelGroupEmitterList
QT_BEGIN_NAMESPACE typedef QQmlListCompositor Compositor
QQmlDelegateModelPointer & operator=(QQmlDelegateModelPointer &&)=default
QQmlDelegateModelPointer(QQmlInstanceModel *model)
QQmlDelegateModelPointer & operator=(QQmlInstanceModel *instanceModel)
QQmlDelegateModelPointer(const QQmlDelegateModelPointer &)=default
QQmlDelegateModelPointer()=default
QQmlDelegateModelPointer & operator=(const QQmlDelegateModelPointer &)=default
QQmlInstanceModel * instanceModel()
QQmlDelegateModel * delegateModel()
QQmlDelegateModelPointer(QQmlDelegateModelPointer &&)=default
void init(ExecutionEngine *engine, uint flag, QV4::ReturnedValue(*code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg))
QV4::ReturnedValue(* code)(QQmlDelegateModelItem *item, uint flag, const QV4::Value &arg)
void init(const QVector< QQmlChangeSet::Change > &changes)
QVector< QQmlChangeSet::Change > * changes
QQmlChangeSet::ChangeData change
QQmlDelegateModelItem * item
void init(QQmlDelegateModelItem *item)