[Marble-commits] KDE/kdeedu/marble/src/lib

Thibaut Gridel tgridel at free.fr
Sat Jan 15 14:34:23 CET 2011


SVN commit 1214587 by tgridel:

PlacemarkManager: get rid of PlacemarkManager

 M  +0 -1      CMakeLists.txt  
 M  +263 -0    FileLoader.cpp  
 M  +6 -0      FileLoader.h  
 M  +0 -8      MarbleModel.cpp  
 M  +0 -1      MarbleRunnerManager.cpp  
 D             PlacemarkManager.cpp  
 D             PlacemarkManager.h  


--- trunk/KDE/kdeedu/marble/src/lib/CMakeLists.txt #1214586:1214587
@@ -116,7 +116,6 @@
     MeasureTool.cpp
     ImageLoadThread.cpp
     VisiblePlacemark.cpp
-    PlacemarkManager.cpp
     PlacemarkLayout.cpp
     PlacemarkPainter.cpp
     PlacemarkInfoDialog.cpp
--- trunk/KDE/kdeedu/marble/src/lib/FileLoader.cpp #1214586:1214587
@@ -22,6 +22,8 @@
 #include "GeoDataPlacemark.h"
 #include "GeoDataData.h"
 #include "GeoDataExtendedData.h"
+#include "GeoDataStyleMap.h"
+#include "GeoDataTypes.h"
 #include "MarbleDirs.h"
 #include "MarbleDebug.h"
 
@@ -169,6 +171,7 @@
 
     m_document = static_cast<GeoDataDocument*>( document );
     m_document->setFileName( m_filepath );
+    setupStyle( m_document, m_document );
 
     file.close();
 
@@ -194,6 +197,7 @@
 
     m_document = static_cast<GeoDataDocument*>( document );
     m_document->setFileName( m_filepath );
+    setupStyle( m_document, m_document );
 
     buffer.close();
 
@@ -274,6 +278,8 @@
     }
 
     m_document->setVisible( false );
+    setupStyle( m_document, m_document );
+    createFilterProperties( m_document );
     return true;
 }
 
@@ -384,5 +390,262 @@
 
 }
 
+void FileLoader::setupStyle( GeoDataDocument *doc, GeoDataContainer *container )
+{
+    QVector<GeoDataFeature*>::Iterator i = container->begin();
+    QVector<GeoDataFeature*>::Iterator const end = container->end();
+    for (; i != end; ++i ) {
+        if ( (*i)->nodeType() == GeoDataTypes::GeoDataFolderType
+             || (*i)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+            GeoDataContainer *child = static_cast<GeoDataContainer*>( *i );
+            setupStyle( doc, child );
+        } else {
+            GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>( *i );
+
+            QString styleUrl = placemark->styleUrl().remove('#');
+            if ( ! styleUrl.isEmpty() )
+            {
+                const GeoDataStyleMap& styleMap = doc->styleMap( styleUrl );
+                /// hard coded to use only the "normal" style
+                if( !styleMap.value( QString( "normal" ) ).isEmpty() ) {
+                    styleUrl = styleMap.value( QString( "normal" ) );
+                }
+                styleUrl.remove( '#' );
+                placemark->setStyle( &doc->style( styleUrl ) );
+            }
+        }
+    }
+}
+
+void FileLoader::createFilterProperties( GeoDataContainer *container )
+{
+
+    QVector<GeoDataFeature*>::Iterator i = container->begin();
+    QVector<GeoDataFeature*>::Iterator const end = container->end();
+    for (; i != end; ++i ) {
+        if ( (*i)->nodeType() == GeoDataTypes::GeoDataFolderType
+             || (*i)->nodeType() == GeoDataTypes::GeoDataDocumentType ) {
+            GeoDataContainer *child = static_cast<GeoDataContainer*>( *i );
+            createFilterProperties( child );
+        } else {
+            GeoDataPlacemark* placemark = static_cast<GeoDataPlacemark*>( *i );
+
+            bool hasPopularity = false;
+
+            // Mountain (H), Volcano (V), Shipwreck (W)
+            if ( placemark->role() == "H" || placemark->role() == "V" || placemark->role() == "W" )
+            {
+                qreal altitude = placemark->coordinate().altitude();
+                if ( altitude != 0.0 )
+                {
+                    hasPopularity = true;
+                    placemark->setPopularity( (qint64)(altitude * 1000.0) );
+                    placemark->setPopularityIndex( cityPopIdx( qAbs( (qint64)(altitude * 1000.0) ) ) );
+                }
+            }
+            // Continent (K), Ocean (O), Nation (S)
+            else if ( placemark->role() == "K" || placemark->role() == "O" || placemark->role() == "S" )
+            {
+                qreal area = placemark->area();
+                if ( area >= 0.0 )
+                {
+                    hasPopularity = true;
+                    //                mDebug() << placemark->name() << " " << (qint64)(area);
+                    placemark->setPopularity( (qint64)(area * 100) );
+                    placemark->setPopularityIndex( areaPopIdx( area ) );
+                }
+            }
+            // Pole (P)
+            else if ( placemark->role() == "P" )
+            {
+                placemark->setPopularity( 1000000000 );
+                placemark->setPopularityIndex( 18 );
+            }
+            // Magnetic Pole (M)
+            else if ( placemark->role() == "M" )
+            {
+                placemark->setPopularity( 10000000 );
+                placemark->setPopularityIndex( 13 );
+            }
+            // MannedLandingSite (h)
+            else if ( placemark->role() == "h" )
+            {
+                placemark->setPopularity( 1000000000 );
+                placemark->setPopularityIndex( 18 );
+            }
+            // RoboticRover (r)
+            else if ( placemark->role() == "r" )
+            {
+                placemark->setPopularity( 10000000 );
+                placemark->setPopularityIndex( 16 );
+            }
+            // UnmannedSoftLandingSite (u)
+            else if ( placemark->role() == "u" )
+            {
+                placemark->setPopularity( 1000000 );
+                placemark->setPopularityIndex( 14 );
+            }
+            // UnmannedSoftLandingSite (i)
+            else if ( placemark->role() == "i" )
+            {
+                placemark->setPopularity( 1000000 );
+                placemark->setPopularityIndex( 14 );
+            }
+            // Space Terrain: Craters, Maria, Montes, Valleys, etc.
+            else if (    placemark->role() == "m" || placemark->role() == "v"
+                         || placemark->role() == "o" || placemark->role() == "c"
+                         || placemark->role() == "a" )
+            {
+                qint64 diameter = placemark->population();
+                if ( diameter >= 0 )
+                {
+                    hasPopularity = true;
+                    placemark->setPopularity( diameter );
+                    if ( placemark->role() == "c" ) {
+                        placemark->setPopularityIndex( spacePopIdx( diameter ) );
+                        if ( placemark->name() == "Tycho" || placemark->name() == "Copernicus" ) {
+                            placemark->setPopularityIndex( 17 );
+                        }
+                    }
+                    else {
+                        placemark->setPopularityIndex( spacePopIdx( diameter ) );
+                    }
+
+                    if ( placemark->role() == "a" && diameter == 0 ) {
+                        placemark->setPopularity( 1000000000 );
+                        placemark->setPopularityIndex( 18 );
+                    }
+                }
+            }
+            else
+            {
+                qint64 population = placemark->population();
+                if ( population >= 0 )
+                {
+                    hasPopularity = true;
+                    placemark->setPopularity( population );
+                    placemark->setPopularityIndex( cityPopIdx( population ) );
+                }
+            }
+
+            //  Then we set the visual category:
+
+            if ( placemark->role() == "H" )      placemark->setVisualCategory( GeoDataPlacemark::Mountain );
+            else if ( placemark->role() == "V" ) placemark->setVisualCategory( GeoDataPlacemark::Volcano );
+
+            else if ( placemark->role() == "m" ) placemark->setVisualCategory( GeoDataPlacemark::Mons );
+            else if ( placemark->role() == "v" ) placemark->setVisualCategory( GeoDataPlacemark::Valley );
+            else if ( placemark->role() == "o" ) placemark->setVisualCategory( GeoDataPlacemark::OtherTerrain );
+            else if ( placemark->role() == "c" ) placemark->setVisualCategory( GeoDataPlacemark::Crater );
+            else if ( placemark->role() == "a" ) placemark->setVisualCategory( GeoDataPlacemark::Mare );
+
+            else if ( placemark->role() == "P" ) placemark->setVisualCategory( GeoDataPlacemark::GeographicPole );
+            else if ( placemark->role() == "M" ) placemark->setVisualCategory( GeoDataPlacemark::MagneticPole );
+            else if ( placemark->role() == "W" ) placemark->setVisualCategory( GeoDataPlacemark::ShipWreck );
+            else if ( placemark->role() == "F" ) placemark->setVisualCategory( GeoDataPlacemark::AirPort );
+            else if ( placemark->role() == "A" ) placemark->setVisualCategory( GeoDataPlacemark::Observatory );
+            else if ( placemark->role() == "K" ) placemark->setVisualCategory( GeoDataPlacemark::Continent );
+            else if ( placemark->role() == "O" ) placemark->setVisualCategory( GeoDataPlacemark::Ocean );
+            else if ( placemark->role() == "S" ) placemark->setVisualCategory( GeoDataPlacemark::Nation );
+            else
+                if ( placemark->role()=="PPL" ) placemark->setVisualCategory(
+                        ( ( GeoDataPlacemark::GeoDataVisualCategory )( (int)( GeoDataPlacemark::SmallCity )
+                                                                       + ( placemark->popularityIndex() -1 ) / 4 * 4 ) ) );
+            else if ( placemark->role() == "PPLA" ) placemark->setVisualCategory(
+                    ( ( GeoDataPlacemark::GeoDataVisualCategory )( (int)( GeoDataPlacemark::SmallStateCapital )
+                                                                   + ( placemark->popularityIndex() -1 ) / 4 * 4 ) ) );
+            else if ( placemark->role()=="PPLC" ) placemark->setVisualCategory(
+                    ( ( GeoDataPlacemark::GeoDataVisualCategory )( (int)( GeoDataPlacemark::SmallNationCapital )
+                                                                   + ( placemark->popularityIndex() -1 ) / 4 * 4 ) ) );
+            else if ( placemark->role()=="PPLA2" || placemark->role()=="PPLA3" ) placemark->setVisualCategory(
+                    ( ( GeoDataPlacemark::GeoDataVisualCategory )( (int)( GeoDataPlacemark::SmallCountyCapital )
+                                                                   + ( placemark->popularityIndex() -1 ) / 4 * 4 ) ) );
+            else if ( placemark->role()==" " && !hasPopularity && placemark->visualCategory() == GeoDataPlacemark::Unknown ) {
+                placemark->setVisualCategory( GeoDataPlacemark::Unknown ); // default location
+                placemark->setPopularityIndex(0);
+            }
+            else if ( placemark->role() == "h" ) placemark->setVisualCategory( GeoDataPlacemark::MannedLandingSite );
+            else if ( placemark->role() == "r" ) placemark->setVisualCategory( GeoDataPlacemark::RoboticRover );
+            else if ( placemark->role() == "u" ) placemark->setVisualCategory( GeoDataPlacemark::UnmannedSoftLandingSite );
+            else if ( placemark->role() == "i" ) placemark->setVisualCategory( GeoDataPlacemark::UnmannedHardLandingSite );
+
+            if ( placemark->role() == "W" && placemark->popularityIndex() > 12 )
+                placemark->setPopularityIndex( 12 );
+            if ( placemark->role() == "O" )
+                placemark->setPopularityIndex( 16 );
+            if ( placemark->role() == "K" )
+                placemark->setPopularityIndex( 19 );
+            if ( !placemark->isVisible() ) {
+                placemark->setPopularityIndex( -1 );
+            }
+            // Workaround: Emulate missing "setVisible" serialization by allowing for population
+            // values smaller than -1 which are considered invisible.
+            if ( placemark->population() < -1 ) {
+                placemark->setPopularityIndex( -1 );
+            }
+        }
+    }
+}
+
+int FileLoader::cityPopIdx( qint64 population ) const
+{
+    int popidx = 15;
+
+    if ( population < 2500 )        popidx=1;
+    else if ( population < 5000)    popidx=2;
+    else if ( population < 7500)    popidx=3;
+    else if ( population < 10000)   popidx=4;
+    else if ( population < 25000)   popidx=5;
+    else if ( population < 50000)   popidx=6;
+    else if ( population < 75000)   popidx=7;
+    else if ( population < 100000)  popidx=8;
+    else if ( population < 250000)  popidx=9;
+    else if ( population < 500000)  popidx=10;
+    else if ( population < 750000)  popidx=11;
+    else if ( population < 1000000) popidx=12;
+    else if ( population < 2500000) popidx=13;
+    else if ( population < 5000000) popidx=14;
+
+    return popidx;
+}
+
+int FileLoader::spacePopIdx( qint64 population ) const
+{
+    int popidx = 18;
+
+    if ( population < 1000 )        popidx=1;
+    else if ( population < 2000)    popidx=2;
+    else if ( population < 4000)    popidx=3;
+    else if ( population < 6000)    popidx=4;
+    else if ( population < 8000)    popidx=5;
+    else if ( population < 10000)   popidx=6;
+    else if ( population < 20000)   popidx=7;
+
+    else if ( population < 40000  )  popidx=8;
+    else if ( population < 60000)    popidx=9;
+    else if ( population < 80000  )  popidx=10;
+    else if ( population < 100000)   popidx=11;
+    else if ( population < 200000 )  popidx=13;
+    else if ( population < 400000 )  popidx=15;
+    else if ( population < 600000 )  popidx=17;
+
+    return popidx;
+}
+
+int FileLoader::areaPopIdx( qreal area ) const
+{
+    int popidx = 17;
+    if      ( area <  200000  )      popidx=11;
+    else if ( area <  400000  )      popidx=12;
+    else if ( area < 1000000  )      popidx=13;
+    else if ( area < 2500000  )      popidx=14;
+    else if ( area < 5000000  )      popidx=15;
+    else if ( area < 10000000 )      popidx=16;
+
+    return popidx;
+}
+
+
+
 #include "FileLoader.moc"
 } // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/FileLoader.h #1214586:1214587
@@ -40,6 +40,12 @@
         void savePlacemarks(QDataStream &out, const GeoDataContainer *container);
         void loadPntFile( const QString &fileName );
 
+        void setupStyle( GeoDataDocument *doc, GeoDataContainer *container );
+        void createFilterProperties( GeoDataContainer *container );
+        int cityPopIdx( qint64 population ) const;
+        int spacePopIdx( qint64 population ) const;
+        int areaPopIdx( qreal area ) const;
+
         QString m_filepath;
         QString m_contents;
         GeoDataDocument *m_document;
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1214586:1214587
@@ -54,7 +54,6 @@
 #include "MarbleDirs.h"
 #include "FileManager.h"
 #include "GeoDataTreeModel.h"
-#include "PlacemarkManager.h"
 #include "Planet.h"
 #include "PluginManager.h"
 #include "StoragePolicy.h"
@@ -89,7 +88,6 @@
                                                                    MarbleDirs::localPath() ),
                                                       m_pluginManager ) ),
           m_fileManager( 0 ),
-          m_placemarkmanager( 0 ),
           m_placemarkselectionmodel( 0 ),
           m_positionTracking( 0 ),
           m_bookmarkManager( 0 ),
@@ -130,7 +128,6 @@
 
     // Places on the map
     FileManager             *m_fileManager;
-    PlacemarkManager        *m_placemarkmanager;
 
     // Selection handling
     QItemSelectionModel      m_placemarkselectionmodel;
@@ -173,11 +170,7 @@
     d->m_fileManager = new FileManager();
     d->m_fileManager->setDataFacade(d->m_dataFacade);
 
-    d->m_placemarkmanager = new PlacemarkManager();
-    d->m_placemarkmanager->setDataFacade(d->m_dataFacade);
-    d->m_placemarkmanager->setFileManager(d->m_fileManager);
 
-
     d->m_positionTracking = new PositionTracking( d->m_fileManager, this );
 
     d->m_routingManager = new RoutingManager( d->m_parent, this );
@@ -195,7 +188,6 @@
     delete d->m_positionTracking;
     delete d->m_bookmarkManager;
 
-    delete d->m_placemarkmanager;
     delete d->m_fileManager;
     delete d->m_mapTheme;
     delete d->m_dataFacade;
--- trunk/KDE/kdeedu/marble/src/lib/MarbleRunnerManager.cpp #1214586:1214587
@@ -13,7 +13,6 @@
 #include "MarblePlacemarkModel.h"
 #include "MarbleDebug.h"
 #include "MarbleModel.h"
-#include "PlacemarkManager.h"
 #include "Planet.h"
 #include "GeoDataPlacemark.h"
 #include "PluginManager.h"


More information about the Marble-commits mailing list