Commit 8b0a09cb authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Use QVector<GeoDataPlacemark*> instead of QList<GeoDataObject*>

This is more efficient and avoids loads of static_casts.
parent 8907b7e5
......@@ -15,14 +15,11 @@
#include "GeoDataObject.h"
#include "GeoDataTypes.h"
BaseFilter::BaseFilter(GeoDataDocument* document, const char *type) :
m_document(document)
BaseFilter::BaseFilter(GeoDataDocument* document) :
m_document(document),
m_placemarks(document->placemarkList())
{
foreach (GeoDataFeature* feature, m_document->featureList()) {
if(feature->nodeType() == type) {
m_objects.append(feature);
}
}
// nothing to do
}
BaseFilter::~BaseFilter()
......@@ -30,12 +27,12 @@ BaseFilter::~BaseFilter()
}
QList<GeoDataObject*>::const_iterator BaseFilter::objectsBegin() const
QVector<GeoDataPlacemark*>::const_iterator BaseFilter::objectsBegin() const
{
return m_objects.begin();
return m_placemarks.begin();
}
QList<GeoDataObject*>::const_iterator BaseFilter::objectsEnd() const
QVector<GeoDataPlacemark*>::const_iterator BaseFilter::objectsEnd() const
{
return m_objects.end();
return m_placemarks.end();
}
......@@ -23,17 +23,17 @@ using namespace Marble;
class BaseFilter
{
public:
BaseFilter(GeoDataDocument* document, const char *type);
BaseFilter(GeoDataDocument* document);
virtual ~BaseFilter();
virtual void process() = 0;
QList<GeoDataObject*>::const_iterator objectsBegin() const;
QList<GeoDataObject*>::const_iterator objectsEnd() const;
QVector<GeoDataPlacemark*>::const_iterator objectsBegin() const;
QVector<GeoDataPlacemark*>::const_iterator objectsEnd() const;
protected:
GeoDataDocument* m_document;
QList<GeoDataObject*> m_objects;
QVector<GeoDataPlacemark*> m_placemarks;
};
#endif // OBJECTHANDLER_H
......@@ -19,26 +19,26 @@ LineStringProcessor::LineStringProcessor(GeoDataDocument* document) :
PlacemarkFilter(document)
{
QList<GeoDataPlacemark*> toRemove;
foreach (GeoDataObject* placemark, m_objects) {
if( static_cast<GeoDataPlacemark*>(placemark)->geometry()->nodeType() != GeoDataTypes::GeoDataLineStringType) {
toRemove.append(static_cast<GeoDataPlacemark*>(placemark));
foreach (GeoDataPlacemark* placemark, m_placemarks) {
if(placemark->geometry()->nodeType() != GeoDataTypes::GeoDataLineStringType) {
toRemove.append(placemark);
}
}
foreach (GeoDataObject* placemark, toRemove) {
m_objects.removeOne(placemark);
foreach (GeoDataPlacemark* placemark, toRemove) {
m_placemarks.removeOne(placemark);
}
}
void LineStringProcessor::process()
{
qDebug() << "Polylines to process: " << m_objects.size();
qDebug() << "Polylines to process: " << m_placemarks.size();
QList<GeoDataObject*> polylinesToDrop;
foreach (GeoDataObject* polyline, m_objects) {
switch(static_cast<GeoDataPlacemark*>(polyline)->visualCategory())
foreach (GeoDataPlacemark* polyline, m_placemarks) {
switch(polyline->visualCategory())
{
case GeoDataFeature::HighwayCycleway :
case GeoDataFeature::HighwayFootway :
......
......@@ -28,9 +28,7 @@ NodeReducer::NodeReducer(GeoDataDocument* document, int zoomLevel) :
void NodeReducer::process()
{
foreach (GeoDataObject* object, m_objects) {
GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>(object);
foreach (GeoDataPlacemark* placemark, m_placemarks) {
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataLineStringType){
GeoDataLineString* prevLine = static_cast<GeoDataLineString*>(placemark->geometry());
......@@ -160,4 +158,4 @@ qreal NodeReducer::resolutionForLevel(int level) {
return 0.0000005;
break;
}
}
\ No newline at end of file
}
......@@ -13,8 +13,8 @@
#include "GeoDataPlacemark.h"
PlacemarkFilter::PlacemarkFilter(GeoDataDocument *document) :
BaseFilter(document, GeoDataTypes::GeoDataPlacemarkType)
BaseFilter(document)
{
qDebug() << "Placemark count:" << m_objects.size();
qDebug() << "Placemark count:" << m_placemarks.size();
}
......@@ -29,8 +29,7 @@ void ShpCoastlineProcessor::process()
OsmPlacemarkData marbleLand;
marbleLand.addTag("marble_land","landmass");
foreach (GeoDataObject* object, m_objects) {
GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>(object);
foreach (GeoDataPlacemark* placemark, m_placemarks) {
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
placemark->setOsmData(marbleLand);
}
......@@ -58,8 +57,7 @@ GeoDataDocument *ShpCoastlineProcessor::cutToTiles(unsigned int zoomLevel, unsig
tileBoundary.setBoundaries(north, south, east, west);
foreach (GeoDataObject* object, m_objects) {
GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>(object);
foreach (GeoDataPlacemark* placemark, m_placemarks) {
if(placemark->geometry()->nodeType() == GeoDataTypes::GeoDataPolygonType) {
GeoDataPolygon* marblePolygon = static_cast<GeoDataPolygon*>(placemark->geometry());
......
......@@ -24,11 +24,10 @@ TagsFilter::TagsFilter(GeoDataDocument *document, const QStringList &tagsList, b
{
int total=0, tagCount=0;
// qDebug()<<"Entered tagFilter";
QList<GeoDataObject*> previousObjects(m_objects);
m_objects.clear();
foreach (GeoDataObject *object, previousObjects) {
QVector<GeoDataPlacemark*> previousObjects(m_placemarks);
m_placemarks.clear();
foreach (GeoDataPlacemark *placemark, previousObjects) {
++total;
GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(object);
bool flag = andFlag;
QStringList::const_iterator itr = tagsList.begin();
for (; itr != tagsList.end(); ++itr) {
......@@ -63,10 +62,10 @@ TagsFilter::TagsFilter(GeoDataDocument *document, const QStringList &tagsList, b
if (flag) {
++tagCount;
// qDebug()<<"Contained tag";
m_objects.append(object);
m_placemarks.append(placemark);
// qDebug()<<"ID "<<placemark->osmData().id();
} else {
m_rejectedObjects.append(object);
m_rejectedObjects.append(placemark);
}
}
......@@ -84,12 +83,12 @@ void TagsFilter::process()
}
QList<GeoDataObject*>::const_iterator TagsFilter::rejectedObjectsBegin() const
QVector<GeoDataPlacemark*>::const_iterator TagsFilter::rejectedObjectsBegin() const
{
return m_rejectedObjects.begin();
}
QList<GeoDataObject*>::const_iterator TagsFilter::rejectedObjectsEnd() const
QVector<GeoDataPlacemark*>::const_iterator TagsFilter::rejectedObjectsEnd() const
{
return m_rejectedObjects.end();
}
......@@ -27,10 +27,10 @@ public:
//Filters placemarks which have tags in the hash
TagsFilter(GeoDataDocument* document, const QStringList& tagsList, bool andFlag = false);
virtual void process();
QList<GeoDataObject*>::const_iterator rejectedObjectsBegin() const;
QList<GeoDataObject*>::const_iterator rejectedObjectsEnd() const;
QVector<GeoDataPlacemark*>::const_iterator rejectedObjectsBegin() const;
QVector<GeoDataPlacemark*>::const_iterator rejectedObjectsEnd() const;
private:
QList<GeoDataObject*> m_rejectedObjects;
QVector<GeoDataPlacemark*> m_rejectedObjects;
};
}
......
......@@ -48,8 +48,7 @@ GeoDataDocument *TinyPlanetProcessor::cutToTiles(unsigned int zoomLevel, unsigne
BaseClipper clipper;
clipper.initClipRect(tileBoundary);
foreach (GeoDataObject* object, m_objects) {
GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>(object);
foreach (GeoDataPlacemark* placemark, m_placemarks) {
if(tileBoundary.intersects(placemark->geometry()->latLonAltBox())) {
......
......@@ -45,9 +45,7 @@ void WayConcatenator::process()
qint64 placemarkCount = 0;
// qDebug()<<"** Number of TagFiletered placemarks "<< m_objects.size();
foreach (GeoDataObject *object, m_objects) {
GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(object);
foreach (GeoDataPlacemark* placemark, m_placemarks) {
qDebug()<<" ";
++placemarkCount;
// qDebug()<<"No."<<plcCount;
......@@ -108,7 +106,7 @@ void WayConcatenator::process()
// qDebug()<< "Both* Both chunks found, concatenating to it";
if(chunk == otherChunk){
qDebug()<<"#### Both the chunks are same, directly adding to the list of placemarks";
m_placemarks.append(*placemark);
m_wayPlacemarks.append(*placemark);
} else {
concatBoth(placemark, chunk, otherChunk);
++count;
......@@ -137,10 +135,10 @@ void WayConcatenator::process()
// if(flag){
// qDebug()<<" Concat not possible";
// m_placemarks.append(*placemark);
// m_wayPlacemarks.append(*placemark);
// }
} else{
m_placemarks.append(*placemark);
m_wayPlacemarks.append(*placemark);
}
}
......@@ -158,11 +156,10 @@ void WayConcatenator::process()
void WayConcatenator::addRejectedPlacemarks()
{
QList<GeoDataObject*>::const_iterator itr = rejectedObjectsBegin();
QList<GeoDataObject*>::const_iterator endItr = rejectedObjectsEnd();
QVector<GeoDataPlacemark*>::const_iterator itr = rejectedObjectsBegin();
QVector<GeoDataPlacemark*>::const_iterator endItr = rejectedObjectsEnd();
for (; itr != endItr; ++itr) {
GeoDataPlacemark *placemark = static_cast<GeoDataPlacemark*>(*itr);
m_placemarks.append(*placemark);
m_wayPlacemarks << **itr;
}
}
......@@ -180,7 +177,7 @@ void WayConcatenator::addWayChunks()
chunkSet.insert(*itr);
GeoDataPlacemark* placemark = (*itr)->merge();
if (placemark) {
m_placemarks.append(*placemark);
m_wayPlacemarks.append(*placemark);
totalSize += (*itr)->size();
qDebug()<<"Chunk:";
(*itr)->printIds();
......@@ -199,9 +196,9 @@ void WayConcatenator::addWayChunks()
void WayConcatenator::modifyDocument()
{
m_document->clear();
QList<GeoDataPlacemark>::iterator itr;
itr = m_placemarks.begin();
for (; itr != m_placemarks.end(); ++itr) {
QVector<GeoDataPlacemark>::iterator itr;
itr = m_wayPlacemarks.begin();
for (; itr != m_wayPlacemarks.end(); ++itr) {
GeoDataPlacemark *placemark = new GeoDataPlacemark(*itr);
m_document->append(placemark);
}
......
......@@ -27,7 +27,7 @@ public:
private:
QMultiHash<qint64, WayChunk*> m_hash;
QVector<WayChunk*> m_chunks;
QList<GeoDataPlacemark> m_placemarks;
QVector<GeoDataPlacemark> m_wayPlacemarks;
void createWayChunk(GeoDataPlacemark *placemark, qint64 firstId, qint64 lastId);
WayChunk* getWayChunk(GeoDataPlacemark *placemark, qint64 matchId);
void concatFirst(GeoDataPlacemark *placemark, WayChunk *chunk);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment