summaryrefslogtreecommitdiff
path: root/src/location/declarativemaps/qdeclarativegeomap.cpp
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-06-09 15:56:41 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-08-07 07:49:18 +0000
commitc6d41bdb24dbfcd846ca2669cee7b83be3e7be0a (patch)
treee5ba8b752d1ed509bf14573245675fc32a8ee557 /src/location/declarativemaps/qdeclarativegeomap.cpp
parent92d8e4dc93400250b47f8dbe96ec7e2f748d8d4b (diff)
downloadqtlocation-c6d41bdb24dbfcd846ca2669cee7b83be3e7be0a.tar.gz
Add invokables to add/remove mapItemViews
This patch adds two new methods to QDeclarativeGeoMap, to allow users to add or remove MapItemViews at runtime. [ChangeLog][QtLocation][Map] Added methods to add or remove MapItemViews at runtime. Task-number: QTBUG-55782 Change-Id: I4e612a9476a864331f61d49dac811a8069ae010f Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeomap.cpp')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp
index 67130bb9..19bc57ce 100644
--- a/src/location/declarativemaps/qdeclarativegeomap.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomap.cpp
@@ -222,8 +222,18 @@ QDeclarativeGeoMap::~QDeclarativeGeoMap()
m_map->clearMapItems();
}
- if (!m_mapViews.isEmpty())
- qDeleteAll(m_mapViews);
+ // This forces the destruction of the associated items now, not when QObject destructor is called, at which point
+ // QDeclarativeGeoMap is long gone
+ if (!m_mapViews.isEmpty()) {
+ for (QDeclarativeGeoMapItemView *v : qAsConst(m_mapViews)) {
+ if (!v)
+ continue;
+ if (v->parent() == this)
+ delete v;
+ else
+ v->removeInstantiatedItems();
+ }
+ }
// remove any map items associations
for (int i = 0; i < m_mapItems.count(); ++i) {
if (m_mapItems.at(i))
@@ -1953,6 +1963,47 @@ void QDeclarativeGeoMap::removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGro
}
/*!
+ \qmlmethod void QtLocation::Map::removeMapItemView(MapItemView itemView)
+
+ Removes \a itemView and the items instantiated by it from the Map.
+
+ \sa MapItemView, addMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::removeMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_ != this) // can't remove a view that is already added to another map
+ return;
+
+ itemView->removeInstantiatedItems();
+ itemView->map_ = 0;
+ // it can be removed from the list at this point, since no operations that require a Map have to be done
+ // anymore on destruction.
+ m_mapViews.removeOne(itemView);
+}
+
+/*!
+ \qmlmethod void QtLocation::Map::addMapItemView(MapItemView itemView)
+
+ Adds \a itemView to the Map.
+
+ \sa MapItemView, removeMapItemView
+
+ \since 5.10
+*/
+void QDeclarativeGeoMap::addMapItemView(QDeclarativeGeoMapItemView *itemView)
+{
+ if (!itemView || itemView->map_) // can't add a view twice
+ return;
+
+ // Not appending it to m_mapViews because it seems unnecessary even if the
+ // itemView is a child of this (in which case it would be destroyed
+ m_mapViews.append(itemView);
+ setupMapView(itemView);
+}
+
+/*!
\qmlproperty MapType QtLocation::Map::activeMapType
\brief Access to the currently active \l{MapType}{map type}.