diff --git a/src/apps/marble-kde/KdeMainWindow.h b/src/apps/marble-kde/KdeMainWindow.h --- a/src/apps/marble-kde/KdeMainWindow.h +++ b/src/apps/marble-kde/KdeMainWindow.h @@ -41,6 +41,7 @@ public slots: void setMapTitle(); void changeViewSize( QAction* ); + void updateCenterFromTheme(); protected: void closeEvent( QCloseEvent *event ); diff --git a/src/apps/marble-kde/KdeMainWindow.cpp b/src/apps/marble-kde/KdeMainWindow.cpp --- a/src/apps/marble-kde/KdeMainWindow.cpp +++ b/src/apps/marble-kde/KdeMainWindow.cpp @@ -71,6 +71,9 @@ connect( marbleWidget(), SIGNAL(themeChanged(QString)), this, SLOT(setMapTitle())); + connect( marbleWidget(), SIGNAL(themeChanged(QString)), + this, SLOT(updateCenterFromTheme())); + } MainWindow::~MainWindow() @@ -97,6 +100,21 @@ } } +void MainWindow::updateCenterFromTheme() +{ + //A scene provider may provide only a subset of the globe, use scene properties read from a dgml as a starting point + GeoSceneDocument * theme = m_controlView->marbleModel()->mapTheme(); + if (theme) { + const GeoSceneMap* map = theme->map(); + if (map) { + const QVariantList lonLat = map->center(); + if (! lonLat.empty()) { + m_controlView->marbleWidget()->centerOn( lonLat.at(0).toDouble(), lonLat.at(1).toDouble() ); + } + } + } +} + void MainWindow::changeViewSize( QAction* action ) { mDebug()<marbleModel(), SIGNAL(themeChanged(QString)), this, SLOT(updateApplicationTitle(QString))); + connect(m_controlView->marbleModel(), SIGNAL(themeChanged(QString)), + this, SLOT(updateCenterFromTheme())); + connect( m_controlView, SIGNAL(showMapWizard()), this, SLOT(showMapWizard()) ); connect( m_controlView, SIGNAL(mapThemeDeleted()), this, SLOT(fallBackToDefaultTheme()) ); @@ -1626,6 +1631,22 @@ } } +void MainWindow::updateCenterFromTheme() +{ + //A scene provider may provide only a subset of the globe, use scene properties read from a dgml as a starting point + GeoSceneDocument * theme = m_controlView->marbleModel()->mapTheme(); + if (theme) { + const GeoSceneMap* map = theme->map(); + if (map) { + const QVariantList lonLat = map->center(); + if (! lonLat.empty()) { + qDebug() << __FUNCTION__ << " lonlat:" << QString::number(lonLat.at(0).toDouble()) << "," << QString::number(lonLat.at(1).toDouble()) ; + m_controlView->marbleWidget()->centerOn( lonLat.at(0).toDouble(), lonLat.at(1).toDouble() ); + } + } + } +} + void MainWindow::showMapWizard() { QPointer mapWizard = new MapWizard(); @@ -1686,5 +1707,4 @@ m_savedSize.setHeight( -1 ); } } - #include "moc_QtMainWindow.cpp" diff --git a/src/lib/marble/geodata/CMakeLists.txt b/src/lib/marble/geodata/CMakeLists.txt --- a/src/lib/marble/geodata/CMakeLists.txt +++ b/src/lib/marble/geodata/CMakeLists.txt @@ -143,6 +143,7 @@ geodata/handlers/dgml/DgmlThemeTagHandler.h geodata/handlers/dgml/DgmlSettingsTagHandler.h geodata/handlers/dgml/DgmlDescriptionTagHandler.h + geodata/handlers/dgml/DgmlCenterTagHandler.h geodata/handlers/dgml/DgmlBrushTagHandler.cpp geodata/handlers/dgml/DgmlSectionTagHandler.h geodata/handlers/dgml/DgmlTextureTagHandler.h @@ -162,6 +163,7 @@ geodata/handlers/dgml/DgmlTileSizeTagHandler.cpp geodata/handlers/dgml/DgmlTextureTagHandler.cpp geodata/handlers/dgml/DgmlPenTagHandler.cpp + geodata/handlers/dgml/DgmlCenterTagHandler.cpp geodata/handlers/dgml/DgmlDescriptionTagHandler.cpp geodata/handlers/dgml/DgmlElementDictionary.h geodata/handlers/dgml/DgmlIconTagHandler.cpp diff --git a/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.h b/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.h new file mode 100644 --- /dev/null +++ b/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2015 Boris Shtrasman + + This file is part of the KDE project + + This library is free software you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef MARBLE_DGML_CENTERTAGHANDLER_H +#define MARBLE_DGML_CENTERTAGHANDLER_H + +#include "GeoTagHandler.h" + +namespace Marble +{ +namespace dgml +{ + +class DgmlCenterTagHandler : public GeoTagHandler +{ +public: + virtual GeoNode* parse(GeoParser&) const; +}; + +} +} + +#endif diff --git a/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.cpp b/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.cpp new file mode 100644 --- /dev/null +++ b/src/lib/marble/geodata/handlers/dgml/DgmlCenterTagHandler.cpp @@ -0,0 +1,48 @@ +/* + Copyright (C) 2015 Boris Shtrasman + + This file is part of the KDE project + + This library is free software you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "DgmlCenterTagHandler.h" + +#include "DgmlElementDictionary.h" +#include "GeoParser.h" +#include "GeoSceneMap.h" + +namespace Marble +{ +namespace dgml +{ +DGML_DEFINE_TAG_HANDLER(Center) + +GeoNode* DgmlCenterTagHandler::parse(GeoParser& parser) const +{ + // Check whether the tag is valid + Q_ASSERT(parser.isStartElement() && parser.isValidElement(dgmlTag_Center)); + + // Checking for parent item + GeoStackItem parentItem = parser.parentElement(); + if (parentItem.represents(dgmlTag_Map)) + parentItem.nodeAs()->setCenter( parser.readElementText().trimmed() ); + + return 0; +} + +} +} diff --git a/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.h b/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.h --- a/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.h +++ b/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.h @@ -36,6 +36,7 @@ extern const char* dgmlTag_Available; extern const char* dgmlTag_Blending; extern const char* dgmlTag_Brush; + extern const char* dgmlTag_Center; extern const char* dgmlTag_Color; extern const char* dgmlTag_CustomPlugin; extern const char* dgmlTag_Dem; diff --git a/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.cpp b/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.cpp --- a/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.cpp +++ b/src/lib/marble/geodata/handlers/dgml/DgmlElementDictionary.cpp @@ -34,6 +34,7 @@ const char* dgmlTag_Blending = "blending"; const char* dgmlTag_Brush = "brush"; const char* dgmlTag_Color = "color"; +const char* dgmlTag_Center = "center"; const char* dgmlTag_CustomPlugin = "customplugin"; const char* dgmlTag_Dem = "dem"; const char* dgmlTag_Description = "description"; diff --git a/src/lib/marble/geodata/scene/GeoSceneMap.h b/src/lib/marble/geodata/scene/GeoSceneMap.h --- a/src/lib/marble/geodata/scene/GeoSceneMap.h +++ b/src/lib/marble/geodata/scene/GeoSceneMap.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -64,7 +65,17 @@ * @param section The new layer */ void addLayer( GeoSceneLayer* ); - + /** + * @ brief Set starting center with lon lat cooredinates + * used if a scene downloadUrl do not handle elements in other locations + */ + void setCenter(const QString & coordinateString); + /** + * @breif Get starting center with cooredinates + * used if a scene downloadUrl do not handle elements in other locations + * return A QVariantList of lon lat as specified in the dgml + */ + QVariantList center() const; /** * @brief Return a layer by its name * @param name The name of the layer diff --git a/src/lib/marble/geodata/scene/GeoSceneMap.cpp b/src/lib/marble/geodata/scene/GeoSceneMap.cpp --- a/src/lib/marble/geodata/scene/GeoSceneMap.cpp +++ b/src/lib/marble/geodata/scene/GeoSceneMap.cpp @@ -26,6 +26,8 @@ #include "GeoSceneFilter.h" #include "DgmlAuxillaryDictionary.h" +#include + namespace Marble { @@ -50,6 +52,8 @@ return GeoSceneTypes::GeoSceneMapType; } + QVariantList m_center; + /// The vector holding all the sections in the legend. /// (We want to preserve the order and don't care /// much about speed here), so we don't use a hash @@ -166,6 +170,24 @@ } } +QVariantList GeoSceneMap::center() const +{ + return d->m_center; +} + +void GeoSceneMap::setCenter(const QString & coordinatesString) +{ + bool success = false; + const GeoDataCoordinates coordinates = GeoDataCoordinates::fromString(coordinatesString, success); + + if ( success ) { + QVariantList lonLat; + lonLat << QVariant( coordinates.longitude(GeoDataCoordinates::Degree) ) + << QVariant( coordinates.latitude(GeoDataCoordinates::Degree) ); + d->m_center = lonLat; + } +} + GeoSceneFilter* GeoSceneMap::filter( const QString& name ) { GeoSceneFilter* filter = 0;