[Marble-devel] [PATCH 5/8] PlacemarkManager: react to FileManager::fileRemoved signal
Thibaut GRIDEL
tgridel at free.fr
Tue Sep 1 23:24:33 CEST 2009
9 files changed, 67 insertions(+), 38 deletions(-)
diff --git a/src/lib/AbstractFileViewItem.h b/src/lib/AbstractFileViewItem.h
index b745341..359d338 100644
--- a/src/lib/AbstractFileViewItem.h
+++ b/src/lib/AbstractFileViewItem.h
@@ -27,7 +27,6 @@ class AbstractFileViewItem
virtual ~AbstractFileViewItem() {};
virtual void saveFile() = 0;
- virtual void closeFile( int start ) = 0;
virtual int size() const { return 0; };
virtual bool isShown() const = 0;
virtual void setShown( bool value ) = 0;
diff --git a/src/lib/FileManager.cpp b/src/lib/FileManager.cpp
index 9b64d68..5776961 100644
--- a/src/lib/FileManager.cpp
+++ b/src/lib/FileManager.cpp
@@ -150,10 +150,20 @@ void FileManager::closeFile( int index )
qDebug() << "FileManager::closeFile";
if (index < d->m_fileItemList.size() )
{
- d->m_fileItemList.at( index )->closeFile( indexStart( index ));
+ emit fileRemoved( index );
+ KmlFileViewItem *file =
+ static_cast<KmlFileViewItem*>(d->m_fileItemList.at(index));
+ if (file)
+ {
+ MarbleGeometryModel *geometryModel =
+ d->m_datafacade->geometryModel();
+ if (geometryModel->geoDataRoot() == file->document())
+ {
+ geometryModel->setGeoDataRoot(0);
+ }
+ }
delete d->m_fileItemList.at( index );
d->m_fileItemList.removeAt( index );
- emit fileRemoved( index );
}
}
@@ -206,13 +216,4 @@ void FileManager::cleanupLoader( FileLoader* loader )
}
}
-int FileManager::indexStart( int index )
-{
- int start = 0;
- for( int i = 0; i < index; i++ ) {
- start += d->m_fileItemList.at( i )->size();
- }
- return start;
-}
-
#include "FileManager.moc"
diff --git a/src/lib/GpxFileViewItem.cpp b/src/lib/GpxFileViewItem.cpp
index b4ea6b8..78d4897 100644
--- a/src/lib/GpxFileViewItem.cpp
+++ b/src/lib/GpxFileViewItem.cpp
@@ -55,12 +55,6 @@ void GpxFileViewItem::saveFile()
stream << ( *m_gpxFile );
}
-void GpxFileViewItem::closeFile( int start )
-{
- Q_UNUSED( start );
- //TODO
-}
-
bool GpxFileViewItem::isShown() const
{
return (m_gpxFile->checkState() == Qt::Checked );
diff --git a/src/lib/GpxFileViewItem.h b/src/lib/GpxFileViewItem.h
index 4e0c865..94495bf 100644
--- a/src/lib/GpxFileViewItem.h
+++ b/src/lib/GpxFileViewItem.h
@@ -34,7 +34,6 @@ class GpxFileViewItem
* AbstractFileViewItem methods
*/
virtual void saveFile();
- virtual void closeFile( int start );
virtual bool isShown() const;
virtual void setShown( bool value );
virtual QString name() const;
diff --git a/src/lib/KmlFileViewItem.cpp b/src/lib/KmlFileViewItem.cpp
index d90d838..71f4398 100644
--- a/src/lib/KmlFileViewItem.cpp
+++ b/src/lib/KmlFileViewItem.cpp
@@ -42,12 +42,6 @@ GeoDataDocument* KmlFileViewItem::document()
return &m_document;
}
-void KmlFileViewItem::closeFile( int start )
-{
- qDebug() << "closing file" << m_document.name() << m_document.fileName();
- m_fileManager.dataFacade()->placemarkModel()->removePlacemarks( m_document.fileName(), start, size() );
-}
-
int KmlFileViewItem::size() const
{
return m_document.placemarks().size();
diff --git a/src/lib/KmlFileViewItem.h b/src/lib/KmlFileViewItem.h
index b2053ba..c2df6e1 100644
--- a/src/lib/KmlFileViewItem.h
+++ b/src/lib/KmlFileViewItem.h
@@ -31,7 +31,6 @@ class KmlFileViewItem : public AbstractFileViewItem
* AbstractFileViewItem methods
*/
virtual void saveFile();
- virtual void closeFile( int start );
virtual bool isShown() const;
virtual void setShown( bool value );
virtual int size() const;
diff --git a/src/lib/MarbleModel.cpp b/src/lib/MarbleModel.cpp
index 3c9336b..e3beba1 100644
--- a/src/lib/MarbleModel.cpp
+++ b/src/lib/MarbleModel.cpp
@@ -169,13 +169,12 @@ MarbleModel::MarbleModel( QObject *parent )
}
d->m_fileManager = new FileManager();
d->m_fileManager->setDataFacade(d->m_dataFacade);
+
d->m_placemarkmanager = new PlacemarkManager();
d->m_placemarkmanager->setDataFacade(d->m_dataFacade);
-
- 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_placemarkmanager->setFileManager(d->m_fileManager);
d->m_popSortModel = new QSortFilterProxyModel( this );
diff --git a/src/lib/PlacemarkManager.cpp b/src/lib/PlacemarkManager.cpp
index 37a3fc1..4120d00 100644
--- a/src/lib/PlacemarkManager.cpp
+++ b/src/lib/PlacemarkManager.cpp
@@ -19,6 +19,7 @@
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
+#include "FileManager.h"
#include "KmlFileViewItem.h"
#include "FileViewModel.h"
#include "MarbleDirs.h"
@@ -44,6 +45,7 @@ class PlacemarkManagerPrivate
}
MarbleDataFacade* m_datafacade;
+ FileManager *m_fileManager;
};
}
@@ -70,14 +72,49 @@ void PlacemarkManager::setDataFacade( MarbleDataFacade *facade )
// d->m_datafacade->placemarkModel()->setPlacemarkContainer(&d->m_placemarkContainer);
}
-void PlacemarkManager::addGeoDataDocument(const GeoDataDocument &document)
+void PlacemarkManager::setFileManager( FileManager *fileManager )
{
- qDebug() << "PlacemarkManager::geoDataDocumentAdded:" << document.name();
- if (!document.placemarks().isEmpty())
- {
-// d->m_placemarkContainer << document->placemarks();
- QVector<GeoDataPlacemark> result = document.placemarks();
- d->m_datafacade->placemarkModel()->addPlacemarks( result );
+ d->m_fileManager = fileManager;
+ connect( d->m_fileManager, SIGNAL( fileAdded(int)),
+ this, SLOT(addGeoDataDocument(int)) );
+ connect( d->m_fileManager, SIGNAL( fileRemoved(int)),
+ this, SLOT(removeGeoDataDocument(int)) );
+}
+
+void PlacemarkManager::addGeoDataDocument( int index )
+{
+ KmlFileViewItem *file =
+ static_cast<KmlFileViewItem*>(d->m_fileManager->at(index));
+ if (file)
+ {
+ const GeoDataDocument &document = *file->document();
+ qDebug() << "PlacemarkManager::addGeoDataDocument:"
+ << document.fileName();
+ if (!document.placemarks().isEmpty())
+ {
+ QVector<GeoDataPlacemark> result = document.placemarks();
+ d->m_datafacade->placemarkModel()->addPlacemarks( result );
+ }
+ }
+}
+
+void PlacemarkManager::removeGeoDataDocument( int index )
+{
+ KmlFileViewItem *file =
+ static_cast<KmlFileViewItem*>(d->m_fileManager->at(index));
+ if (file)
+ {
+ const GeoDataDocument &document = *file->document();
+ qDebug() << "PlacemarkManager::removeGeoDataDocument:"
+ << document.fileName();
+ int start = 0;
+ for ( int i = 0; i < index; ++i )
+ {
+ start += d->m_fileManager->at(i)->size();
+ }
+ d->m_datafacade->placemarkModel()->removePlacemarks(
+ document.fileName(), start, d->m_fileManager->at(index)->size() );
+
}
}
diff --git a/src/lib/PlacemarkManager.h b/src/lib/PlacemarkManager.h
index 114e613..555490c 100644
--- a/src/lib/PlacemarkManager.h
+++ b/src/lib/PlacemarkManager.h
@@ -20,6 +20,7 @@
namespace Marble
{
+class FileManager;
class GeoDataDocument;
class MarblePlacemarkModel;
class MarbleDataFacade;
@@ -64,8 +65,14 @@ class PlacemarkManager : public QObject
*/
void setDataFacade ( MarbleDataFacade *facade );
- public Q_SLOTS:
- void addGeoDataDocument( const GeoDataDocument & );
+ /**
+ * Sets the FileManager from which the placemarks are loaded.
+ */
+ void setFileManager ( FileManager *fileManager );
+
+public Q_SLOTS:
+ void addGeoDataDocument( int index );
+ void removeGeoDataDocument( int index );
private:
--
1.6.3.3
More information about the Marble-devel
mailing list