summaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap.cpp55
-rw-r--r--src/location/declarativemaps/qdeclarativegeomap_p.h3
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemview.cpp3
-rw-r--r--src/location/declarativemaps/qdeclarativegeomapitemview_p.h1
4 files changed, 60 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}.
diff --git a/src/location/declarativemaps/qdeclarativegeomap_p.h b/src/location/declarativemaps/qdeclarativegeomap_p.h
index f88eb03f..90e73420 100644
--- a/src/location/declarativemaps/qdeclarativegeomap_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomap_p.h
@@ -164,6 +164,9 @@ public:
Q_INVOKABLE void addMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup);
Q_INVOKABLE void removeMapItemGroup(QDeclarativeGeoMapItemGroup *itemGroup);
+ Q_INVOKABLE void removeMapItemView(QDeclarativeGeoMapItemView *itemView);
+ Q_INVOKABLE void addMapItemView(QDeclarativeGeoMapItemView *itemView);
+
Q_INVOKABLE void clearMapItems();
QList<QObject *> mapItems();
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
index a17bf672..d8c19528 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
+++ b/src/location/declarativemaps/qdeclarativegeomapitemview.cpp
@@ -431,6 +431,9 @@ void QDeclarativeGeoMapItemView::instantiateAllItems()
fitViewport();
}
+/*
+ * used internally
+*/
void QDeclarativeGeoMapItemView::removeItemData(QDeclarativeGeoMapItemViewItemData *itemData)
{
if (!itemData)
diff --git a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
index 8c83e37d..8f1a081f 100644
--- a/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
+++ b/src/location/declarativemaps/qdeclarativegeomapitemview_p.h
@@ -141,6 +141,7 @@ private:
int m_readyIncubators;
bool m_repopulating;
+ friend class QDeclarativeGeoMap;
friend class QDeclarativeGeoMapItemViewItemData;
friend class MapItemViewDelegateIncubator;
};