[Marble-devel] [PATCH 2/8] get rid of PlacemarkContainer
Thibaut GRIDEL
tgridel at free.fr
Tue Sep 1 23:24:30 CEST 2009
replace it with the actual QVector<GeoDataPlacemark> where needed
13 files changed, 24 insertions(+), 196 deletions(-)
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index f8de6b7..1a9ab6b 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -101,7 +101,6 @@ set(marblewidget_SRCS
MeasureTool.cpp
ImageLoadThread.cpp
VisiblePlacemark.cpp
- PlacemarkContainer.cpp
PlacemarkManager.cpp
PlacemarkLayout.cpp
PlacemarkLoader.cpp
diff --git a/src/lib/MarbleControlBox.cpp b/src/lib/MarbleControlBox.cpp
index d82432c..885dda6 100644
--- a/src/lib/MarbleControlBox.cpp
+++ b/src/lib/MarbleControlBox.cpp
@@ -46,7 +46,6 @@
#include "gps/GpxFileModel.h"
#include "gps/GpsLayer.h"
#include "gps/PositionTracking.h"
-#include "PlacemarkContainer.h"
#include "MarbleLocale.h"
#include "MarblePlacemarkModel.h"
#include "MarbleRunnerManager.h"
diff --git a/src/lib/MarblePlacemarkModel.cpp b/src/lib/MarblePlacemarkModel.cpp
index 60030fc..a002a67 100644
--- a/src/lib/MarblePlacemarkModel.cpp
+++ b/src/lib/MarblePlacemarkModel.cpp
@@ -22,7 +22,6 @@
// Marble
#include "GeoDataStyle.h" // In geodata/data/
-#include "PlacemarkContainer.h"
using namespace Marble;
@@ -30,8 +29,7 @@ class MarblePlacemarkModel::Private
{
public:
- Private( MarblePlacemarkModel *parent )
- : m_parent( parent )
+ Private()
{
}
@@ -39,8 +37,7 @@ class MarblePlacemarkModel::Private
{
}
- MarblePlacemarkModel *m_parent;
- PlacemarkContainer m_placemarkContainer;
+ QVector<Marble::GeoDataPlacemark> m_placemarkContainer;
};
@@ -49,7 +46,7 @@ class MarblePlacemarkModel::Private
MarblePlacemarkModel::MarblePlacemarkModel( QObject *parent )
: QAbstractListModel( parent ),
- d( new Private( this ) )
+ d( new Private )
{
}
@@ -59,21 +56,6 @@ MarblePlacemarkModel::~MarblePlacemarkModel()
delete d;
}
-void MarblePlacemarkModel::sort( int column, Qt::SortOrder order )
-{
- Q_UNUSED( column )
- Q_UNUSED( order )
-
- QTime t;
- t.start();
- qDebug() << "start sorting";
-
- emit layoutAboutToBeChanged();
-// d->m_placemarkContainer.sort( order );
- emit layoutChanged();
-
- qDebug() << "MarblePlacemarkModel (sort): Time elapsed:" << t.elapsed() << "ms";
-}
int MarblePlacemarkModel::rowCount( const QModelIndex &parent ) const
{
@@ -185,7 +167,7 @@ QModelIndexList MarblePlacemarkModel::approxMatch( const QModelIndex & start, in
return results;
}
-void MarblePlacemarkModel::addPlacemarks( PlacemarkContainer &placemarks,
+void MarblePlacemarkModel::addPlacemarks( QVector<Marble::GeoDataPlacemark> &placemarks,
bool clearPrevious,
bool finalize )
{
@@ -228,9 +210,6 @@ void MarblePlacemarkModel::removePlacemarks( const QString &containerName,
d->m_placemarkContainer.erase(begin, end);
endRemoveRows();
-/* if ( finalize ) {
-// sort( Qt::DescendingOrder );
- }*/
// there have not been any additions, but without the following line marble seems to crash here.
emit dataChanged( index( 0, 0 ), index( 0, 0 ) );
qDebug() << "removePlacemarks(" << containerName << "): Time elapsed:" << t.elapsed() << "ms for" << length << "Placemarks.";
@@ -247,7 +226,7 @@ void MarblePlacemarkModel::clearPlacemarks()
reset();
}
-void MarblePlacemarkModel::createFilterProperties( PlacemarkContainer &container )
+void MarblePlacemarkModel::createFilterProperties( QVector<Marble::GeoDataPlacemark> &container )
{
QVector<GeoDataPlacemark>::Iterator i;
diff --git a/src/lib/MarblePlacemarkModel.h b/src/lib/MarblePlacemarkModel.h
index 1061335..fb31d38 100644
--- a/src/lib/MarblePlacemarkModel.h
+++ b/src/lib/MarblePlacemarkModel.h
@@ -25,12 +25,13 @@
#include "marble_export.h"
+#include "GeoDataPlacemark.h"
+
namespace Marble
{
class GeoDataCoordinates;
class GeoDataStyle;
-class PlacemarkContainer;
/**
* This class represents a model of all place marks which
* are currently available through a given PlacemarkManager.
@@ -100,7 +101,7 @@ class MARBLE_EXPORT MarblePlacemarkModel : public QAbstractListModel
*
* Note: The model takes ownership of the place marks!
*/
- void addPlacemarks( PlacemarkContainer &placemarks,
+ void addPlacemarks( QVector<Marble::GeoDataPlacemark> &placemarks,
bool clearPrevious = false,
bool finalize = true );
@@ -134,9 +135,7 @@ class MARBLE_EXPORT MarblePlacemarkModel : public QAbstractListModel
*/
void clearPlacemarks();
- virtual void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
-
- void createFilterProperties( PlacemarkContainer &container );
+ void createFilterProperties( QVector<Marble::GeoDataPlacemark> &container );
Q_DISABLE_COPY( MarblePlacemarkModel )
class Private;
diff --git a/src/lib/MarbleRunnerManager.cpp b/src/lib/MarbleRunnerManager.cpp
index 3a3da52..f237c11 100644
--- a/src/lib/MarbleRunnerManager.cpp
+++ b/src/lib/MarbleRunnerManager.cpp
@@ -22,7 +22,6 @@
#include "MarblePlacemarkModel.h"
#include "PlacemarkManager.h"
-#include "PlacemarkContainer.h"
#include "GeoDataPlacemark.h"
#include "LatLonRunner.h"
@@ -41,7 +40,7 @@ MarbleRunnerManager::MarbleRunnerManager( QObject *parent )
: QObject(parent),
m_activeRunners(0),
m_lastString(""),
- m_model(new MarblePlacemarkModel(0))
+ m_model(new MarblePlacemarkModel)
{
qRegisterMetaType<QVector<GeoDataPlacemark> >("QVector<GeoDataPlacemark>");
}
@@ -95,22 +94,11 @@ void MarbleRunnerManager::slotRunnerFinished( MarbleAbstractRunner* runner, QVec
if( result.isEmpty() )
return;
- PlacemarkContainer cont( result, "Runner Results" );
- m_model->addPlacemarks( cont, false );
+ m_model->addPlacemarks( result, false );
emit modelChanged( m_model );
}
-MarblePlacemarkModel* MarbleRunnerManager::model()
-{
- return m_model;
-}
-
-void MarbleRunnerManager::setModel( MarblePlacemarkModel *model )
-{
- m_model = model;
-}
-
}
#include "MarbleRunnerManager.moc"
diff --git a/src/lib/MarbleRunnerManager.h b/src/lib/MarbleRunnerManager.h
index 1ce69e3..ad47d0d 100644
--- a/src/lib/MarbleRunnerManager.h
+++ b/src/lib/MarbleRunnerManager.h
@@ -40,8 +40,6 @@ public:
explicit MarbleRunnerManager( QObject *parent = 0 );
~MarbleRunnerManager();
- void setModel(MarblePlacemarkModel *model);
- MarblePlacemarkModel* model();
public slots:
void newText(QString text);
signals:
diff --git a/src/lib/PlacemarkContainer.cpp b/src/lib/PlacemarkContainer.cpp
deleted file mode 100644
index 4648030..0000000
--- a/src/lib/PlacemarkContainer.cpp
+++ /dev/null
@@ -1,58 +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 2006-2007 Torsten Rahn <tackat at kde.org>"
-// Copyright 2007 Inge Wallin <ingwa at kde.org>"
-//
-
-
-#include "PlacemarkContainer.h"
-
-using namespace Marble;
-
-PlacemarkContainer::PlacemarkContainer()
-{
-}
-
-PlacemarkContainer::PlacemarkContainer( const QString& name )
- : m_name( name )
-{
-}
-
-PlacemarkContainer::PlacemarkContainer( const QVector<GeoDataPlacemark>& container, const QString& name )
- : QVector<GeoDataPlacemark>( container ), m_name( name )
-{
-}
-
-inline bool populationLessThan( const GeoDataPlacemark& mark1, const GeoDataPlacemark& mark2 )
-{
- // If compared items do not differ in terms of being selected,
- // compare them based on population numbers.
- if ( mark1.popularityIndex() != mark2.popularityIndex() )
- return ( mark1.popularityIndex() > mark2.popularityIndex() );
- else
- return ( mark1.popularity() > mark2.popularity() );
-}
-
-
-void PlacemarkContainer::setName( const QString& name )
-{
- m_name = name;
-}
-
-QString PlacemarkContainer::name() const
-{
- return m_name;
-}
-
-void PlacemarkContainer::sort( Qt::SortOrder order )
-{
- Q_UNUSED( order )
-
- // FIXME: use order
- qStableSort( begin(), end(), populationLessThan );
-}
diff --git a/src/lib/PlacemarkContainer.h b/src/lib/PlacemarkContainer.h
deleted file mode 100644
index dca0ca2..0000000
--- a/src/lib/PlacemarkContainer.h
+++ /dev/null
@@ -1,68 +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 2006-2007 Torsten Rahn <tackat at kde.org>"
-// Copyright 2007 Inge Wallin <ingwa at kde.org>"
-//
-
-
-#ifndef PLACEMARKCONTAINER_H
-#define PLACEMARKCONTAINER_H
-
-
-#include <QtCore/QString>
-#include <QtCore/QVector>
-
-#include "GeoDataPlacemark.h" // In geodata/data/
-
-namespace Marble
-{
-
-/**
- * A helper class which contains a couple of place mark
- * objects.
- *
- * The ownership of the place mark objects is <b>not</b> transfered to the container!
- */
-class PlacemarkContainer : public QVector<Marble::GeoDataPlacemark>
-{
- public:
- /// Create a new PlacemarkContainer.
- PlacemarkContainer();
-
- /**
- * @brief Create a new PlacemarkContainer
- * param name the name of the container
- */
- explicit PlacemarkContainer( const QString& name );
-
- /**
- * @brief Create a new PlacemarkContainer
- * param container a QVector of Placemarks
- * param name the name of the container
- */
- PlacemarkContainer( const QVector<Marble::GeoDataPlacemark>& container, const QString& name );
-
- /// Return the name of the container
- QString name() const;
-
- /**
- * @brief Set a new name for the PlacemarkContainer
- * param name the new name of the container
- */
- void setName( const QString& name );
-
- /// @brief Sort the placemarks in descending order by population.
- void sort( Qt::SortOrder order = Qt::AscendingOrder );
-
- private:
- QString m_name;
-};
-
-}
-
-#endif // PLACEMARKCONTAINER_H
diff --git a/src/lib/PlacemarkLoader.cpp b/src/lib/PlacemarkLoader.cpp
index 98ce0a5..69aaade 100644
--- a/src/lib/PlacemarkLoader.cpp
+++ b/src/lib/PlacemarkLoader.cpp
@@ -23,7 +23,6 @@
#include "GeoDataPlacemark.h"
#include "MarbleDirs.h"
#include "MarblePlacemarkModel.h"
-#include "PlacemarkContainer.h"
namespace Marble
@@ -65,7 +64,7 @@ void PlacemarkLoader::run()
QString defaultsrcname;
QString defaulthomecache;
- m_container = new PlacemarkContainer( m_filepath );
+ m_container = new QVector<Marble::GeoDataPlacemark>;
if( m_filepath.endsWith(".kml") ) {
m_filepath.remove(QRegExp("\\.kml$"));
@@ -143,7 +142,7 @@ void PlacemarkLoader::run()
emit placemarkLoaderFailed( this );
}
} else {
- m_container = new PlacemarkContainer( m_filepath );
+ m_container = new QVector<Marble::GeoDataPlacemark>;
// Read the KML Data
importKmlFromData();
@@ -177,9 +176,6 @@ void PlacemarkLoader::importKml( const QString& filename )
m_document = static_cast<GeoDataDocument*>( document );
m_document->setFileName( m_filepath );
- m_container = new PlacemarkContainer( m_document->placemarks(),
- m_filepath );
-
file.close();
qDebug() << "newGeoDataDocumentAdded" << m_filepath;
@@ -205,9 +201,6 @@ void PlacemarkLoader::importKmlFromData()
m_document = static_cast<GeoDataDocument*>( document );
m_document->setFileName( m_filepath );
- m_container = new PlacemarkContainer( m_document->placemarks(),
- m_filepath );
-
buffer.close();
qDebug() << "newGeoDataDocumentAdded" << m_filepath;
@@ -235,8 +228,8 @@ void PlacemarkLoader::saveFile( const QString& filename )
qreal lat;
qreal alt;
- PlacemarkContainer::const_iterator it = m_container->constBegin();
- PlacemarkContainer::const_iterator const end = m_container->constEnd();
+ 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();
diff --git a/src/lib/PlacemarkLoader.h b/src/lib/PlacemarkLoader.h
index 380e902..7281cbd 100644
--- a/src/lib/PlacemarkLoader.h
+++ b/src/lib/PlacemarkLoader.h
@@ -13,9 +13,10 @@
#include <QtCore/QString>
#include <QtCore/QThread>
+#include "GeoDataPlacemark.h"
+
namespace Marble
{
-class PlacemarkContainer;
class GeoDataDocument;
class PlacemarkLoader : public QThread
@@ -30,7 +31,7 @@ class PlacemarkLoader : public QThread
QString path() const;
Q_SIGNALS:
- void placemarksLoaded( PlacemarkLoader*, PlacemarkContainer * );
+ void placemarksLoaded( PlacemarkLoader*, QVector<Marble::GeoDataPlacemark> * );
void placemarkLoaderFailed( PlacemarkLoader* );
void newGeoDataDocumentAdded( GeoDataDocument* );
private:
@@ -42,7 +43,7 @@ class PlacemarkLoader : public QThread
QString m_filepath;
QString m_contents;
GeoDataDocument *m_document;
- PlacemarkContainer *m_container;
+ QVector<Marble::GeoDataPlacemark> *m_container;
};
} // namespace Marble
diff --git a/src/lib/PlacemarkManager.cpp b/src/lib/PlacemarkManager.cpp
index 6467445..ca1a8ac 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 "PlacemarkContainer.h"
#include "PlacemarkLoader.h"
#include "GeoDataDocument.h"
@@ -56,7 +55,6 @@ PlacemarkManager::PlacemarkManager( QObject *parent )
: QObject( parent )
, d( new PlacemarkManagerPrivate() )
{
-
}
@@ -218,9 +216,9 @@ void PlacemarkManager::cleanupLoader( PlacemarkLoader* loader )
}
}
-void PlacemarkManager::loadPlacemarkContainer( PlacemarkLoader* loader, PlacemarkContainer * container )
+void PlacemarkManager::loadPlacemarkContainer( PlacemarkLoader* loader, QVector<Marble::GeoDataPlacemark> * container )
{
- qDebug() << "Containername:" << container->name() << "to be finalized:" << (d->m_loaderList.size() == 1) << d->m_loaderList.size();
+ qDebug() << "Containername " << "to be finalized:" << (d->m_loaderList.size() == 1) << d->m_loaderList.size();
d->m_loaderList.removeAll( loader );
if ( container )
{
diff --git a/src/lib/PlacemarkManager.h b/src/lib/PlacemarkManager.h
index 3a4af32..9303cd6 100644
--- a/src/lib/PlacemarkManager.h
+++ b/src/lib/PlacemarkManager.h
@@ -19,11 +19,12 @@
#include "PlacemarkLoader.h"
+#include "GeoDataPlacemark.h"
+
namespace Marble
{
class GeoDataDocument;
-class PlacemarkContainer;
class MarblePlacemarkModel;
class MarbleDataFacade;
class PlacemarkManagerPrivate;
@@ -103,7 +104,7 @@ class PlacemarkManager : public QObject
void fileRemoved( int index );
private Q_SLOTS:
- void loadPlacemarkContainer( PlacemarkLoader* loader, PlacemarkContainer * );
+ void loadPlacemarkContainer( PlacemarkLoader* loader, QVector<Marble::GeoDataPlacemark> * );
void cleanupLoader( PlacemarkLoader* loader );
void addGeoDataDocument( GeoDataDocument* );
diff --git a/src/lib/geodata/data/GeoDataContainer.h b/src/lib/geodata/data/GeoDataContainer.h
index 5812c05..00725e0 100644
--- a/src/lib/geodata/data/GeoDataContainer.h
+++ b/src/lib/geodata/data/GeoDataContainer.h
@@ -78,7 +78,6 @@ class GEODATA_EXPORT GeoDataContainer : public GeoDataFeature
* @return A QVector of GeoDataPlacemark
*
* @see GeoDataPlacemark
- * @see PlacemarkContainer
*/
QVector<GeoDataPlacemark> placemarks() const;
--
1.6.3.3
More information about the Marble-devel
mailing list