summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2011-07-04 14:05:53 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-08 09:04:32 +0200
commitd4c5941e17c3b726514731fed53e1f7796004bde (patch)
tree9587f285bf2f52cb2986b182d948bc8cc8034386
parentb5eb68b15896147ef6e9a9d5aa5bbaa075f2774c (diff)
Fix mouse event reception for map objects within a group.
Child objects of a MapGroup were not receiving mouse events because they were not being added to the object map. Recursively add and remove child objects to the object map. Change-Id: Ief486674b7dcf034f422711f81f6a3e52c3d1d43 Reviewed-on: http://codereview.qt.nokia.com/1261 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: David Laing <david.laing@nokia.com>
-rw-r--r--src/imports/location/qdeclarativegeomapobject.cpp8
-rw-r--r--src/imports/location/qdeclarativegraphicsgeomap.cpp37
-rw-r--r--src/imports/location/qdeclarativegraphicsgeomap_p.h2
3 files changed, 42 insertions, 5 deletions
diff --git a/src/imports/location/qdeclarativegeomapobject.cpp b/src/imports/location/qdeclarativegeomapobject.cpp
index eb3de35f..b9ca7cce 100644
--- a/src/imports/location/qdeclarativegeomapobject.cpp
+++ b/src/imports/location/qdeclarativegeomapobject.cpp
@@ -42,6 +42,7 @@
#include "qdeclarativegeomapobject_p.h"
#include "qdeclarativegeomapmousearea_p.h"
#include "qdeclarativelandmark_p.h"
+#include "qdeclarativegeomapgroupobject_p.h"
#include "qgeomapdata.h"
#include <QDeclarativeParserStatus>
@@ -345,7 +346,10 @@ void QDeclarativeGeoMapObjectView::removeInstantiatedItems()
if (!mapObjects.isEmpty()) {
for (int i = 0; i < mapObjects.size(); i++) {
group_.removeChildObject(mapObjects.at(i));
- delete map_->objectMap_.take(mapObjects.at(i));
+
+ QDeclarativeGeoMapObject *mapObject = map_->objectMap_.value(mapObjects.at(i));
+ map_->recursiveRemoveFromObjectMap(mapObjects.at(i));
+ delete mapObject;
}
}
declarativeObjectList_.clear();
@@ -373,7 +377,7 @@ void QDeclarativeGeoMapObjectView::repopulate()
mapObject->setMap(map_);
group_.addChildObject(mapObject->mapObject());
// Needed in order for mouse areas to work.
- map_->objectMap_.insert(mapObject->mapObject(), mapObject);
+ map_->recursiveAddToObjectMap(mapObject);
}
}
diff --git a/src/imports/location/qdeclarativegraphicsgeomap.cpp b/src/imports/location/qdeclarativegraphicsgeomap.cpp
index 6c468061..90994398 100644
--- a/src/imports/location/qdeclarativegraphicsgeomap.cpp
+++ b/src/imports/location/qdeclarativegraphicsgeomap.cpp
@@ -45,6 +45,7 @@
#include "qdeclarativecoordinate_p.h"
#include "qdeclarativegeoserviceprovider_p.h"
#include "qdeclarativelandmark_p.h"
+#include "qdeclarativegeomapgroupobject_p.h"
#include <qgeoserviceprovider.h>
#include <qgeomappingmanager.h>
@@ -150,6 +151,36 @@ void QDeclarativeGraphicsGeoMap::componentComplete()
populateMap();
}
+void QDeclarativeGraphicsGeoMap::recursiveAddToObjectMap(QDeclarativeGeoMapObject *mapObject)
+{
+ objectMap_.insert(mapObject->mapObject(), mapObject);
+
+ QDeclarativeGeoMapGroupObject *groupObject =
+ qobject_cast<QDeclarativeGeoMapGroupObject *>(mapObject);
+
+ if (groupObject) {
+ QDeclarativeListReference ref(groupObject, "objects");
+ for (int i = 0; i < ref.count(); ++i) {
+ QDeclarativeGeoMapObject *subObject =
+ qobject_cast<QDeclarativeGeoMapObject *>(ref.at(i));
+
+ if (subObject)
+ recursiveAddToObjectMap(subObject);
+ }
+ }
+}
+
+void QDeclarativeGraphicsGeoMap::recursiveRemoveFromObjectMap(QGeoMapObject *mapObject)
+{
+ objectMap_.remove(mapObject);
+
+ QGeoMapGroupObject *groupObject = qobject_cast<QGeoMapGroupObject *>(mapObject);
+ if (groupObject) {
+ foreach (QGeoMapObject *subObject, groupObject->childObjects())
+ recursiveRemoveFromObjectMap(subObject);
+ }
+}
+
void QDeclarativeGraphicsGeoMap::populateMap()
{
if (!mapData_ || !componentCompleted_)
@@ -166,7 +197,7 @@ void QDeclarativeGraphicsGeoMap::populateMap()
QDeclarativeGeoMapObject *mapObject = qobject_cast<QDeclarativeGeoMapObject*>(kids.at(i));
if (mapObject) {
mapObjects_.append(mapObject);
- objectMap_.insert(mapObject->mapObject(), mapObject);
+ recursiveAddToObjectMap(mapObject);
mapData_->addMapObject(mapObject->mapObject());
mapObject->setMap(this);
continue;
@@ -863,7 +894,7 @@ void QDeclarativeGraphicsGeoMap::addMapObject(QDeclarativeGeoMapObject *object)
if (!mapData_ || !object || objectMap_.contains(object->mapObject()))
return;
mapObjects_.append(object);
- objectMap_.insert(object->mapObject(), object);
+ recursiveAddToObjectMap(object);
mapData_->addMapObject(object->mapObject());
object->setMap(this);
}
@@ -889,7 +920,7 @@ void QDeclarativeGraphicsGeoMap::removeMapObject(QDeclarativeGeoMapObject *objec
qmlInfo(this) << tr("Map plugin is not set, map object cannot be removed.");
if (!mapData_ || !object || !objectMap_.contains(object->mapObject()))
return;
- objectMap_.remove(object->mapObject());
+ recursiveRemoveFromObjectMap(object->mapObject());
mapObjects_.removeOne(object);
mapData_->removeMapObject(object->mapObject());
}
diff --git a/src/imports/location/qdeclarativegraphicsgeomap_p.h b/src/imports/location/qdeclarativegraphicsgeomap_p.h
index c6a701e0..603d8270 100644
--- a/src/imports/location/qdeclarativegraphicsgeomap_p.h
+++ b/src/imports/location/qdeclarativegraphicsgeomap_p.h
@@ -177,6 +177,8 @@ private Q_SLOTS:
private:
void setupMapView(QDeclarativeGeoMapObjectView *view);
void populateMap();
+ void recursiveAddToObjectMap(QDeclarativeGeoMapObject *mapObject);
+ void recursiveRemoveFromObjectMap(QGeoMapObject *mapObject);
QDeclarativeGeoMapObject* createItem(int modelIndex);
QDeclarativeGeoMapMouseEvent* createMapMouseEvent(QGraphicsSceneMouseEvent *event);