diff options
Diffstat (limited to 'src/location')
-rw-r--r-- | src/location/quickmapitems/qdeclarativegeomapitemview.cpp | 49 | ||||
-rw-r--r-- | src/location/quickmapitems/qdeclarativegeomapitemview_p.h | 17 |
2 files changed, 62 insertions, 4 deletions
diff --git a/src/location/quickmapitems/qdeclarativegeomapitemview.cpp b/src/location/quickmapitems/qdeclarativegeomapitemview.cpp index a97174a6..aae41965 100644 --- a/src/location/quickmapitems/qdeclarativegeomapitemview.cpp +++ b/src/location/quickmapitems/qdeclarativegeomapitemview.cpp @@ -87,6 +87,7 @@ void QDeclarativeGeoMapItemView::componentComplete() if (m_delegate) m_delegateModel->setDelegate(m_delegate); + m_delegateModel->setDelegateModelAccess(m_delegateModelAccess); m_delegateModel->componentComplete(); } @@ -189,8 +190,14 @@ void QDeclarativeGeoMapItemView::setModel(const QVariant &model) return; m_itemModel = model; - if (m_componentCompleted) + if (m_componentCompleted) { + + // Make sure to clear all stale items from the map and the model + m_delegateModel->drainReusableItemsPool(0); + removeInstantiatedItems(false); + m_delegateModel->setModel(m_itemModel); + } emit modelChanged(); } @@ -315,6 +322,46 @@ bool QDeclarativeGeoMapItemView::incubateDelegates() const return m_incubationMode == QQmlIncubator::Asynchronous; } +/*! + \qmlproperty enumeration QtLocation::MapItemView::delegateModelAccess + \since 6.10 + + This property determines how delegates can access the model. + + \value DelegateModel.ReadOnly + Prohibit delegates from writing the model via either context properties, + the \c model object, or required properties. + + \value DelegateModel.ReadWrite + Allow delegates to write the model via either context properties, + the \c model object, or required properties. + + \value DelegateModel.Qt5ReadWrite + Allow delegates to write the model via the \c model object and context + properties but \e not via required properties. + + The default is \c DelegateModel.Qt5ReadWrite. + + \sa {Models and Views in Qt Quick#Changing Model Data} +*/ +QQmlDelegateModel::DelegateModelAccess QDeclarativeGeoMapItemView::delegateModelAccess() const +{ + return m_delegateModelAccess; +} + +void QDeclarativeGeoMapItemView::setDelegateModelAccess( + QQmlDelegateModel::DelegateModelAccess delegateModelAccess) +{ + if (m_delegateModelAccess == delegateModelAccess) + return; + + m_delegateModelAccess = delegateModelAccess; + if (m_componentCompleted) + m_delegateModel->setDelegateModelAccess(m_delegateModelAccess); + + emit delegateModelAccessChanged(); +} + QList<QQuickItem *> QDeclarativeGeoMapItemView::mapItems() { return m_instantiatedItems; diff --git a/src/location/quickmapitems/qdeclarativegeomapitemview_p.h b/src/location/quickmapitems/qdeclarativegeomapitemview_p.h index 4b4078ee..57ae5561 100644 --- a/src/location/quickmapitems/qdeclarativegeomapitemview_p.h +++ b/src/location/quickmapitems/qdeclarativegeomapitemview_p.h @@ -52,6 +52,9 @@ class Q_LOCATION_EXPORT QDeclarativeGeoMapItemView : public QDeclarativeGeoMapIt Q_PROPERTY(QQuickTransition *remove MEMBER m_exit REVISION(5, 12)) Q_PROPERTY(QList<QQuickItem *> mapItems READ mapItems REVISION(5, 12)) Q_PROPERTY(bool incubateDelegates READ incubateDelegates WRITE setIncubateDelegates NOTIFY incubateDelegatesChanged REVISION(5, 12)) + Q_PROPERTY(QQmlDelegateModel::DelegateModelAccess delegateModelAccess READ delegateModelAccess + WRITE setDelegateModelAccess NOTIFY delegateModelAccessChanged REVISION(6, 10) FINAL) + public: explicit QDeclarativeGeoMapItemView(QQuickItem *parent = nullptr); @@ -73,6 +76,9 @@ public: void setIncubateDelegates(bool useIncubators); bool incubateDelegates() const; + QQmlDelegateModel::DelegateModelAccess delegateModelAccess() const; + void setDelegateModelAccess(QQmlDelegateModel::DelegateModelAccess delegateModelAccess); + QList<QQuickItem *> mapItems(); // From QQmlParserStatus @@ -84,6 +90,7 @@ Q_SIGNALS: void delegateChanged(); void autoFitViewportChanged(); void incubateDelegatesChanged(); + Q_REVISION(6, 10) void delegateModelAccessChanged(); private Q_SLOTS: void destroyingItem(QObject *object); @@ -106,18 +113,22 @@ private: void addItemGroupToMap(QDeclarativeGeoMapItemGroup *item, int index, bool createdItem); void addDelegateToMap(QQuickItem *object, int index, bool createdItem = false); - bool m_componentCompleted = false; QQmlIncubator::IncubationMode m_incubationMode = QQmlIncubator::Asynchronous; QQmlComponent *m_delegate = nullptr; QVariant m_itemModel; QDeclarativeGeoMap *m_map = nullptr; QList<QQuickItem *> m_instantiatedItems; - bool m_fitViewport = false; - bool m_creatingObject = false; QQmlDelegateModel *m_delegateModel = nullptr; QQuickTransition *m_enter = nullptr; QQuickTransition *m_exit = nullptr; + QQmlDelegateModel::DelegateModelAccess m_delegateModelAccess + = QQmlDelegateModel::Qt5ReadWrite; + + bool m_componentCompleted = false; + bool m_fitViewport = false; + bool m_creatingObject = false; + friend class QDeclarativeGeoMap; friend class QDeclarativeGeoMapItemBase; friend class QDeclarativeGeoMapItemTransitionManager; |