summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-02-08 18:15:35 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-02-23 12:00:43 +0000
commit3a83884d4971d4a6fe8e5e017862684a47c10568 (patch)
tree590d40ac3218b5997d0fefb4e201bf718acf7b5f
parentd87f58c8d8eab0c66a9b0e2d0355ff42fbf33b93 (diff)
downloadqtlocation-3a83884d4971d4a6fe8e5e017862684a47c10568.tar.gz
Prepare for dual mode item creation in MapObjectView
Put variables in place to switch between sync/async incubation. Change-Id: Iabe2d0af4b6a4c5f4c4a8e840333bba44926db3f Reviewed-by: BogDan Vatra <bogdan@kdab.com>
-rw-r--r--src/locationlabs/qmapobjectview.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/locationlabs/qmapobjectview.cpp b/src/locationlabs/qmapobjectview.cpp
index 59db7b95..310775a1 100644
--- a/src/locationlabs/qmapobjectview.cpp
+++ b/src/locationlabs/qmapobjectview.cpp
@@ -47,6 +47,7 @@ QT_BEGIN_NAMESPACE
*/
+static const QQmlIncubator::IncubationMode incubationMode = QQmlIncubator::Asynchronous;
QMapObjectViewPrivate::QMapObjectViewPrivate(QGeoMapObject *q)
: QGeoMapObjectPrivate(q)
@@ -281,7 +282,7 @@ void QMapObjectView::modelUpdated(const QQmlChangeSet &changeSet, bool reset)
for (const QQmlChangeSet::Change &c: changeSet.inserts()) {
for (int idx = c.start(); idx < c.end(); idx++) {
m_instantiatedMapObjects.insert(idx, nullptr);
- QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(idx, QQmlIncubator::Asynchronous));
+ QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(idx, incubationMode));
if (mo) // if not, a createdItem signal will be emitted.
addMapObjectToMap(mo, idx);
}
@@ -320,13 +321,15 @@ void QMapObjectView::removeMapObjectFromMap(int index)
// See QObject *QQmlDelegateModel::object(int index, QQmlIncubator::IncubationMode incubationMode) doc
// for explanation on when createdItem is emitted.
-void QMapObjectView::createdItem(int index, QObject *object)
+void QMapObjectView::createdItem(int index, QObject * /*object*/)
{
- // According to the documentation above, object() should be called again for index.
- // However, this seem to result in too many references for index, which will prevent destruction with
- // one single release()
- // QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(index, QQmlIncubator::Asynchronous));
- QGeoMapObject *mo = qobject_cast<QGeoMapObject *>(object);
+ if (m_instantiatedMapObjects.at(index))
+ return; // The first call to object() apparently returned a valid item. Don't call it again.
+
+ // If here, according to the documentation above, object() should be called again for index,
+ // or else, it will be destroyed exiting this scope
+ QGeoMapObject *mo = nullptr;
+ mo = qobject_cast<QGeoMapObject *>(m_delegateModel->object(index, incubationMode));
if (mo)
addMapObjectToMap(mo, index);
}