[Marble-devel] [PATCH 1/3] PlacemarkManager: deal with all Placemarks of a document recursively

Thibaut GRIDEL tgridel at free.fr
Wed Sep 16 22:18:39 CEST 2009


---
 src/lib/PlacemarkManager.cpp |   28 +++++++++++++++++++++++++---
 src/lib/PlacemarkManager.h   |    2 ++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/lib/PlacemarkManager.cpp b/src/lib/PlacemarkManager.cpp
index 19429f5..841c412 100644
--- a/src/lib/PlacemarkManager.cpp
+++ b/src/lib/PlacemarkManager.cpp
@@ -46,6 +46,7 @@ class PlacemarkManagerPrivate
         MarbleDataFacade* m_datafacade;
         FileManager *m_fileManager;
         QVector<GeoDataPlacemark> m_placemarkContainer;
+        QVector<int> m_sizeForDocument;
 };
 }
 
@@ -88,12 +89,14 @@ void PlacemarkManager::addGeoDataDocument( int index )
     if (file)
     {
         const GeoDataDocument &document = *file->document();
-        QVector<GeoDataPlacemark> result = document.placemarks();
+        QVector<GeoDataPlacemark> result = recurseContainer(document);
         if (!result.isEmpty())
         {
             createFilterProperties( result );
             int start = d->m_placemarkContainer.size();
             d->m_placemarkContainer << result;
+            d->m_sizeForDocument.resize(index+1);
+            d->m_sizeForDocument[index] = result.size();
             qDebug() << "PlacemarkManager::addGeoDataDocument:"
                     << document.fileName() << " size " << result.size();
             d->m_datafacade->placemarkModel()->addPlacemarks( start, result.size() );
@@ -112,10 +115,11 @@ void PlacemarkManager::removeGeoDataDocument( int index )
         int start = 0;
         for ( int i = 0; i < index; ++i )
         {
-            start += d->m_fileManager->at(i)->size();
+            start += d->m_sizeForDocument[i];
         }
-        int size = d->m_fileManager->at(index)->size();
+        int size = d->m_sizeForDocument[index];
         d->m_placemarkContainer.remove(start, size);
+        d->m_sizeForDocument.remove(index);
         qDebug() << "PlacemarkManager::removeGeoDataDocument:"
                 << document.fileName() << " size " << size;
         d->m_datafacade->placemarkModel()->removePlacemarks(
@@ -123,6 +127,24 @@ void PlacemarkManager::removeGeoDataDocument( int index )
     }
 }
 
+QVector<GeoDataPlacemark> PlacemarkManager::recurseContainer(GeoDataContainer container)
+{
+    QVector<GeoDataPlacemark> results;
+
+    const QVector<GeoDataFeature> features = container.features();
+    QVector<GeoDataFeature>::const_iterator it = features.constBegin();
+    QVector<GeoDataFeature>::const_iterator end = features.constEnd();
+
+    results += container.placemarks();
+    for (; it != end; ++it) {
+        if ( GeoDataFolderId == it->featureId() ) {
+            const GeoDataContainer *cont = static_cast<const GeoDataContainer*>(it);
+            results += recurseContainer(*cont);
+        }
+    }
+    return results;
+}
+
 void PlacemarkManager::createFilterProperties( QVector<Marble::GeoDataPlacemark> &container )
 {
 
diff --git a/src/lib/PlacemarkManager.h b/src/lib/PlacemarkManager.h
index 4dc0fbe..de5a024 100644
--- a/src/lib/PlacemarkManager.h
+++ b/src/lib/PlacemarkManager.h
@@ -21,6 +21,7 @@ namespace Marble
 {
 
 class FileManager;
+class GeoDataContainer;
 class GeoDataDocument;
 class GeoDataPlacemark;
 class MarblePlacemarkModel;
@@ -76,6 +77,7 @@ public Q_SLOTS:
     void removeGeoDataDocument( int index );
 
  private:
+    QVector<GeoDataPlacemark> recurseContainer(GeoDataContainer container);
     void createFilterProperties( QVector<Marble::GeoDataPlacemark> &container );
     int cityPopIdx( qint64 population ) const;
     int spacePopIdx( qint64 diameter ) const;
-- 
1.6.3.3





More information about the Marble-devel mailing list