void QDeclarativeGraphicsGeoMap::populateMap() { if (!mapData_ || !componentCompleted_) return; QObjectList kids = children(); for (int i = 0; i < kids.size(); ++i) { // dispatch items appropriately QDeclarativeGeoMapObjectView* mapView = qobject_cast<QDeclarativeGeoMapObjectView*>(kids.at(i)); if (mapView) { mapViews_.append(mapView); setupMapView(mapView); continue; } QDeclarativeGeoMapObject *mapObject = qobject_cast<QDeclarativeGeoMapObject*>(kids.at(i)); if (mapObject) { mapObjects_.append(mapObject); objectMap_.insert(mapObject->mapObject(), mapObject); mapData_->addMapObject(mapObject->mapObject()); mapObject->setMap(this); continue; } QDeclarativeGeoMapMouseArea *mouseArea = qobject_cast<QDeclarativeGeoMapMouseArea*>(kids.at(i)); if (mouseArea) { mouseArea->setMap(this); mouseAreas_.append(mouseArea); } } }
void QDeclarativeGeoMapObjectView::modelRowsRemoved(QModelIndex, int start, int end) { if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) return; Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); for (int i = end; i >= start; --i) { QDeclarativeGeoMapObject *object = declarativeObjectList_.takeAt(i); if (!object) // bad break; group_.removeChildObject(object->mapObject()); map_->objectMap_.remove(object->mapObject()); delete object; } Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); }
void QDeclarativeGeoMapObjectView::modelRowsInserted(QModelIndex, int start, int end) { if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) return; Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); QDeclarativeGeoMapObject* mapObject; for (int i = start; i <= end; ++i) { mapObject = createItem(i); if (!mapObject) { break; } declarativeObjectList_.append(mapObject); mapObject->setVisible(visible_); mapObject->setMap(map_); group_.addChildObject(mapObject->mapObject()); // Needed in order for mouse areas to work. map_->objectMap_.insert(mapObject->mapObject(), mapObject); } Q_ASSERT(declarativeObjectList_.count() == group_.childObjects().count()); }
void QDeclarativeGeoMapGroupObject::componentComplete() { QList<QGraphicsItem*> children = childItems(); for (int i = 0; i < children.size(); ++i) { QDeclarativeGeoMapObject *mapObject = qobject_cast<QDeclarativeGeoMapObject*>(children.at(i)); if (mapObject) { group_->addChildObject(mapObject->mapObject()); objects_.append(mapObject); mapObject->setMap(map()); } } QDeclarativeGeoMapObject::componentComplete(); }
// Removes and repopulates all items. void QDeclarativeGeoMapObjectView::repopulate() { if (!componentCompleted_ || !map_ || !map_->mapData_ || !delegate_ || !model_) return; // Free any earlier instances removeInstantiatedItems(); // Iterate model data and instantiate delegates. // We could use more specialized landmark model calls here too, // but hopefully the support will be leveraged to a general model // level. QDeclarativeGeoMapObject* mapObject; for (int i = 0; i < model_->rowCount(); ++i) { mapObject = createItem(i); if (!mapObject) break; declarativeObjectList_.append(mapObject); mapObject->setVisible(visible_); mapObject->setMap(map_); group_.addChildObject(mapObject->mapObject()); // Needed in order for mouse areas to work. map_->recursiveAddToObjectMap(mapObject); } }