Fixed reading the initial coordinate from the settings
[situare] / src / map / mapengine.cpp
index 8b2f972..beb6858 100644 (file)
@@ -111,10 +111,6 @@ MapEngine::~MapEngine()
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    // register meta type for custom GeoCoordinate class so that saving the settings does work
-    qRegisterMetaType<GeoCoordinate>("GeoCoordinate");
-    qRegisterMetaTypeStreamOperators<GeoCoordinate>("GeoCoordinate");
-
     settings.setValue(MAP_LAST_POSITION, QVariant::fromValue(centerGeoCoordinate()));
     settings.setValue(MAP_LAST_ZOOMLEVEL, m_zoomLevel);
 }
@@ -312,17 +308,19 @@ void MapEngine::init()
 
     // init can be only done if both values exists in the settings
     if (settings.contains(MAP_LAST_POSITION) && settings.contains(MAP_LAST_ZOOMLEVEL)) {
-        qWarning() << __PRETTY_FUNCTION__ << "both settings found";
         QVariant zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL);
         QVariant location = settings.value(MAP_LAST_POSITION);
-        // init can be only done if we are able to convert variants into target data types
+
+        // also the init can be only done if we are able to convert variants into target data types
         if (zoomLevel.canConvert<int>() && location.canConvert<GeoCoordinate>()) {
-            qWarning() << __PRETTY_FUNCTION__ << "both settings can be converted";
             m_zoomLevel = zoomLevel.toInt();
             m_sceneCoordinate = SceneCoordinate(location.value<GeoCoordinate>());
         }
     }
 
+    // emit zoom level and center coordinate so that all parts of the map system gets initialized
+    // NOTE: emit is also done even if we weren't able to read initial valuef from the settings
+    //       so that the default values set in the constructor are used
     emit zoomLevelChanged(m_zoomLevel);
     scrollToPosition(m_sceneCoordinate);
 }