From d4c5941e17c3b726514731fed53e1f7796004bde Mon Sep 17 00:00:00 2001 From: Aaron McCarthy Date: Mon, 4 Jul 2011 14:05:53 +1000 Subject: 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 Reviewed-by: David Laing --- src/imports/location/qdeclarativegeomapobject.cpp | 8 +++-- .../location/qdeclarativegraphicsgeomap.cpp | 37 ++++++++++++++++++++-- .../location/qdeclarativegraphicsgeomap_p.h | 2 ++ 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 @@ -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 #include @@ -150,6 +151,36 @@ void QDeclarativeGraphicsGeoMap::componentComplete() populateMap(); } +void QDeclarativeGraphicsGeoMap::recursiveAddToObjectMap(QDeclarativeGeoMapObject *mapObject) +{ + objectMap_.insert(mapObject->mapObject(), mapObject); + + QDeclarativeGeoMapGroupObject *groupObject = + qobject_cast(mapObject); + + if (groupObject) { + QDeclarativeListReference ref(groupObject, "objects"); + for (int i = 0; i < ref.count(); ++i) { + QDeclarativeGeoMapObject *subObject = + qobject_cast(ref.at(i)); + + if (subObject) + recursiveAddToObjectMap(subObject); + } + } +} + +void QDeclarativeGraphicsGeoMap::recursiveRemoveFromObjectMap(QGeoMapObject *mapObject) +{ + objectMap_.remove(mapObject); + + QGeoMapGroupObject *groupObject = qobject_cast(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(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); -- cgit v1.2.3