[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/marble
From:       Inge Wallin <inge () lysator ! liu ! se>
Date:       2007-04-23 22:37:25
Message-ID: 1177367845.615382.14134.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 657392 by ingwa:

Cleaned class PlaceMarkManager

 M  +3 -0      ChangeLog  
 M  +1 -1      src/CLEANING  
 M  +161 -139  src/placemarkmanager.cpp  
 M  +19 -12    src/placemarkmanager.h  


--- trunk/playground/base/marble/ChangeLog #657391:657392
@@ -1,3 +1,6 @@
+23.04.07 - ingwa
+	Cleaned placemarkmanager.{h,cpp}
+	
 22.04.07 - ingwa
 	Cleaned placemark.{h,cpp}
 	Cleaned placecontainer.{h,cpp}
--- trunk/playground/base/marble/src/CLEANING #657391:657392
@@ -26,6 +26,7 @@
 
 placemark.h             placemark.cpp
 placecontainer.h        placecontainer.cpp
+placemarkmanager.h      placemarkmanager.cpp
 
 Model/View:
 -----------
@@ -58,7 +59,6 @@
 katlasviewpopupmenu.h   katlasviewpopupmenu.cpp
 maptheme.h              maptheme.cpp
 measuretool.h           measuretool.cpp
-placemarkmanager.h      placemarkmanager.cpp
 placemarkmodel.h        placemarkmodel.cpp
 placemarkpainter.h      placemarkpainter.cpp
 texcolorizer.h          texcolorizer.cpp
--- trunk/playground/base/marble/src/placemarkmanager.cpp #657391:657392
@@ -1,193 +1,215 @@
 #include "placemarkmanager.h"
 
 #include <QtCore/QDebug>
-
 #include <QtCore/QDataStream>
 #include <QtCore/QDateTime>
 #include <QtXml/QXmlInputSource>
 #include <QtXml/QXmlSimpleReader>
+
 #include "xmlhandler.h"
 
-PlaceMarkManager::PlaceMarkManager(){
-	m_placecontainer = new PlaceContainer(); 
 
-	addPlaceMarkFile("cityplacemarks");
-	addPlaceMarkFile("baseplacemarks");
-	addPlaceMarkFile("elevplacemarks");
+PlaceMarkManager::PlaceMarkManager()
+{
+    m_placecontainer = new PlaceContainer(); 
+
+    addPlaceMarkFile( "cityplacemarks" );
+    addPlaceMarkFile( "baseplacemarks" );
+    addPlaceMarkFile( "elevplacemarks" );
 }
 
-void PlaceMarkManager::addPlaceMarkFile( QString filepath ){
 
-	QString defaultcachename, defaultsrcname, defaulthomecache;
+void PlaceMarkManager::addPlaceMarkFile( QString filepath )
+{
 
-	if ( !filepath.contains("\\" && !filepath.contains("/")) ){
-		defaultcachename = KAtlasDirs::path( "placemarks/" + filepath + ".cache" );
-		defaultsrcname = KAtlasDirs::path( "placemarks/" + filepath + ".kml");
-		defaulthomecache = KAtlasDirs::localDir() + "/placemarks/" + filepath + ".cache";
-	}
-	else return;
+    QString  defaultcachename;
+    QString  defaultsrcname;
+    QString  defaulthomecache;
 
-	if ( QFile::exists( defaultcachename ) ){
-		qDebug() << "Loading Default Placemark Cache File:" + defaultcachename;
+    if ( !filepath.contains( "\\" && !filepath.contains( "/" ) ) ) {
+        defaultcachename = KAtlasDirs::path( "placemarks/" + filepath + ".cache" );
+        defaultsrcname   = KAtlasDirs::path( "placemarks/" + filepath + ".kml");
+        defaulthomecache = KAtlasDirs::localDir() + "/placemarks/" + filepath + ".cache";
+    }
+    else 
+        return;
 
-		bool cacheoutdated = false;
-		QDateTime sourceLastModified, cacheLastModified;
+    if ( QFile::exists( defaultcachename ) ) {
+        qDebug() << "Loading Default Placemark Cache File:" + defaultcachename;
 
-		if ( QFile::exists( defaultsrcname ) ){
-			sourceLastModified = QFileInfo( defaultsrcname ).lastModified();
-			cacheLastModified = QFileInfo( defaultcachename ).lastModified();
+        bool       cacheoutdated = false;
+        QDateTime  sourceLastModified;
+        QDateTime  cacheLastModified;
 
-			if ( cacheLastModified < sourceLastModified )
-				cacheoutdated = true;
-		}
+        if ( QFile::exists( defaultsrcname ) ) {
+            sourceLastModified = QFileInfo( defaultsrcname ).lastModified();
+            cacheLastModified  = QFileInfo( defaultcachename ).lastModified();
+
+            if ( cacheLastModified < sourceLastModified )
+                cacheoutdated = true;
+        }
 			
-		bool loadok = false; 
+        bool  loadok = false; 
 
-		if ( cacheoutdated == false )
-			loadok = loadFile( defaultcachename, m_placecontainer );
+        if ( cacheoutdated == false )
+            loadok = loadFile( defaultcachename, m_placecontainer );
 
-		if ( loadok == true ) return;
-	}
+        if ( loadok == true )
+            return;
+    }
 
-	qDebug("No recent Default Placemark Cache File available!");
+    qDebug( "No recent Default Placemark Cache File available!" );
 
-	if ( QFile::exists( defaultsrcname ) ){
-		PlaceContainer* importcontainer = new PlaceContainer();
-		importKml( defaultsrcname, importcontainer );
-		saveFile( defaulthomecache, importcontainer );
-		*m_placecontainer << *importcontainer;
-	}
-	else {
-		qDebug() << "No Default Placemark Source File!";
-	}
+    if ( QFile::exists( defaultsrcname ) ) {
+        PlaceContainer  *importcontainer = new PlaceContainer();
+
+        importKml( defaultsrcname, importcontainer );
+        saveFile( defaulthomecache, importcontainer );
+
+        *m_placecontainer << *importcontainer;
+    }
+    else {
+        qDebug() << "No Default Placemark Source File!";
+    }
 }
 
-void PlaceMarkManager::loadKml( QString filename ){ 
 
-// this still is buggy and needs a lot of work as does the concept as a whole ...
+void PlaceMarkManager::loadKml( QString filename )
+{
+    // This still is buggy and needs a lot of work as does the concept
+    // as a whole ...
 
-//	PlaceContainer* tmp = m_placecontainer;
-	m_placecontainer -> clear();
-//	tmp -> deleteAll();
-//	delete tmp;
+    // PlaceContainer* tmp = m_placecontainer;
+    m_placecontainer -> clear();
+    // tmp -> deleteAll();
+    // delete tmp;
 
-	importKml( filename, m_placecontainer );
+    importKml( filename, m_placecontainer );
 }
 
-void PlaceMarkManager::importKml( QString filename, PlaceContainer* placecontainer ){ 
+void PlaceMarkManager::importKml( QString filename, PlaceContainer* placecontainer )
+{
 
-	KAtlasXmlHandler handler( placecontainer );
+    KAtlasXmlHandler handler( placecontainer );
 
-	QFile file( filename );
+    QFile file( filename );
 
-	// gzip reader:
-/*
-	QDataStream dataIn(&file);
-	QByteArray compByteArray;
-	dataIn >> compByteArray;
-	QByteArray xmlByteArray = qUncompress(compByteArray);
-	QString xmlString = QString::fromUtf8(xmlByteArray.data(), xmlByteArray.size());
-	QXmlInputSource source;
-	source.setData(xmlString);
-*/
-	QXmlInputSource source( &file );
+    // gzip reader:
+#if 0
+      QDataStream dataIn(&file);
+      QByteArray compByteArray;
+      dataIn >> compByteArray;
+      QByteArray xmlByteArray = qUncompress(compByteArray);
+      QString xmlString = QString::fromUtf8(xmlByteArray.data(), xmlByteArray.size());
+      QXmlInputSource source;
+      source.setData(xmlString);
+#endif
+    QXmlInputSource   source( &file );
 
-	QXmlSimpleReader reader;
-	reader.setContentHandler( &handler );
-	reader.parse( source );
+    QXmlSimpleReader  reader;
+    reader.setContentHandler( &handler );
+    reader.parse( source );
 }
 
-void PlaceMarkManager::saveFile( QString filename, PlaceContainer* placecontainer ){ 
-
-	if ( QDir( KAtlasDirs::localDir() + "/placemarks/" ).exists() == false ) 
-		( QDir::root() ).mkpath( KAtlasDirs::localDir() + "/placemarks/" );
+void PlaceMarkManager::saveFile( QString filename, PlaceContainer* placecontainer )
+{
+    if ( QDir( KAtlasDirs::localDir() + "/placemarks/" ).exists() == false ) 
+        ( QDir::root() ).mkpath( KAtlasDirs::localDir() + "/placemarks/" );
 	
-	QFile file( filename );
-	file.open(QIODevice::WriteOnly);
-	QDataStream out(&file);
+    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)0x31415926;
-	out << (qint32)004;
+    // Write a header with a "magic number" and a version
+    // out << (quint32)0xA0B0C0D0;
+    out << (quint32)0x31415926;
+    out << (qint32)004;
 
-	out.setVersion(QDataStream::Qt_4_0);
+    out.setVersion(QDataStream::Qt_4_0);
 
-	float lng, lat;
+    float  lng;
+    float  lat;
 
-	PlaceContainer::const_iterator it;
+    PlaceContainer::const_iterator  it;
 
-	for ( it=placecontainer->constBegin(); it != placecontainer->constEnd(); it++ ){ // STL iterators
-		out << (*it) -> name();
-		(*it) -> coordinate(lng, lat);
-		out << lng << lat;
-		out << QString( (*it) -> role() );
-		out << QString( (*it) -> description() );
-		out << QString( (*it) -> countryCode() );
-		out << (qint32)(*it) -> popidx();
-		out << (qint32)(*it) -> symbol();
-		out << (qint32)(*it) -> population();
-	}
+    for ( it=placecontainer->constBegin(); 
+          it != placecontainer->constEnd();
+          it++ )
+    {
+        out << (*it) -> name();
+        (*it) -> coordinate(lng, lat);
 
+        out << lng << lat;
+        out << QString( (*it) -> role() );
+        out << QString( (*it) -> description() );
+        out << QString( (*it) -> countryCode() );
+        out << (qint32)(*it) -> popidx();
+        out << (qint32)(*it) -> symbol();
+        out << (qint32)(*it) -> population();
+    }
 }
 
-bool PlaceMarkManager::loadFile( QString filename, PlaceContainer* placecontainer ){ 
-	QFile file( filename );
-	file.open(QIODevice::ReadOnly);
-	QDataStream in(&file);
 
-	// Read and check the header
-	quint32 magic;
-	in >> magic;
-	if (magic != 0x31415926) {
-		qDebug( "Bad file format!" );
-		return false;
-	}
-	// Read the version
-	qint32 version;
-	in >> version;
-	if (version < 004) {
-		qDebug( "Bad file - too old!" );
-		return false;
-	} 
-/*
-	if (version > 002) {
-		qDebug( "Bad file - too new!" );
-		return;
-	} 
-*/
+bool PlaceMarkManager::loadFile( QString filename, 
+                                 PlaceContainer* placecontainer )
+{
+    QFile  file( filename );
+    file.open(QIODevice::ReadOnly);
+    QDataStream in(&file);
 
-	in.setVersion(QDataStream::Qt_4_0);
+    // Read and check the header
+    quint32 magic;
+    in >> magic;
+    if (magic != 0x31415926) {
+        qDebug( "Bad file format!" );
+        return false;
+    }
+    // Read the version
+    qint32 version;
+    in >> version;
+    if (version < 004) {
+        qDebug( "Bad file - too old!" );
+        return false;
+    } 
+    /*
+      if (version > 002) {
+      qDebug( "Bad file - too new!" );
+      return;
+      } 
+    */
 
-// Read the data
-	float lng, lat;
-	QString tmpstr;
-	qint32 a;
+    in.setVersion(QDataStream::Qt_4_0);
 
-	PlaceMark* mark;
+    // Read the data
+    float    lng;
+    float    lat;
+    QString  tmpstr;
+    qint32   a;
 
-	while (	!in.atEnd() ){
-		mark = new PlaceMark();
+    PlaceMark  *mark;
+
+    while ( !in.atEnd() ) {
+        mark = new PlaceMark();
 		
-		in >> tmpstr;
-		mark -> setName( tmpstr );
-		in >> lng >> lat;
-		mark -> setCoordinate(lng, lat);
-		in >> tmpstr;
-		mark -> setRole( tmpstr.at(0) );
-		in >> tmpstr;
-		mark -> setDescription( tmpstr );
-		in >> tmpstr;
-		mark -> setCountryCode( tmpstr );
-		in >> a;
-		mark -> setPopidx( a );
-		in >> a;
-		mark -> setSymbol( a );
-		in >> a;
-		mark -> setPopulation( a );
+        in >> tmpstr;
+        mark -> setName( tmpstr );
+        in >> lng >> lat;
+        mark -> setCoordinate(lng, lat);
+        in >> tmpstr;
+        mark -> setRole( tmpstr.at(0) );
+        in >> tmpstr;
+        mark -> setDescription( tmpstr );
+        in >> tmpstr;
+        mark -> setCountryCode( tmpstr );
+        in >> a;
+        mark -> setPopidx( a );
+        in >> a;
+        mark -> setSymbol( a );
+        in >> a;
+        mark -> setPopulation( a );
 
-		placecontainer -> append( mark );
-	}
+        placecontainer -> append( mark );
+    }
 
-	return true;
+    return true;
 }
--- trunk/playground/base/marble/src/placemarkmanager.h #657391:657392
@@ -7,33 +7,40 @@
 //
 // Copyright: See COPYING file that comes with this distribution
 
+
 #ifndef PLACEMARKMANAGER_H
 #define PLACEMARKMANAGER_H
 
+
 #include "placecontainer.h"
 #include "katlasdirs.h"
 
+
 /**
 @author Torsten Rahn
 */
 
-class PlaceMarkManager {
-public:
-	PlaceMarkManager();
-	~PlaceMarkManager(){};
+class PlaceMarkManager
+{
+ public:
+    PlaceMarkManager();
+    ~PlaceMarkManager(){};
 
-	void addPlaceMarkFile( QString );
+    void addPlaceMarkFile( QString );
 
-	PlaceContainer* getPlaceContainer(){ m_placecontainer->sort(); return m_placecontainer; }
+    PlaceContainer* getPlaceContainer() {
+        m_placecontainer->sort();
+        return m_placecontainer;
+    }
 
-	void loadKml( QString );
+    void loadKml( QString );
 
-protected:
-	PlaceContainer* m_placecontainer;
+ protected:
+    PlaceContainer  *m_placecontainer;
 
-	void importKml( QString, PlaceContainer* );
-	void saveFile( QString, PlaceContainer* );
-	bool loadFile( QString, PlaceContainer* );
+    void importKml( QString, PlaceContainer* );
+    void saveFile( QString, PlaceContainer* );
+    bool loadFile( QString, PlaceContainer* );
 };
 
 #endif // PLACEMARKMANAGER_H
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic