From f4a98904855b57c6ad42f9ead29737d0201b6733 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Sun, 5 Jan 2020 21:13:53 +0100 Subject: Fix MapObjectView not setting properties Set parent for incubated objects in MapObjectView to the view. Also properly set component completed when removing the view from a map and then readding it. Finally silence the useless warning about MapObjectView being unsupported, as the default MOV is basically what's wanted. Change-Id: Iecbc345ced99754d0d09112b4b30eaca2bb078e5 Reviewed-by: Alex Blasche --- src/location/declarativemaps/qgeomapobject.cpp | 6 ++++-- src/location/labs/qmapobjectview.cpp | 14 +++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/location/declarativemaps/qgeomapobject.cpp b/src/location/declarativemaps/qgeomapobject.cpp index 00faac9b..b0a10806 100644 --- a/src/location/declarativemaps/qgeomapobject.cpp +++ b/src/location/declarativemaps/qgeomapobject.cpp @@ -193,8 +193,10 @@ void QGeoMapObject::setMap(QGeoMap *map) if (map) { bool oldVisible = d_ptr->m_visible; bool oldCmponentCompleted = d_ptr->m_componentCompleted; - if (!map->createMapObjectImplementation(this)) - qWarning() << "Unsupported type " << type(); + if (!map->createMapObjectImplementation(this)) { + if (type() != ViewType) + qWarning() << "Unsupported type " << type(); + } // old implementation gets destroyed if/when d_ptr gets replaced d_ptr->m_componentCompleted = oldCmponentCompleted; d_ptr->setVisible(oldVisible); diff --git a/src/location/labs/qmapobjectview.cpp b/src/location/labs/qmapobjectview.cpp index 8cbf8ded..54d384fb 100644 --- a/src/location/labs/qmapobjectview.cpp +++ b/src/location/labs/qmapobjectview.cpp @@ -339,8 +339,10 @@ void QMapObjectView::modelUpdated(const QQmlChangeSet &changeSet, bool reset) for (int idx = c.start(); idx < c.end(); idx++) { m_instantiatedMapObjects.insert(idx, nullptr); QGeoMapObject *mo = qobject_cast(m_delegateModel->object(idx, incubationMode)); - if (mo) // if not, a createdItem signal will be emitted later, else it has been emitted already while createBlocker is in effect. + if (mo) {// if not, a createdItem signal will be emitted later, else it has been emitted already while createBlocker is in effect. + mo->setParent(this); addMapObjectToMap(mo, idx); + } } } } @@ -395,10 +397,12 @@ void QMapObjectView::createdItem(int index, QObject * /*object*/) // or else, it will be destroyed exiting this scope QGeoMapObject *mo = nullptr; mo = qobject_cast(m_delegateModel->object(index, incubationMode)); - if (mo) + if (mo) { + mo->setParent(this); addMapObjectToMap(mo, index); - else + } else { qWarning() << "QQmlDelegateModel::object called in createdItem for " << index << " produced a null object"; + } } @@ -436,7 +440,11 @@ void QMapObjectView::setMap(QGeoMap *map) // Map was set, now it has ben re-set to NULL flushDelegateModel(); flushUserAddedMapObjects(); + bool oldVisible = d_ptr->m_visible; + bool oldCmponentCompleted = d_ptr->m_componentCompleted; d_ptr = new QMapObjectViewPrivateDefault(*d); + d_ptr->m_componentCompleted = oldCmponentCompleted; + d_ptr->setVisible(oldVisible); } else if (d->m_componentCompleted) { // Map was null, now it's set AND delegateModel is already complete. // some delegates may have been incubated but not added to the map. -- cgit v1.2.1