[Marble-devel] [PATCH 3/3] FileLoader: Save recursive Placemarks in .cache file

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


---
 src/lib/FileLoader.cpp       |   37 ++++++++++++++++++++++++++++---------
 src/lib/FileLoader.h         |    3 ++-
 src/lib/PlacemarkManager.cpp |    3 ++-
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/lib/FileLoader.cpp b/src/lib/FileLoader.cpp
index b04c5bc..620c6dc 100644
--- a/src/lib/FileLoader.cpp
+++ b/src/lib/FileLoader.cpp
@@ -19,6 +19,7 @@
 
 #include "GeoDataParser.h"
 #include "GeoDataDocument.h"
+#include "GeoDataFolder.h"
 #include "GeoDataPlacemark.h"
 #include "MarbleDirs.h"
 
@@ -274,24 +275,42 @@ void FileLoader::saveFile( const QString& filename )
 
     out.setVersion( QDataStream::Qt_4_2 );
 
+    savePlacemarks(out, m_document);
+}
+
+void FileLoader::savePlacemarks(QDataStream &out, const GeoDataContainer *container)
+{
     qreal lon;
     qreal lat;
     qreal alt;
 
-    QVector<Marble::GeoDataPlacemark>::const_iterator it = m_document->placemarks().constBegin();
-    QVector<Marble::GeoDataPlacemark>::const_iterator const end = m_document->placemarks().constEnd();
+    const QVector<GeoDataPlacemark> placemarks = container->placemarks();
+    QVector<Marble::GeoDataPlacemark>::const_iterator it = placemarks.constBegin();
+    QVector<Marble::GeoDataPlacemark>::const_iterator const end = placemarks.constEnd();
     for (; it != end; ++it )
     {
-        out << (*it).name();
-        (it)->coordinate( lon, lat, alt );
+        out << it->name();
+        it->coordinate( lon, lat, alt );
 
         // Use double to provide a single cache file format across architectures
         out << (double)(lon) << (double)(lat) << (double)(alt);
-        out << QString( (*it).role() );
-        out << QString( (*it).description() );
-        out << QString( (*it).countryCode() );
-        out << (double)(*it).area();
-        out << (qint64)(*it).population();
+        out << QString( it->role() );
+        out << QString( it->description() );
+        out << QString( it->countryCode() );
+        out << (double) it->area();
+        out << (qint64) it->population();
+    }
+
+    const QVector<GeoDataFolder> folders = container->folders();
+    QVector<GeoDataFolder>::const_iterator cont = folders.constBegin();
+    QVector<GeoDataFolder>::const_iterator endcont = folders.constEnd();
+    for (; cont != endcont; ++cont )
+    {
+        if (GeoDataFolderId == cont->featureId() )
+        {
+            const GeoDataContainer *subcontainer = static_cast<const GeoDataContainer*>(cont);
+            savePlacemarks(out, subcontainer);
+        }
     }
 }
 
diff --git a/src/lib/FileLoader.h b/src/lib/FileLoader.h
index c74e608..9218ad7 100644
--- a/src/lib/FileLoader.h
+++ b/src/lib/FileLoader.h
@@ -15,7 +15,7 @@
 
 namespace Marble
 {
-
+class GeoDataContainer;
 class GeoDataDocument;
 
 class FileLoader : public QThread
@@ -37,6 +37,7 @@ class FileLoader : public QThread
         void importKmlFromData();
         bool loadFile(const QString &filename );
         void saveFile(const QString& filename );
+        void savePlacemarks(QDataStream &out, const GeoDataContainer *container);
 
         QString m_filepath;
         QString m_contents;
diff --git a/src/lib/PlacemarkManager.cpp b/src/lib/PlacemarkManager.cpp
index 841c412..1389f65 100644
--- a/src/lib/PlacemarkManager.cpp
+++ b/src/lib/PlacemarkManager.cpp
@@ -119,7 +119,8 @@ void PlacemarkManager::removeGeoDataDocument( int index )
         }
         int size = d->m_sizeForDocument[index];
         d->m_placemarkContainer.remove(start, size);
-        d->m_sizeForDocument.remove(index);
+        if (d->m_sizeForDocument.size() > index)
+            d->m_sizeForDocument.remove(index);
         qDebug() << "PlacemarkManager::removeGeoDataDocument:"
                 << document.fileName() << " size " << size;
         d->m_datafacade->placemarkModel()->removePlacemarks(
-- 
1.6.3.3





More information about the Marble-devel mailing list