7#include <QtCore/QTimer>
9#include <QtQml/private/qqmlincubator_p.h>
10#include <QtQmlModels/private/qqmlchangeset_p.h>
11#include <QtQml/private/qqmlcomponent_p.h>
19 if (!modelItem->incubationTask)
22 const auto status = modelItem->incubationTask->status();
30 delete modelItem->object;
31 modelItem->object =
nullptr;
32 modelItem->contextData.reset();
33 modelItem->deleteLater();
51 for (
const auto modelItem : m_modelItems) {
61 if (modelItem->object) {
62 delete modelItem->object;
63 modelItem->object =
nullptr;
64 modelItem->contextData.reset();
68 deleteAllFinishedIncubationTasks();
75 if (m_delegateChooser) {
82 chooser = qobject_cast<QQmlAbstractDelegateComponent *>(
delegate);
131 if (modelItem->object) {
134 modelItem->referenceObject();
135 return modelItem->object;
139 incubateModelItem(modelItem, incubationMode);
140 if (!isDoneIncubating(modelItem))
144 Q_ASSERT(!modelItem->incubationTask);
146 if (!modelItem->object) {
151 Q_ASSERT(!modelItem->isObjectReferenced());
152 Q_ASSERT(!modelItem->isReferenced());
153 m_modelItems.
remove(modelItem->index);
159 modelItem->referenceObject();
160 return modelItem->object;
170 Q_ASSERT(m_modelItems[modelItem->index]->object ==
object);
172 if (!modelItem->releaseObject())
175 if (modelItem->isReferenced()) {
186 m_modelItems.
remove(modelItem->index);
190 emit itemPooled(modelItem->index, modelItem->object);
195 destroyModelItem(modelItem, Deferred);
202 if (
mode == Deferred)
203 modelItem->destroyObject();
205 delete modelItem->object;
215 modelItem->releaseObject();
218 Q_ASSERT(!modelItem->isObjectReferenced());
219 Q_ASSERT(!modelItem->isReferenced());
222 Q_ASSERT(m_modelItems[modelItem->index]->object ==
object);
224 m_modelItems.
remove(modelItem->index);
239 Q_ASSERT(modelItem->incubationTask);
240 Q_ASSERT(!modelItem->isObjectReferenced());
244 if (modelItem->object)
245 delete modelItem->object;
254 destroyModelItem(modelItem, Immediate);
265 const bool alwaysEmit =
true;
266 const int newRow = m_adaptorModel.
rowAt(newModelIndex);
267 const int newColumn = m_adaptorModel.
columnAt(newModelIndex);
268 item->setModelIndex(newModelIndex, newRow, newColumn, alwaysEmit);
272 auto const itemAsList = QList<QQmlDelegateModelItem *>() <<
item;
273 auto const updateAllRoles = QVector<int>();
274 m_adaptorModel.
notify(itemAsList, newModelIndex, 1, updateAllRoles);
278 emit itemReused(newModelIndex,
item->object);
285 modelItem->scriptRef++;
287 if (modelItem->incubationTask) {
292 modelItem->incubationTask->forceCompletion();
296 QQmlContext *creationContext = modelItem->delegate->creationContext();
297 const QQmlRefPointer<QQmlContextData> componentContext
302 modelItem->contextData = componentContext;
304 modelItem->incubationTask,
312 ctxt->setContextObject(modelItem);
313 modelItem->contextData = ctxt;
316 modelItem->incubationTask,
325 modelItem->scriptRef--;
331 Q_ASSERT(modelItem->incubationTask);
333 modelItem->incubationTask =
nullptr;
344 modelItem->scriptRef++;
346 modelItem->scriptRef--;
348 qWarning() <<
"Error incubating delegate:" << incubationTask->
errors();
351 if (!modelItem->isReferenced() && !modelItem->isObjectReferenced()) {
356 m_modelItems.
remove(modelItem->index);
358 if (modelItem->object) {
359 modelItem->scriptRef++;
361 modelItem->scriptRef--;
362 Q_ASSERT(!modelItem->isReferenced());
365 deleteModelItemLater(modelItem);
368 deleteIncubationTaskLater(incubationTask);
372 const auto modelItem = m_modelItems.
value(
index,
nullptr);
376 if (modelItem->incubationTask)
390 const auto modelItem = m_modelItems.
value(
index,
nullptr);
393 if (!modelItem->object)
395 if (!modelItem->incubationTask)
398 bool wasInRequired =
false;
408 componentProp.write(
value);
409 return wasInRequired;
412void QQmlTableInstanceModel::deleteIncubationTaskLater(
QQmlIncubator *incubationTask)
417 m_finishedIncubationTasks.
append(incubationTask);
418 if (m_finishedIncubationTasks.
size() == 1)
419 QTimer::singleShot(1,
this, &QQmlTableInstanceModel::deleteAllFinishedIncubationTasks);
422void QQmlTableInstanceModel::deleteAllFinishedIncubationTasks()
425 m_finishedIncubationTasks.
clear();
430 return m_adaptorModel.
model();
455 int numberOfRowsChanged =
end.row() -
begin.row() + 1;
456 int numberOfColumnsChanged =
end.column() -
begin.column() + 1;
460 const int rowIndex =
begin.row() + (columnIndex *
rows());
461 m_adaptorModel.
notify(m_modelItems.
values(), rowIndex, numberOfRowsChanged, roles);
465void QQmlTableInstanceModel::modelAboutToBeResetCallback()
473 auto oldRoleNames = aim->roleNames();
475 if (oldRoleNames != aim->roleNames())
490 m_delegateChooser =
nullptr;
493 qobject_cast<QQmlAbstractDelegateComponent *>(
delegate);
495 m_delegateChooser = adc;
503 return m_adaptorModel.
adaptsAim() ? m_adaptorModel.
aim() :
nullptr;
534#include "moc_qqmltableinstancemodel_p.cpp"
void modelAboutToBeReset(QPrivateSignal)
void modelReset(QPrivateSignal)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles=QList< int >())
This signal is emitted whenever the data in an existing item changes.
bool remove(const Key &key)
Removes the item that has the key from the hash.
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
qsizetype size() const noexcept
void append(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
void deleteLater()
\threadsafe
void initializeRequiredProperties(QQmlDelegateModelItem *modelItemToIncubate, QObject *object)
bool notify(const QList< QQmlDelegateModelItem * > &items, int index, int count, const QVector< int > &roles) const
QAbstractItemModel * aim()
int rowAt(int index) const
QQmlDelegateModelItem * createItem(const QQmlRefPointer< QQmlDelegateModelItemMetaType > &metaType, int index)
int columnAt(int index) const
void useImportVersion(QTypeRevision revision)
void setModel(const QVariant &variant)
virtual void incubateObject(QQmlIncubator *incubationTask, QQmlComponent *component, QQmlEngine *engine, const QQmlRefPointer< QQmlContextData > &context, const QQmlRefPointer< QQmlContextData > &forContext)
static QQmlComponentPrivate * get(QQmlComponent *c)
static QQmlProperty removePropertyFromRequired(QObject *createdComponent, const QString &name, RequiredProperties *requiredProperties, QQmlEngine *engine, bool *wasInRequiredProperties=nullptr)
The QQmlComponent class encapsulates a QML component definition.
static QQmlRefPointer< QQmlContextData > get(QQmlContext *context)
static QQmlRefPointer< QQmlContextData > createRefCounted(const QQmlRefPointer< QQmlContextData > &parent)
The QQmlContext class defines a context within a QML engine.
bool isValid() const
Returns whether the context is valid.
QQmlEngine * engine() const
Return the context's QQmlEngine, or \nullptr if the context has no QQmlEngine or the QQmlEngine was d...
QQDMIncubationTask * incubationTask
QPointer< QObject > object
static QQmlEnginePrivate * get(QQmlEngine *e)
static QQmlIncubatorPrivate * get(QQmlIncubator *incubator)
The QQmlIncubator class allows QML objects to be created asynchronously.
QList< QQmlError > errors() const
Return the list of errors encountered while incubating the object.
QObject * object() const
Return the incubated object if the status is Ready, otherwise 0.
IncubationMode
Specifies the mode the incubator operates in.
Status status() const
Return the current status of the incubator.
Status
Specifies the status of the QQmlIncubator.
void createdItem(int index, QObject *object)
void destroyingItem(QObject *object)
void initItem(int index, QObject *object)
The QQmlProperty class abstracts accessing properties on objects created from QML.
void drain(int maxPoolTime, std::function< void(QQmlDelegateModelItem *cacheItem)> releaseItem)
void insertItem(QQmlDelegateModelItem *modelItem)
QQmlDelegateModelItem * takeItem(const QQmlComponent *delegate, int newIndexHint)
void statusChanged(Status status) override
Called when the status of the incubator changes.
QQmlDelegateModelItem * modelItemToIncubate
QQmlTableInstanceModel * tableInstanceModel
void setInitialState(QObject *object) override
Called after the object is first created, but before complex property bindings are evaluated and,...
const QAbstractItemModel * abstractItemModel() const override
void drainReusableItemsPool(int maxPoolTime) override
~QQmlTableInstanceModel() override
bool setRequiredProperty(int index, const QString &name, const QVariant &value) final
QQmlTableInstanceModel(QQmlContext *qmlContext, QObject *parent=nullptr)
void reuseItem(QQmlDelegateModelItem *item, int newModelIndex)
void setModel(const QVariant &model)
QQmlComponent * delegate() const
void useImportVersion(QTypeRevision version)
friend class QQmlTableInstanceModelIncubationTask
void setDelegate(QQmlComponent *)
QQmlIncubator::Status incubationStatus(int index) override
void dispose(QObject *object)
ReleaseFlags release(QObject *object, ReusableFlag reusable=NotReusable) override
void cancel(int) override
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool singleShot
whether the timer is a single-shot timer
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint64 GLenum void * handle
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLsizei const GLenum * props
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLenum GLsizei void * row
QQmlContext * qmlContext(const QObject *obj)
QT_BEGIN_NAMESPACE const char * kModelItemTag
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
QSqlQueryModel * model
[16]
myObject disconnect()
[26]
bool contains(const AT &t) const noexcept