diff options
Diffstat (limited to 'src/qml/types')
-rw-r--r-- | src/qml/types/qqmlbind.cpp | 2 | ||||
-rw-r--r-- | src/qml/types/qqmlconnections.cpp | 2 | ||||
-rw-r--r-- | src/qml/types/qqmldelegatemodel.cpp | 134 | ||||
-rw-r--r-- | src/qml/types/qqmlinstantiator.cpp | 10 | ||||
-rw-r--r-- | src/qml/types/qqmlinstantiator_p_p.h | 9 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel.cpp | 34 | ||||
-rw-r--r-- | src/qml/types/qqmllistmodel_p_p.h | 7 | ||||
-rw-r--r-- | src/qml/types/qqmlobjectmodel.cpp | 3 | ||||
-rw-r--r-- | src/qml/types/qquickpackage.cpp | 3 |
9 files changed, 115 insertions, 89 deletions
diff --git a/src/qml/types/qqmlbind.cpp b/src/qml/types/qqmlbind.cpp index fcb3079891..4c4e541e11 100644 --- a/src/qml/types/qqmlbind.cpp +++ b/src/qml/types/qqmlbind.cpp @@ -139,7 +139,7 @@ public: If the binding target or binding property is changed, the bound value is immediately pushed onto the new target. - \sa QtQml + \sa {Qt QML} */ QQmlBind::QQmlBind(QObject *parent) : QObject(*(new QQmlBindPrivate), parent) diff --git a/src/qml/types/qqmlconnections.cpp b/src/qml/types/qqmlconnections.cpp index 286933e557..93df0842fe 100644 --- a/src/qml/types/qqmlconnections.cpp +++ b/src/qml/types/qqmlconnections.cpp @@ -126,7 +126,7 @@ public: } \endqml - \sa QtQml + \sa {Qt QML} */ QQmlConnections::QQmlConnections(QObject *parent) : QObject(*(new QQmlConnectionsPrivate), parent) diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index aa665e4283..afd2a49155 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -144,8 +144,9 @@ QQmlDelegateModelParts::QQmlDelegateModelParts(QQmlDelegateModel *parent) The VisualDataModel type encapsulates a model and the delegate that will be instantiated for items in a model. - This type is provided by QtQuick 2 for compatibility reasons. The same implementation - is now primarily available as DelegateModel in the QtQml.Models module. + This type is provided by the \l{Qt QML} module due to compatibility reasons. + The same implementation is now primarily available as DelegateModel in the + \l{Qt QML Models QML Types}{Qt QML Models} module. \sa {QtQml.Models2::DelegateModel} */ @@ -158,9 +159,6 @@ QQmlDelegateModelParts::QQmlDelegateModelParts(QQmlDelegateModel *parent) The DelegateModel type encapsulates a model and the delegate that will be instantiated for items in the model. - This element is also available as DelegateModel in the QtQuick module. For full details, - see the \l DelegateModel documentation. - It is usually not necessary to create a DelegateModel. However, it can be useful for manipulating and accessing the \l modelIndex when a QAbstractItemModel subclass is used as the @@ -170,7 +168,10 @@ QQmlDelegateModelParts::QQmlDelegateModelParts(QQmlDelegateModel *parent) The example below illustrates using a DelegateModel with a ListView. - \snippet qml/visualdatamodel.qml 0 + \snippet delegatemodel/visualdatamodel.qml 0 + + \note This type is also available as \l VisualDataModel in the \l{Qt QML} + module due to compatibility reasons. */ QQmlDelegateModelPrivate::QQmlDelegateModelPrivate(QQmlContext *ctxt) @@ -243,6 +244,8 @@ QQmlDelegateModel::~QQmlDelegateModel() cacheItem->objectRef = 0; if (!cacheItem->isReferenced()) delete cacheItem; + else if (cacheItem->incubationTask) + cacheItem->incubationTask->vdm = 0; } } @@ -408,10 +411,10 @@ void QQmlDelegateModel::setDelegate(QQmlComponent *delegate) the new directory's contents. \c main.cpp: - \snippet qml/visualdatamodel_rootindex/main.cpp 0 + \snippet delegatemodel/visualdatamodel_rootindex/main.cpp 0 \c view.qml: - \snippet qml/visualdatamodel_rootindex/view.qml 0 + \snippet delegatemodel/visualdatamodel_rootindex/view.qml 0 If the \l model is a QAbstractItemModel subclass, the delegate can also reference a \c hasModelChildren property (optionally qualified by a @@ -615,7 +618,7 @@ QQmlDelegateModelGroup *QQmlDelegateModelPrivate::group_at( The following example illustrates using groups to select items in a model. - \snippet qml/visualdatagroup.qml 0 + \snippet delegatemodel/visualdatagroup.qml 0 */ QQmlListProperty<QQmlDelegateModelGroup> QQmlDelegateModel::groups() @@ -791,9 +794,28 @@ void QQmlDelegateModelPrivate::emitDestroyingPackage(QQuickPackage *package) QQmlDelegateModelGroupPrivate::get(m_groups[i])->destroyingPackage(package); } +static bool isDoneIncubating(QQmlIncubator::Status status) +{ + return status == QQmlIncubator::Ready || status == QQmlIncubator::Error; +} + void QQDMIncubationTask::statusChanged(Status status) { - vdm->incubatorStatusChanged(this, status); + if (vdm) { + vdm->incubatorStatusChanged(this, status); + } else if (isDoneIncubating(status)) { + Q_ASSERT(incubating); + // The model was deleted from under our feet, cleanup ourselves + if (incubating->object) { + delete incubating->object; + + incubating->object = 0; + incubating->contextData->destroy(); + incubating->contextData = 0; + } + incubating->scriptRef = 0; + incubating->deleteLater(); + } } void QQmlDelegateModelPrivate::releaseIncubator(QQDMIncubationTask *incubationTask) @@ -821,7 +843,7 @@ void QQmlDelegateModelPrivate::removeCacheItem(QQmlDelegateModelItem *cacheItem) void QQmlDelegateModelPrivate::incubatorStatusChanged(QQDMIncubationTask *incubationTask, QQmlIncubator::Status status) { Q_Q(QQmlDelegateModel); - if (status != QQmlIncubator::Ready && status != QQmlIncubator::Error) + if (!isDoneIncubating(status)) return; QQmlDelegateModelItem *cacheItem = incubationTask->incubating; @@ -830,10 +852,12 @@ void QQmlDelegateModelPrivate::incubatorStatusChanged(QQDMIncubationTask *incuba releaseIncubator(incubationTask); if (status == QQmlIncubator::Ready) { + cacheItem->referenceObject(); if (QQuickPackage *package = qmlobject_cast<QQuickPackage *>(cacheItem->object)) emitCreatedPackage(incubationTask, package); else emitCreatedItem(incubationTask, cacheItem->object); + cacheItem->releaseObject(); } else if (status == QQmlIncubator::Error) { qmlInfo(q, m_delegate->errors()) << "Error creating delegate"; } @@ -846,8 +870,10 @@ void QQmlDelegateModelPrivate::incubatorStatusChanged(QQDMIncubationTask *incuba delete cacheItem->object; cacheItem->object = 0; cacheItem->scriptRef -= 1; - cacheItem->contextData->destroy(); + if (cacheItem->contextData) + cacheItem->contextData->destroy(); cacheItem->contextData = 0; + if (!cacheItem->isReferenced()) { removeCacheItem(cacheItem); delete cacheItem; @@ -945,7 +971,7 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, bo // Remove the temporary reference count. cacheItem->scriptRef -= 1; - if (cacheItem->object) + if (cacheItem->object && (!cacheItem->incubationTask || isDoneIncubating(cacheItem->incubationTask->status()))) return cacheItem->object; cacheItem->releaseObject(); @@ -960,7 +986,7 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, bo /* If asynchronous is true or the component is being loaded asynchronously due to an ancestor being loaded asynchronously, item() may return 0. In this - case itemCreated() will be emitted when the item is available. The item + case createdItem() will be emitted when the item is available. The item at this stage does not have any references, so item() must be called again to ensure a reference is held. Any call to item() which returns a valid item must be matched by a call to release() in order to destroy the item. @@ -1168,8 +1194,8 @@ void QQmlDelegateModelPrivate::itemsInserted( cacheIndex = insert.cacheIndex + insert.count; } } - for (; cacheIndex < m_cache.count(); ++cacheIndex) - incrementIndexes(m_cache.at(cacheIndex), m_groupCount, inserted); + for (const QList<QQmlDelegateModelItem *> cache = m_cache; cacheIndex < cache.count(); ++cacheIndex) + incrementIndexes(cache.at(cacheIndex), m_groupCount, inserted); } void QQmlDelegateModelPrivate::itemsInserted(const QVector<Compositor::Insert> &inserts) @@ -1193,8 +1219,9 @@ void QQmlDelegateModel::_q_itemsInserted(int index, int count) d->m_count += count; - for (int i = 0, c = d->m_cache.count(); i < c; ++i) { - QQmlDelegateModelItem *item = d->m_cache.at(i); + const QList<QQmlDelegateModelItem *> cache = d->m_cache; + for (int i = 0, c = cache.count(); i < c; ++i) { + QQmlDelegateModelItem *item = cache.at(i); if (item->modelIndex() >= index) item->setModelIndex(item->modelIndex() + count); } @@ -1285,8 +1312,8 @@ void QQmlDelegateModelPrivate::itemsRemoved( } } - for (; cacheIndex < m_cache.count(); ++cacheIndex) - incrementIndexes(m_cache.at(cacheIndex), m_groupCount, removed); + for (const QList<QQmlDelegateModelItem *> cache = m_cache; cacheIndex < cache.count(); ++cacheIndex) + incrementIndexes(cache.at(cacheIndex), m_groupCount, removed); } void QQmlDelegateModelPrivate::itemsRemoved(const QVector<Compositor::Remove> &removes) @@ -1308,9 +1335,9 @@ void QQmlDelegateModel::_q_itemsRemoved(int index, int count) return; d->m_count -= count; - - for (int i = 0, c = d->m_cache.count(); i < c; ++i) { - QQmlDelegateModelItem *item = d->m_cache.at(i); + const QList<QQmlDelegateModelItem *> cache = d->m_cache; + for (int i = 0, c = cache.count(); i < c; ++i) { + QQmlDelegateModelItem *item = cache.at(i); if (item->modelIndex() >= index + count) item->setModelIndex(item->modelIndex() - count); else if (item->modelIndex() >= index) @@ -1356,8 +1383,9 @@ void QQmlDelegateModel::_q_itemsMoved(int from, int to, int count) const int maximum = qMax(from, to) + count; const int difference = from > to ? count : -count; - for (int i = 0, c = d->m_cache.count(); i < c; ++i) { - QQmlDelegateModelItem *item = d->m_cache.at(i); + const QList<QQmlDelegateModelItem *> cache = d->m_cache; + for (int i = 0, c = cache.count(); i < c; ++i) { + QQmlDelegateModelItem *item = cache.at(i); if (item->modelIndex() >= from && item->modelIndex() < from + count) item->setModelIndex(item->modelIndex() - from + to); else if (item->modelIndex() >= minimum && item->modelIndex() < maximum) @@ -1413,8 +1441,9 @@ void QQmlDelegateModel::_q_modelReset() if (d->m_complete) { d->m_count = d->m_adaptorModel.count(); - for (int i = 0, c = d->m_cache.count(); i < c; ++i) { - QQmlDelegateModelItem *item = d->m_cache.at(i); + const QList<QQmlDelegateModelItem *> cache = d->m_cache; + for (int i = 0, c = cache.count(); i < c; ++i) { + QQmlDelegateModelItem *item = cache.at(i); if (item->modelIndex() != -1) item->setModelIndex(-1); } @@ -1773,8 +1802,12 @@ QQmlDelegateModelItem::~QQmlDelegateModelItem() Q_ASSERT(objectRef == 0); Q_ASSERT(!object); - if (incubationTask && metaType->model) - QQmlDelegateModelPrivate::get(metaType->model)->releaseIncubator(incubationTask); + if (incubationTask) { + if (metaType->model) + QQmlDelegateModelPrivate::get(metaType->model)->releaseIncubator(incubationTask); + else + delete incubationTask; + } metaType->release(); @@ -2149,14 +2182,31 @@ void QQmlDelegateModelGroupPrivate::destroyingPackage(QQuickPackage *package) } /*! - \qmltype DelegateModelGroup + \qmltype VisualDataGroup \instantiates QQmlDelegateModelGroup \inqmlmodule QtQuick 2 \ingroup qtquick-models \brief Encapsulates a filtered set of visual data items - The DelegateModelGroup type provides a means to address the model data of a DelegateModel's - delegate items, as well as sort and filter these delegate items. + The VisualDataGroup type provides a means to address the model data of a + model's delegate items, as well as sort and filter these delegate items. + + This type is provided by the \l{Qt QML} module due to compatibility reasons. + The same implementation is now primarily available as \l DelegateModelGroup + in the \l{Qt QML Models QML Types}{Qt QML Models} module. + + \sa {QtQml.Models2::DelegateModelGroup} +*/ +/*! + \qmltype DelegateModelGroup + \instantiates QQmlDelegateModelGroup + \inqmlmodule QtQml.Models 2 + \ingroup qtquick-models + \brief Encapsulates a filtered set of visual data items + + The DelegateModelGroup type provides a means to address the model data of a + DelegateModel's delegate items, as well as sort and filter these delegate + items. The initial set of instantiable delegate items in a DelegateModel is represented by its \l {QtQml.Models2::DelegateModel::items}{items} group, which normally directly reflects @@ -2180,24 +2230,11 @@ void QQmlDelegateModelGroupPrivate::destroyingPackage(QQuickPackage *package) type or to cherry-pick specific items that should be instantiated irregardless of whether they're currently within a view's visible area. - \sa {QML Dynamic View Ordering Tutorial} -*/ -/*! - \qmltype DelegateModelGroup - \instantiates QQmlDelegateModelGroup - \inqmlmodule QtQml.Models 2 - \brief Encapsulates a filtered set of visual data items - - The DelegateModelGroup type provides a means to address the model data of a DelegateModel's - delegate items, as well as sort and filter these delegate items. - - This element is also available as DelegateModelGroup in the QtQuick module. For full details, - see the \l DelegateModelGroup documentation. + \note This type is also available as \l VisualDataGroup in the \l{Qt QML} + module due to compatibility reasons. - \sa {QtQuick::DelegateModelGroup} + \sa {QML Dynamic View Ordering Tutorial} */ - - QQmlDelegateModelGroup::QQmlDelegateModelGroup(QObject *parent) : QObject(*new QQmlDelegateModelGroupPrivate, parent) { @@ -3222,4 +3259,3 @@ QV4::Value QQmlDelegateModelEngineData::array( } QT_END_NAMESPACE - diff --git a/src/qml/types/qqmlinstantiator.cpp b/src/qml/types/qqmlinstantiator.cpp index a2a1fa23ad..234494e088 100644 --- a/src/qml/types/qqmlinstantiator.cpp +++ b/src/qml/types/qqmlinstantiator.cpp @@ -52,6 +52,7 @@ QT_BEGIN_NAMESPACE QQmlInstantiatorPrivate::QQmlInstantiatorPrivate() : componentComplete(true) + , effectiveReset(false) , active(true) , async(false) , ownModel(false) @@ -124,7 +125,7 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo { Q_Q(QQmlInstantiator); - if (componentComplete) + if (!componentComplete || effectiveReset) return; if (reset) { @@ -162,7 +163,7 @@ void QQmlInstantiatorPrivate::_q_modelUpdated(const QQmlChangeSet &changeSet, bo objects = objects.mid(0, index) + movedObjects + objects.mid(index); } else for (int i = 0; i < insert.count; ++i) { int modelIndex = index + i; - QObject* obj = instanceModel->object(i, async); + QObject* obj = instanceModel->object(modelIndex, async); if (obj) _q_createdItem(modelIndex, obj); } @@ -378,8 +379,11 @@ void QQmlInstantiator::setModel(const QVariant &v) if (!d->ownModel) d->makeModel(); - if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel *>(d->instanceModel)) + if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel *>(d->instanceModel)) { + d->effectiveReset = true; dataModel->setModel(v); + d->effectiveReset = false; + } } if (d->instanceModel != prevModel) { diff --git a/src/qml/types/qqmlinstantiator_p_p.h b/src/qml/types/qqmlinstantiator_p_p.h index 79459299dc..a7d6905a7e 100644 --- a/src/qml/types/qqmlinstantiator_p_p.h +++ b/src/qml/types/qqmlinstantiator_p_p.h @@ -75,10 +75,11 @@ public: void _q_createdItem(int, QObject *); void _q_modelUpdated(const QQmlChangeSet &, bool); - bool componentComplete; - bool active; - bool async; - bool ownModel; + bool componentComplete:1; + bool effectiveReset:1; + bool active:1; + bool async:1; + bool ownModel:1; QVariant model; QQmlInstanceModel *instanceModel; QQmlComponent *delegate; diff --git a/src/qml/types/qqmllistmodel.cpp b/src/qml/types/qqmllistmodel.cpp index 8e1821092b..5091e46499 100644 --- a/src/qml/types/qqmllistmodel.cpp +++ b/src/qml/types/qqmllistmodel.cpp @@ -1412,22 +1412,12 @@ QQmlListModelParser::ListInstruction *QQmlListModelParser::ListModelData::instru \qmltype ListModel \instantiates QQmlListModel \inqmlmodule QtQml.Models 2 - \brief Defines a free-form list data source - - The ListModel is a simple container of ListElement definitions, each containing data roles. - The contents can be defined dynamically, or explicitly in QML. - - This type is also available in the QtQuick 2 import. For full documentation, see \l QtQuick2::ListModel -*/ -/*! - \qmltype ListModel - \instantiates QQmlListModel - \inqmlmodule QtQuick 2 - \brief Defines a free-form list data source \ingroup qtquick-models + \brief Defines a free-form list data source - The ListModel is a simple container of ListElement definitions, each containing data roles. - The contents can be defined dynamically, or explicitly in QML. + The ListModel is a simple container of ListElement definitions, each + containing data roles. The contents can be defined dynamically, or + explicitly in QML. The number of elements in the model can be obtained from its \l count property. A number of familiar methods are also provided to manipulate the contents of the @@ -1509,7 +1499,7 @@ QQmlListModelParser::ListInstruction *QQmlListModelParser::ListModelData::instru handler. You must call sync() or else the changes made to the list from the external thread will not be reflected in the list model in the main thread. - \sa {qml-data-models}{Data Models}, {declarative/threading/threadedlistmodel}{Threaded ListModel example}, QtQml + \sa {qml-data-models}{Data Models}, {declarative/threading/threadedlistmodel}{Threaded ListModel example}, {Qt QML} */ QQmlListModel::QQmlListModel(QObject *parent) @@ -1787,7 +1777,7 @@ QHash<int, QByteArray> QQmlListModel::roleNames() const } /*! - \qmlproperty bool QtQml2::ListModel::dynamicRoles + \qmlproperty bool ListModel::dynamicRoles By default, the type of a role is fixed the first time the role is used. For example, if you create a role called @@ -1833,7 +1823,7 @@ void QQmlListModel::setDynamicRoles(bool enableDynamicRoles) } /*! - \qmlproperty int QtQml2::ListModel::count + \qmlproperty int ListModel::count The number of data entries in the model. */ int QQmlListModel::count() const @@ -2516,16 +2506,6 @@ bool QQmlListModelParser::definesEmptyList(const QString &s) \instantiates QQmlListElement \inqmlmodule QtQml.Models 2 \brief Defines a data item in a ListModel - - List elements are defined inside ListModel definitions, and represent items in a list. - - This type is also available in the QtQuick 2 import. For full documentation, see \l QtQuick2::ListElement -*/ -/*! - \qmltype ListElement - \instantiates QQmlListElement - \inqmlmodule QtQuick 2 - \brief Defines a data item in a ListModel \ingroup qtquick-models List elements are defined inside ListModel definitions, and represent items in a diff --git a/src/qml/types/qqmllistmodel_p_p.h b/src/qml/types/qqmllistmodel_p_p.h index 5cee6a0251..48cd248c32 100644 --- a/src/qml/types/qqmllistmodel_p_p.h +++ b/src/qml/types/qqmllistmodel_p_p.h @@ -229,6 +229,9 @@ private: QStringHash<Role *> roleHash; }; +/*! +\internal +*/ class ListElement { public: @@ -292,6 +295,9 @@ private: friend class ListModel; }; +/*! +\internal +*/ class ListModel { public: @@ -375,4 +381,3 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(ListModel *); #endif // QQUICKLISTMODEL_P_P_H - diff --git a/src/qml/types/qqmlobjectmodel.cpp b/src/qml/types/qqmlobjectmodel.cpp index 7f7bf92fa3..f2a7477c1b 100644 --- a/src/qml/types/qqmlobjectmodel.cpp +++ b/src/qml/types/qqmlobjectmodel.cpp @@ -176,7 +176,7 @@ public: as a model. This element is now primarily available as ObjectModel in the QtQml.Models module. - VisualItemModel continues to be provided, with the same implementation, in QtQuick for + VisualItemModel continues to be provided, with the same implementation, in \c QtQuick for compatibility reasons. For full details about the type, see the \l ObjectModel documentation. @@ -266,4 +266,3 @@ QQmlObjectModelAttached *QQmlObjectModel::qmlAttachedProperties(QObject *obj) } QT_END_NAMESPACE - diff --git a/src/qml/types/qquickpackage.cpp b/src/qml/types/qquickpackage.cpp index e885524b27..bdb8a4bc15 100644 --- a/src/qml/types/qquickpackage.cpp +++ b/src/qml/types/qquickpackage.cpp @@ -73,7 +73,8 @@ QT_BEGIN_NAMESPACE \snippet quick/views/package/view.qml 0 - \sa {quick/views/package}{Package example}, {quick/demos/photoviewer}{Photo Viewer example}, QtQml + \sa {quick/views/package}{Package example}, {quick/demos/photoviewer}{Photo + Viewer example}, {Qt QML} */ /*! |