[Marble-commits] KDE/kdeedu/marble/src/lib

Thibaut Gridel tgridel at free.fr
Thu Aug 5 00:26:02 CEST 2010


SVN commit 1159264 by tgridel:

MarbleModel: on theme change, detect the previous theme's geodata files
and close them if they are not used in the new one.

 M  +1 -1      FileManager.cpp  
 M  +8 -8      KmlFileViewItem.cpp  
 M  +2 -5      KmlFileViewItem.h  
 M  +33 -7     MarbleModel.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/FileManager.cpp #1159263:1159264
@@ -174,7 +174,7 @@
 
 void FileManager::addGeoDataDocument( GeoDataDocument* document )
 {
-    KmlFileViewItem* item = new KmlFileViewItem( *document );
+    KmlFileViewItem* item = new KmlFileViewItem( document );
     addFile( item );
 
     // now get the document that will be preserved throughout the life time
--- trunk/KDE/kdeedu/marble/src/lib/KmlFileViewItem.cpp #1159263:1159264
@@ -15,7 +15,7 @@
 
 using namespace Marble;
 
-KmlFileViewItem::KmlFileViewItem( const GeoDataDocument &document ) :
+KmlFileViewItem::KmlFileViewItem( GeoDataDocument *document ) :
     m_document( document )
 {
 }
@@ -32,25 +32,25 @@
 
 GeoDataDocument* KmlFileViewItem::document()
 {
-    return &m_document;
+    return m_document;
 }
 
 bool KmlFileViewItem::isShown() const
 {
-    return m_document.isVisible();
+    return m_document->isVisible();
 }
 
 void KmlFileViewItem::setShown( bool value )
 {
-    m_document.setVisible( value );
+    m_document->setVisible( value );
 }
 
 QString KmlFileViewItem::name() const
 {
-    if(!m_document.name().isEmpty())
-        return m_document.name();
-    else if(!m_document.fileName().isEmpty())
-        return m_document.fileName();
+    if(!m_document->name().isEmpty())
+        return m_document->name();
+    else if(!m_document->fileName().isEmpty())
+        return m_document->fileName();
     else
         return QString("KML Document");
 
--- trunk/KDE/kdeedu/marble/src/lib/KmlFileViewItem.h #1159263:1159264
@@ -21,12 +21,9 @@
 class KmlFileViewItem
 {
   public:
-    KmlFileViewItem( const GeoDataDocument &document );
+    KmlFileViewItem( GeoDataDocument *document );
     ~KmlFileViewItem();
 
-    /*
-     * AbstractFileViewItem methods
-     */
     void saveFile();
     bool isShown() const;
     void setShown( bool value );
@@ -34,7 +31,7 @@
 
     GeoDataDocument* document();
   private:
-    GeoDataDocument    m_document;
+    GeoDataDocument    *m_document;
 };
 
 }
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1159263:1159264
@@ -304,6 +304,7 @@
 void MarbleModel::setMapTheme( GeoSceneDocument* mapTheme,
                                Projection currentProjection )
 {
+    GeoSceneDocument *oldTheme = d->m_mapTheme;
     d->m_mapTheme = mapTheme;
     addDownloadPolicies( d->m_mapTheme );
     d->m_tileLoader->setTextureLayerSettings( d->textureLayerProperties() );
@@ -410,11 +411,36 @@
             }
         }
     }
-    QStringList loadedContainers = d->m_fileManager->containers();
+
+    // find the list of previous theme's geodata
+    QStringList loadedContainers;
+    QVector<GeoSceneLayer*>::const_iterator it;
+    QVector<GeoSceneLayer*>::const_iterator end;
+    if (oldTheme) {
+        it = oldTheme->map()->layers().constBegin();
+        end = oldTheme->map()->layers().constEnd();
+        for (; it != end; ++it) {
+            GeoSceneLayer* layer = *it;
+            if ( layer->backend() == dgml::dgmlValue_geodata && layer->datasets().count() > 0 ) {
+                // look for documents
+                const QVector<GeoSceneAbstractDataset*> & datasets = layer->datasets();
+                QVector<GeoSceneAbstractDataset*>::const_iterator itds = datasets.constBegin();
+                QVector<GeoSceneAbstractDataset*>::const_iterator endds = datasets.constEnd();
+                for (; itds != endds; ++itds) {
+                    GeoSceneAbstractDataset* dataset = *itds;
+                    if( dataset->fileFormat() == "KML" ) {
+                        QString containername = reinterpret_cast<GeoSceneXmlDataSource*>(dataset)->filename();
+                        if( containername.endsWith(".kml") ) containername.remove(".kml");
+                        loadedContainers <<  containername;
+                    }
+                }
+            }
+        }
+    }
     QStringList loadList;
     const QVector<GeoSceneLayer*> & layers = d->m_mapTheme->map()->layers();
-    QVector<GeoSceneLayer*>::const_iterator it = layers.constBegin();
-    QVector<GeoSceneLayer*>::const_iterator end = layers.constEnd();
+    it = layers.constBegin();
+    end = layers.constEnd();
     for (; it != end; ++it) {
         GeoSceneLayer* layer = *it;
         if ( layer->backend() == dgml::dgmlValue_geodata && layer->datasets().count() > 0 ) {
@@ -434,10 +460,10 @@
         }
     }
     // unload old standard Placemarks which are not part of the new map
-//    foreach(const QString& container, loadedContainers) {
-//        loadedContainers.pop_front();
-//        d->m_fileManager->removeFile( container );
-//    }
+    foreach(const QString& container, loadedContainers) {
+        loadedContainers.pop_front();
+        d->m_fileManager->removeFile( container );
+    }
     // load new standard Placemarks
     foreach(const QString& container, loadList) {
         loadList.pop_front();


More information about the Marble-commits mailing list