[Marble-devel] [PATCH 3/8] Turn file loading responsibility to FileManager

Thibaut GRIDEL tgridel at free.fr
Tue Sep 1 23:24:31 CEST 2009


That deletes PlacemarkLoader as well and cleans PlacemarkManager

 12 files changed, 60 insertions(+), 640 deletions(-)

diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 1a9ab6b..c559e0d 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -103,7 +103,6 @@ set(marblewidget_SRCS
     VisiblePlacemark.cpp
     PlacemarkManager.cpp
     PlacemarkLayout.cpp
-    PlacemarkLoader.cpp
     PlacemarkPainter.cpp
     PlacemarkInfoDialog.cpp
     Planet.cpp
diff --git a/src/lib/FileManager.cpp b/src/lib/FileManager.cpp
index 0b70218..9b64d68 100644
--- a/src/lib/FileManager.cpp
+++ b/src/lib/FileManager.cpp
@@ -69,7 +69,7 @@ FileManager::~FileManager()
 void FileManager::setDataFacade( MarbleDataFacade *facade )
 {
     d->m_datafacade = facade;
-//    d->m_datafacade->fileViewModel()->setFileManager(this);
+    d->m_datafacade->fileViewModel()->setFileManager(this);
 }
 
 MarbleDataFacade *FileManager::dataFacade()
@@ -173,29 +173,28 @@ AbstractFileViewItem * FileManager::at( int index )
 
 void FileManager::addGeoDataDocument( GeoDataDocument* document )
 {
-    Q_UNUSED( document );
-//    KmlFileViewItem* item = new KmlFileViewItem( *this, *document );
-//    addFile( item );
-//
-//    // now get the document that will be preserved throughout the life time
-//    GeoDataDocument* doc = item->document();
-//    // remove the hashes in front of the styles.
-//    QVector<GeoDataFeature>::Iterator end = doc->end();
-//    QVector<GeoDataFeature>::Iterator itr = doc->begin();
-//    for ( ; itr != end; ++itr ) {
-//        // use *itr (or itr.value()) here
-//        QString styleUrl = itr->styleUrl().remove('#');
-//        itr->setStyle( &doc->style( styleUrl ) );
-//    }
-//
-//    // do not set this file if it only contains points
-//    if( doc->isVisible() && d->m_datafacade->geometryModel() )
-//        d->m_datafacade->geometryModel()->setGeoDataRoot( doc );
-//    emit geoDataDocumentAdded( *doc );
-//
-//    if( d->m_loaderList.isEmpty() ) {
-//        emit finalize();
-//    }
+    KmlFileViewItem* item = new KmlFileViewItem( *this, *document );
+    addFile( item );
+
+    // now get the document that will be preserved throughout the life time
+    GeoDataDocument* doc = item->document();
+    // remove the hashes in front of the styles.
+    QVector<GeoDataFeature>::Iterator end = doc->end();
+    QVector<GeoDataFeature>::Iterator itr = doc->begin();
+    for ( ; itr != end; ++itr ) {
+        // use *itr (or itr.value()) here
+        QString styleUrl = itr->styleUrl().remove('#');
+        itr->setStyle( &doc->style( styleUrl ) );
+    }
+
+    // do not set this file if it only contains points
+    if( doc->isVisible() && d->m_datafacade->geometryModel() )
+        d->m_datafacade->geometryModel()->setGeoDataRoot( doc );
+    emit geoDataDocumentAdded( *doc );
+
+    if( d->m_loaderList.isEmpty() ) {
+        emit finalize();
+    }
 }
 
 void FileManager::cleanupLoader( FileLoader* loader )
diff --git a/src/lib/FileManager.h b/src/lib/FileManager.h
index 2b86f37..b4d862a 100644
--- a/src/lib/FileManager.h
+++ b/src/lib/FileManager.h
@@ -88,7 +88,7 @@ class FileManager : public QObject
 
 
  Q_SIGNALS:
-    void geoDataDocumentAdded( GeoDataDocument &document );
+    void geoDataDocumentAdded( const GeoDataDocument &document );
     void fileAdded( int index );
     void fileRemoved( int index );
     void finalize();
diff --git a/src/lib/FileViewModel.cpp b/src/lib/FileViewModel.cpp
index 0c211f0..0ca10b3 100644
--- a/src/lib/FileViewModel.cpp
+++ b/src/lib/FileViewModel.cpp
@@ -111,9 +111,9 @@ void FileViewModel::closeFile()
         m_manager->closeFile( m_selectionModel->selectedRows().first().row() );
     }
 }
-void FileViewModel::setPlacemarkManager( PlacemarkManager *placemarkManager)
+void FileViewModel::setFileManager( FileManager *fileManager)
 {
-    m_manager = placemarkManager;
+    m_manager = fileManager;
     connect (m_manager, SIGNAL(fileAdded(int)),
              this, SLOT(append(int)));
     connect (m_manager, SIGNAL(fileRemoved(int)),
diff --git a/src/lib/FileViewModel.h b/src/lib/FileViewModel.h
index 2f2433d..200d71c 100644
--- a/src/lib/FileViewModel.h
+++ b/src/lib/FileViewModel.h
@@ -19,7 +19,7 @@
 
 #include "marble_export.h"
 
-#include "PlacemarkManager.h"
+#include "FileManager.h"
 
 namespace Marble
 {
@@ -39,7 +39,7 @@ class MARBLE_EXPORT FileViewModel : public QAbstractListModel
     virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
     virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
 
-    void setPlacemarkManager( PlacemarkManager * placemarkManager );
+    void setFileManager( FileManager * fileManager );
     QItemSelectionModel * selectionModel();
 
   Q_SIGNALS:
@@ -54,7 +54,7 @@ class MARBLE_EXPORT FileViewModel : public QAbstractListModel
   private:
     Q_DISABLE_COPY( FileViewModel )
     QItemSelectionModel *m_selectionModel;
-    PlacemarkManager *m_manager;
+    FileManager *m_manager;
     
 };
 
diff --git a/src/lib/KmlFileViewItem.cpp b/src/lib/KmlFileViewItem.cpp
index a6cdea8..6d75771 100644
--- a/src/lib/KmlFileViewItem.cpp
+++ b/src/lib/KmlFileViewItem.cpp
@@ -12,15 +12,17 @@
 #include "KmlFileViewItem.h"
 #include "GeoDataDocument.h"    // In geodata/data/
 #include "GeoDataPlacemark.h"
-#include "PlacemarkManager.h"
+#include "FileManager.h"
+#include "MarbleDataFacade.h"
 #include "MarblePlacemarkModel.h"
+#include "MarbleGeometryModel.h"
 
 #include <QtCore/QDebug>
 
 using namespace Marble;
 
-KmlFileViewItem::KmlFileViewItem( PlacemarkManager& manager, const GeoDataDocument& document ) :
-    m_placemarkManager( manager ),
+KmlFileViewItem::KmlFileViewItem( FileManager& manager, const GeoDataDocument& document ) :
+    m_fileManager( manager ),
     m_document( document )
 {
 }
@@ -43,7 +45,7 @@ GeoDataDocument* KmlFileViewItem::document()
 void KmlFileViewItem::closeFile( int start, bool finalize )
 {
     qDebug() << "closing file" << m_document.name() << m_document.fileName();
-    m_placemarkManager.model()->removePlacemarks( m_document.fileName(), start, size(), finalize );
+    m_fileManager.dataFacade()->placemarkModel()->removePlacemarks( m_document.fileName(), start, size(), finalize );
 }
 
 int KmlFileViewItem::size() const
diff --git a/src/lib/KmlFileViewItem.h b/src/lib/KmlFileViewItem.h
index d8e41a0..505c698 100644
--- a/src/lib/KmlFileViewItem.h
+++ b/src/lib/KmlFileViewItem.h
@@ -19,12 +19,12 @@
 namespace Marble
 {
 
-class PlacemarkManager;
+class FileManager;
 
 class KmlFileViewItem : public AbstractFileViewItem
 {
   public:
-    KmlFileViewItem( PlacemarkManager& manager, const GeoDataDocument& document );
+    KmlFileViewItem( FileManager &manager, const GeoDataDocument& document );
     ~KmlFileViewItem();
 
     /*
@@ -39,7 +39,7 @@ class KmlFileViewItem : public AbstractFileViewItem
 
     GeoDataDocument* document();
   private:
-    PlacemarkManager&   m_placemarkManager;
+    FileManager  &m_fileManager;
     GeoDataDocument    m_document;
 };
 
diff --git a/src/lib/MarbleModel.cpp b/src/lib/MarbleModel.cpp
index 057eaec..3c9336b 100644
--- a/src/lib/MarbleModel.cpp
+++ b/src/lib/MarbleModel.cpp
@@ -172,8 +172,10 @@ MarbleModel::MarbleModel( QObject *parent )
     d->m_placemarkmanager = new PlacemarkManager();
     d->m_placemarkmanager->setDataFacade(d->m_dataFacade);
 
-    connect( d->m_placemarkmanager, SIGNAL( geoDataDocumentAdded( const GeoDataDocument& ) ),
-             this,                  SLOT( geoDataDocumentAdded( const GeoDataDocument& ) ) );
+    connect( d->m_fileManager, SIGNAL( geoDataDocumentAdded( const GeoDataDocument & ) ),
+             d->m_placemarkmanager, SLOT(addGeoDataDocument(const GeoDataDocument & )) );
+    connect( d->m_fileManager, SIGNAL( geoDataDocumentAdded( const GeoDataDocument& ) ),
+             this,             SLOT( geoDataDocumentAdded( const GeoDataDocument& ) ) );
 
     d->m_popSortModel = new QSortFilterProxyModel( this );
 
@@ -186,7 +188,7 @@ MarbleModel::MarbleModel( QObject *parent )
     d->m_placemarkselectionmodel = new QItemSelectionModel( d->m_popSortModel );
 
     d->m_placemarkLayout = new PlacemarkLayout( this );
-    connect( d->m_placemarkmanager,         SIGNAL( finalize() ),
+    connect( d->m_fileManager,              SIGNAL( finalize() ),
              d->m_placemarkLayout,          SLOT( requestStyleReset() ) );
     connect( d->m_placemarkselectionmodel,  SIGNAL( selectionChanged( QItemSelection,
                                                                       QItemSelection) ),
@@ -416,7 +418,7 @@ void MarbleModel::setMapTheme( GeoSceneDocument* mapTheme,
         }
     }
     d->m_dataFacade->geometryModel()->setGeoDataRoot( 0 );
-    QStringList loadedContainers = d->m_placemarkmanager->containers();
+    QStringList loadedContainers = d->m_fileManager->containers();
     QStringList loadList;
     const QVector<GeoSceneLayer*> & layers = d->m_mapTheme->map()->layers();
     QVector<GeoSceneLayer*>::const_iterator it = layers.constBegin();
@@ -442,12 +444,12 @@ void MarbleModel::setMapTheme( GeoSceneDocument* mapTheme,
     // unload old standard Placemarks which are not part of the new map
     foreach(const QString& container, loadedContainers) {
         loadedContainers.pop_front();
-        d->m_placemarkmanager->removePlacemarkKey( container );
+        d->m_fileManager->removeFile( container );
     }
     // load new standard Placemarks
     foreach(const QString& container, loadList) {
         loadList.pop_front();
-        d->m_placemarkmanager->addPlacemarkFile( container );
+        d->m_fileManager->addFile( container );
     }
     d->notifyModelChanged();
     d->m_placemarkLayout->requestStyleReset();
@@ -705,27 +707,27 @@ void MarbleModel::openGpxFile( const QString& filename )
     GpxFile* gpxFile = new GpxFile( filename );
     GpxFileViewItem* item = new GpxFileViewItem( gpxFile );
 
-    d->m_placemarkmanager->addFile( item );
+    d->m_fileManager->addFile( item );
     d->m_gpxFileModel->addFile( gpxFile );
 }
 
 void MarbleModel::addPlacemarkFile( const QString& filename )
 {
-    d->m_placemarkmanager->addPlacemarkFile( filename );
+    d->m_fileManager->addFile( filename );
 
     d->notifyModelChanged();
 }
 
 void MarbleModel::addPlacemarkData( const QString& data, const QString& key )
 {
-    d->m_placemarkmanager->addPlacemarkData( data, key );
+    d->m_fileManager->addData( key, data );
 
     d->notifyModelChanged();
 }
 
-void MarbleModel::removePlacemarkKey( const QString& key )
+void MarbleModel::removePlacemarkKey( const QString& fileName )
 {
-    d->m_placemarkmanager->removePlacemarkKey( key );
+    d->m_fileManager->removeFile( fileName );
 
     d->notifyModelChanged();
 }
diff --git a/src/lib/PlacemarkLoader.cpp b/src/lib/PlacemarkLoader.cpp
deleted file mode 100644
index 69aaade..0000000
--- a/src/lib/PlacemarkLoader.cpp
+++ /dev/null
@@ -1,319 +0,0 @@
-//
-// This file is part of the Marble Desktop Globe.
-//
-// This program is free software licensed under the GNU LGPL. You can
-// find a copy of this license in LICENSE.txt in the top directory of
-// the source code.
-//
-// Copyright 2008      Patrick Spendrin <ps_ml at gmx.de>
-//
-
-#include "PlacemarkLoader.h"
-
-#include <QtCore/QBuffer>
-#include <QtCore/QDataStream>
-#include <QtCore/QDateTime>
-#include <QtCore/QDebug>
-#include <QtCore/QFile>
-#include <QtCore/QThread>
-
-#include "GeoDataParser.h"
-#include "GeoSceneDocument.h"
-#include "GeoDataDocument.h"
-#include "GeoDataPlacemark.h"
-#include "MarbleDirs.h"
-#include "MarblePlacemarkModel.h"
-
-
-namespace Marble
-{
-
-PlacemarkLoader::PlacemarkLoader( QObject* parent, const QString& file )
-    : QThread( parent ), 
-      m_filepath( file ),
-      m_contents( QString() ),
-      m_document( 0 ),
-      m_container( 0 )
-{
-}
-
-PlacemarkLoader::PlacemarkLoader( QObject* parent, const QString& contents, const QString& file )
-    : QThread( parent ), 
-      m_filepath( file ), 
-      m_contents( contents ),
-      m_document( 0 ),
-      m_container( 0 )
-{
-}
-
-PlacemarkLoader::~PlacemarkLoader()
-{
-    delete m_container;
-    delete m_document;
-}
-
-QString PlacemarkLoader::path() const
-{
-    return m_filepath;
-}
-
-void PlacemarkLoader::run()
-{
-    if( m_contents.isEmpty() ) {
-        QString defaultcachename;
-        QString defaultsrcname;
-        QString defaulthomecache;
-
-        m_container = new QVector<Marble::GeoDataPlacemark>;
-    
-        if( m_filepath.endsWith(".kml") ) {
-            m_filepath.remove(QRegExp("\\.kml$"));
-        }
-        qDebug() << "starting parser for" << m_filepath;
-
-        QFileInfo fileinfo(m_filepath);
-        if ( fileinfo.isAbsolute() ) {
-            // We got an _absolute_ path now: e.g. "/patrick.kml"
-            defaultcachename = m_filepath + ".cache";
-            defaultsrcname   = m_filepath + ".kml";
-        }
-        else {
-            if ( m_filepath.contains( '/' ) ) {
-                // _relative_ path: "maps/mars/viking/patrick.kml" 
-                defaultcachename = MarbleDirs::path( m_filepath + ".cache" );
-                defaultsrcname   = MarbleDirs::path( m_filepath + ".kml");
-                defaulthomecache = MarbleDirs::localPath() + m_filepath + ".cache";
-            }
-            else {
-                // _standard_ shared placemarks: "placemarks/patrick.kml"
-                defaultcachename = MarbleDirs::path( "placemarks/" + m_filepath + ".cache" );
-                defaultsrcname   = MarbleDirs::path( "placemarks/" + m_filepath + ".kml");
-                defaulthomecache = MarbleDirs::localPath() + "/placemarks/" + m_filepath + ".cache";
-            }
-        }
-
-        if ( QFile::exists( defaultcachename ) ) {
-            qDebug() << "Loading Default Placemark Cache File:" + defaultcachename;
-
-            bool      cacheoutdated = false;
-            QDateTime sourceLastModified;
-            QDateTime cacheLastModified;
-
-            if ( QFile::exists( defaultsrcname ) ) {
-                sourceLastModified = QFileInfo( defaultsrcname ).lastModified();
-                cacheLastModified  = QFileInfo( defaultcachename ).lastModified();
-
-                if ( cacheLastModified < sourceLastModified )
-                    cacheoutdated = true;
-            }
-
-            bool loadok = false;
-
-            if ( !cacheoutdated ) {
-                loadok = loadFile( defaultcachename );
-                if ( loadok )
-                    emit placemarksLoaded( this, m_container );
-            }
-            qDebug() << "Loading ended" << loadok;
-            if ( loadok ) {
-                qDebug() << "placemarksLoaded";
-                return;
-            }
-        }
-
-        qDebug() << "No recent Default Placemark Cache File available for " << m_filepath;
-
-        if ( QFile::exists( defaultsrcname ) ) {
-
-            // Read the KML file.
-            importKml( defaultsrcname );
-
-            qDebug() << "ContainerSize for" << m_filepath << ":" << m_container->size();
-            // Save the contents in the efficient cache format.
-            saveFile( defaulthomecache );
-
-            qDebug() << "placemarksLoaded";
-
-            // ...and finally add it to the PlacemarkContainer
-            emit placemarksLoaded( this, m_container );
-        }
-        else {
-            qDebug() << "No Default Placemark Source File for " << m_filepath;
-            emit placemarkLoaderFailed( this );
-        }
-    } else {
-        m_container = new QVector<Marble::GeoDataPlacemark>;
-
-        // Read the KML Data
-        importKmlFromData();
-
-        emit placemarksLoaded( this, m_container );
-    }
-}
-
-const quint32 MarbleMagicNumber = 0x31415926;
-
-void PlacemarkLoader::importKml( const QString& filename )
-{
-    GeoDataParser parser( GeoData_KML );
-
-    QFile file( filename );
-    if ( !file.exists() ) {
-        qWarning( "File does not exist!" );
-        return;
-    }
-
-    // Open file in right mode
-    file.open( QIODevice::ReadOnly );
-
-    if ( !parser.read( &file ) ) {
-        qWarning( "Could not parse file!" );
-        return;
-    }
-    GeoDocument* document = parser.releaseDocument();
-    Q_ASSERT( document );
-
-    m_document = static_cast<GeoDataDocument*>( document );
-    m_document->setFileName( m_filepath );
-
-    file.close();
-
-    qDebug() << "newGeoDataDocumentAdded" << m_filepath;
-
-    emit newGeoDataDocumentAdded( m_document );
-}
-
-void PlacemarkLoader::importKmlFromData()
-{
-    GeoDataParser parser( GeoData_KML );
-
-    QByteArray ba( m_contents.toUtf8() );
-    QBuffer buffer( &ba );
-    buffer.open( QIODevice::ReadOnly );
-
-    if ( !parser.read( &buffer ) ) {
-        qWarning( "Could not parse buffer!" );
-        return;
-    }
-    GeoDocument* document = parser.releaseDocument();
-    Q_ASSERT( document );
-
-    m_document = static_cast<GeoDataDocument*>( document );
-    m_document->setFileName( m_filepath );
-
-    buffer.close();
-
-    qDebug() << "newGeoDataDocumentAdded" << m_filepath;
-    
-    emit newGeoDataDocumentAdded( m_document );
-}
-
-void PlacemarkLoader::saveFile( const QString& filename )
-{
-    if ( !QDir( MarbleDirs::localPath() + "/placemarks/" ).exists() )
-        ( QDir::root() ).mkpath( MarbleDirs::localPath() + "/placemarks/" );
-
-    QFile file( filename );
-    file.open( QIODevice::WriteOnly );
-    QDataStream out( &file );
-
-    // Write a header with a "magic number" and a version
-    // out << (quint32)0xA0B0C0D0;
-    out << (quint32)MarbleMagicNumber;
-    out << (qint32)014;
-
-    out.setVersion( QDataStream::Qt_4_2 );
-
-    qreal lon;
-    qreal lat;
-    qreal alt;
-
-    QVector<Marble::GeoDataPlacemark>::const_iterator it = m_container->constBegin();
-    QVector<Marble::GeoDataPlacemark>::const_iterator const end = m_container->constEnd();
-    for (; it != end; ++it )
-    {
-        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();
-    }
-}
-
-bool PlacemarkLoader::loadFile( const QString& filename )
-{
-    QFile file( filename );
-    file.open( QIODevice::ReadOnly );
-    QDataStream in( &file );
-
-    // Read and check the header
-    quint32 magic;
-    in >> magic;
-    if ( magic != MarbleMagicNumber ) {
-        qDebug( "Bad file format!" );
-        return false;
-    }
-
-    // Read the version
-    qint32 version;
-    in >> version;
-    if ( version < 014 ) {
-        qDebug( "Bad file - too old!" );
-        return false;
-    }
-    /*
-      if (version > 002) {
-      qDebug( "Bad file - too new!" );
-      return;
-      }
-    */
-    m_document = new GeoDataDocument();
-
-    m_document->setFileName( m_filepath );
-
-    in.setVersion( QDataStream::Qt_4_2 );
-
-    // Read the data itself
-    // Use double to provide a single cache file format across architectures
-    double   lon;
-    double   lat;
-    double   alt;
-    double   area;
-
-    QString  tmpstr;
-    qint64   tmpint64;
-
-    while ( !in.atEnd() ) {
-        GeoDataPlacemark mark;
-        in >> tmpstr;
-        mark.setName( tmpstr );
-        in >> lon >> lat >> alt;
-        mark.setCoordinate( (qreal)(lon), (qreal)(lat), (qreal)(alt) );
-        in >> tmpstr;
-        mark.setRole( tmpstr.at(0) );
-        in >> tmpstr;
-        mark.setDescription( tmpstr );
-        in >> tmpstr;
-        mark.setCountryCode( tmpstr );
-        in >> area;
-        mark.setArea( (qreal)(area) );
-        in >> tmpint64;
-        mark.setPopulation( tmpint64 );
-
-        m_container->append( mark );
-        m_document->append( mark );
-    }
-
-    m_document->setVisible( false );
-    qDebug() << "newGeoDataDocumentAdded" << m_filepath;
-    emit newGeoDataDocumentAdded( m_document );
-    return true;
-}
-
-#include "PlacemarkLoader.moc"
-} // namespace Marble
diff --git a/src/lib/PlacemarkLoader.h b/src/lib/PlacemarkLoader.h
deleted file mode 100644
index 7281cbd..0000000
--- a/src/lib/PlacemarkLoader.h
+++ /dev/null
@@ -1,50 +0,0 @@
-//
-// This file is part of the Marble Desktop Globe.
-//
-// This program is free software licensed under the GNU LGPL. You can
-// find a copy of this license in LICENSE.txt in the top directory of
-// the source code.
-//
-// Copyright 2008      Patrick Spendrin <ps_ml at gmx.de>
-//
-#ifndef PLACEMARKLOADER_H
-#define PLACEMARKLOADER_H
-
-#include <QtCore/QString>
-#include <QtCore/QThread>
-
-#include "GeoDataPlacemark.h"
-
-namespace Marble
-{
-class GeoDataDocument;
-
-class PlacemarkLoader : public QThread
-{
-    Q_OBJECT
-    public:
-        PlacemarkLoader( QObject* parent, const QString& file );
-        PlacemarkLoader( QObject* parent, const QString& contents, const QString& name );
-        virtual ~PlacemarkLoader();
-
-        void run();
-        QString path() const;
-        
-    Q_SIGNALS:
-        void placemarksLoaded( PlacemarkLoader*, QVector<Marble::GeoDataPlacemark> * );
-        void placemarkLoaderFailed( PlacemarkLoader* );
-        void newGeoDataDocumentAdded( GeoDataDocument* );
-    private:
-        bool loadFile( const QString& filename );
-        void saveFile( const QString& filename );
-        void importKml( const QString& filename );
-        void importKmlFromData();
-
-        QString m_filepath;
-        QString m_contents;
-        GeoDataDocument *m_document;
-        QVector<Marble::GeoDataPlacemark> *m_container;
-};
-
-} // namespace Marble
-#endif // PLACEMARKLOADER_H
diff --git a/src/lib/PlacemarkManager.cpp b/src/lib/PlacemarkManager.cpp
index ca1a8ac..07418dd 100644
--- a/src/lib/PlacemarkManager.cpp
+++ b/src/lib/PlacemarkManager.cpp
@@ -25,7 +25,6 @@
 #include "MarblePlacemarkModel.h"
 #include "MarbleGeometryModel.h"
 #include "MarbleDataFacade.h"
-#include "PlacemarkLoader.h"
 
 #include "GeoDataDocument.h"
 #include "GeoDataParser.h"
@@ -45,9 +44,6 @@ class PlacemarkManagerPrivate
         }
 
         MarbleDataFacade* m_datafacade;
-        QList<PlacemarkLoader*> m_loaderList;
-        QStringList m_pathList;
-        QList < AbstractFileViewItem* > m_fileItemList;
 };
 }
 
@@ -60,17 +56,6 @@ PlacemarkManager::PlacemarkManager( QObject *parent )
 
 PlacemarkManager::~PlacemarkManager()
 {
-    foreach( PlacemarkLoader *loader, d->m_loaderList ) {
-        if ( loader ) {
-            loader->wait();
-        }
-    }
-
-    foreach( AbstractFileViewItem *file, d->m_fileItemList)
-    {
-        delete file;
-    }
-
     delete d;
 }
 
@@ -82,166 +67,18 @@ MarblePlacemarkModel* PlacemarkManager::model() const
 void PlacemarkManager::setDataFacade( MarbleDataFacade *facade )
 {
     d->m_datafacade = facade;
-    d->m_datafacade->fileViewModel()->setPlacemarkManager(this);
-}
-
-QStringList PlacemarkManager::containers() const
-{
-    QStringList retList;
-    for( int line = 0; line < d->m_fileItemList.count(); ++line ) {
-        retList << d->m_fileItemList.at( line )->name();
-    }
-    return retList + d->m_pathList;
-}
-
-QString PlacemarkManager::toRegularName( QString name )
-{
-    return name.remove(".kml").remove(".cache");
-}
-
-void PlacemarkManager::addPlacemarkFile( const QString& filepath )
-{
-    if( ! containers().contains( toRegularName( filepath ) ) ) {
-        qDebug() << "adding container:" << toRegularName( filepath );
-        PlacemarkLoader* loader = new PlacemarkLoader( this, filepath );
-        appendLoader( loader );
-        d->m_pathList.append( toRegularName( filepath ) );
-    }
-}
-
-void PlacemarkManager::addGeoDataDocument( GeoDataDocument* document )
-{
-    KmlFileViewItem* item = new KmlFileViewItem( *this, *document );
-    addFile( item );
-
-    // now get the document that will be preserved throughout the life time
-    GeoDataDocument* doc = item->document();
-    // remove the hashes in front of the styles.
-    QVector<GeoDataFeature>::Iterator end = doc->end();
-    QVector<GeoDataFeature>::Iterator itr = doc->begin();
-    for ( ; itr != end; ++itr ) {
-        // use *itr (or itr.value()) here
-        QString styleUrl = itr->styleUrl().remove('#');
-        itr->setStyle( &doc->style( styleUrl ) );
-    }
-
-    // do not set this file if it only contains points
-    if( doc->isVisible() && d->m_datafacade->geometryModel() )
-        d->m_datafacade->geometryModel()->setGeoDataRoot( doc );
-    emit geoDataDocumentAdded( *doc );
-}
-
-void PlacemarkManager::addPlacemarkData( const QString& data, const QString& key )
-{
-    Q_ASSERT( d->m_datafacade->placemarkModel() != 0 && "You have called loadKmlFromData before creating a model!" );
-
-    qDebug() << "adding container:" << key;
-    PlacemarkLoader* loader = new PlacemarkLoader( this, data, key );
-    appendLoader( loader );
-}
-
-void PlacemarkManager::removePlacemarkKey( const QString& key )
-{
-    QString nkey = key;
-    qDebug() << "trying to remove file:" << key;
-    for( int i = 0; i < d->m_fileItemList.size(); ++i )
-    {
-        if( toRegularName( nkey ) == toRegularName( d->m_fileItemList.at(i)->name() ) ) {
-            closeFile(i);
-            break;
-        }
-    }
-}
-
-void PlacemarkManager::addFile ( AbstractFileViewItem * item )
-{
-    d->m_fileItemList.append( item );
-    emit fileAdded(d->m_fileItemList.indexOf( item ) );
+//    d->m_datafacade->placemarkModel()->setPlacemarkContainer(&d->m_placemarkContainer);
 }
 
-void PlacemarkManager::saveFile( int index )
+void PlacemarkManager::addGeoDataDocument(const GeoDataDocument &document)
 {
-    if (index < d->m_fileItemList.size() )
-    {
-        d->m_fileItemList.at( index )->saveFile();
-    }
-}
-
-void PlacemarkManager::closeFile( int index )
-{
-    if (index < d->m_fileItemList.size() )
-    {
-        d->m_fileItemList.at( index )->closeFile( indexStart( index ));
-        delete d->m_fileItemList.at( index );
-        d->m_fileItemList.removeAt( index );
-        emit fileRemoved( index );
-    }
-}
-
-int PlacemarkManager::size() const
-{
-    return d->m_fileItemList.size();
-}
-
-AbstractFileViewItem * PlacemarkManager::at( int index )
-{
-    if (index < d->m_fileItemList.size() )
-    {
-        return d->m_fileItemList.at( index );
-    }
-    return 0;
-}
-
-void PlacemarkManager::appendLoader( PlacemarkLoader *loader )
-{
-    connect (   loader, SIGNAL( placemarksLoaded( PlacemarkLoader*, PlacemarkContainer * ) ),
-                this, SLOT( loadPlacemarkContainer( PlacemarkLoader*, PlacemarkContainer * ) ) );
-
-    connect (   loader, SIGNAL( placemarkLoaderFailed( PlacemarkLoader* ) ),
-                this, SLOT( cleanupLoader( PlacemarkLoader* ) ) );
-
-    connect (   loader, SIGNAL( newGeoDataDocumentAdded( GeoDataDocument* ) ),
-                this, SLOT( addGeoDataDocument( GeoDataDocument* ) ) );
-
-    d->m_loaderList.append( loader );
-    loader->start();
-}
-
-void PlacemarkManager::cleanupLoader( PlacemarkLoader* loader )
-{
-    d->m_loaderList.removeAll( loader );
-    if ( loader->isFinished() ) {
-         d->m_pathList.removeAll( loader->path() );
-         delete loader;
-    }
-}
-
-void PlacemarkManager::loadPlacemarkContainer( PlacemarkLoader* loader, QVector<Marble::GeoDataPlacemark> * container )
-{
-    qDebug() << "Containername " << "to be finalized:" << (d->m_loaderList.size() == 1) << d->m_loaderList.size();
-    d->m_loaderList.removeAll( loader );
-    if ( container )
+    qDebug() << "PlacemarkManager::geoDataDocumentAdded:" << document.name();
+    if (!document.placemarks().isEmpty())
     { 
-        d->m_datafacade->placemarkModel()->addPlacemarks( *container, false, d->m_loaderList.isEmpty() );
-    }
-
-    if( d->m_loaderList.isEmpty() ) {
-        emit finalize();
-    }
-
-    if ( loader->isFinished() ) {
-         d->m_pathList.removeAll( loader->path() );
-         delete loader;
-    }
-}
-
-int PlacemarkManager::indexStart( int index )
-{
-    int start = 0;
-    for( int i = 0; i < index; i++ ) {
-        start += d->m_fileItemList.at( i )->size();
+//        d->m_placemarkContainer << document->placemarks();
+        QVector<GeoDataPlacemark> result = document.placemarks();
+        d->m_datafacade->placemarkModel()->addPlacemarks( result, false );
     }
-    return start;
 }
 
 #include "PlacemarkManager.moc"
diff --git a/src/lib/PlacemarkManager.h b/src/lib/PlacemarkManager.h
index 9303cd6..114e613 100644
--- a/src/lib/PlacemarkManager.h
+++ b/src/lib/PlacemarkManager.h
@@ -17,10 +17,6 @@
 #include <QtCore/QObject>
 #include <QtCore/QString>
 
-#include "PlacemarkLoader.h"
-
-#include "GeoDataPlacemark.h"
-
 namespace Marble
 {
 
@@ -68,57 +64,11 @@ class PlacemarkManager : public QObject
      */
     void setDataFacade ( MarbleDataFacade *facade );
 
-    /**
-     * return a list containing all containers that have been queued for loading or that are
-     * loaded already
-     */
-    QStringList containers() const;
-
-    /**
-     * Loads a new place mark file into the manager.
-     */
-    void addPlacemarkFile( const QString &fileName );
-
-    /**
-    * removes an existing GeoDataDocument from the manager
-    */
-    void removePlacemarkKey( const QString& key );
-
-    /**
-    * add Data containing KML code as string
-    */
-    void addPlacemarkData( const QString& data, const QString& key );
-
-    void addFile( AbstractFileViewItem * item );
-    void saveFile( int index );
-    void closeFile( int index );
-
-    int size() const;
-    AbstractFileViewItem * at( int index );
-
-
- Q_SIGNALS:
-    void geoDataDocumentAdded( const GeoDataDocument& );
-    void finalize();
-    void fileAdded( int index );
-    void fileRemoved( int index );
-
- private Q_SLOTS:
-    void loadPlacemarkContainer( PlacemarkLoader* loader, QVector<Marble::GeoDataPlacemark> * );
-    void cleanupLoader( PlacemarkLoader* loader );
-    void addGeoDataDocument( GeoDataDocument* );
+ public Q_SLOTS:
+    void addGeoDataDocument( const GeoDataDocument & );
 
  private:
 
-    int indexStart( int index );
-
-    void appendLoader( PlacemarkLoader *loader );
-
-    /**
-     * internal helper function which returns the regular name of a kml or cache file
-     */
-    static QString toRegularName( QString name );
-
     Q_DISABLE_COPY( PlacemarkManager )
 
     PlacemarkManagerPrivate *const d;
-- 
1.6.3.3





More information about the Marble-devel mailing list