map loads.

On Fri, Jan 8, 2016 at 5:12 PM, Tomaz Canabrava <[email protected]> wrote:

>
>
From e9d414d880a25e7a807675e3b07b2f135bc21e7a Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 8 Jan 2016 19:04:56 -0200
Subject: [PATCH 4/5] Make it possible to have a map on the DiveDetailsView

Working, code shamelessy stolen and adapted from the
QGroundCode project.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 CMakeLists.txt                     |   1 +
 qt-mobile/flightmapsettings.cpp    | 148 +++++++++++++++++++++++++++++++++++++
 qt-mobile/flightmapsettings.h      |  72 ++++++++++++++++++
 qt-mobile/qml/DiveDetailsView.qml  |  13 +---
 qt-mobile/qml/DiveMap.qml          |  68 +++++++++++++++++
 qt-mobile/qml/DiveMapView.qml      |  55 ++++++++++++++
 qt-mobile/qml/mobile-resources.qrc |   2 +
 subsurface-mobile-helper.cpp       |   4 +
 8 files changed, 353 insertions(+), 10 deletions(-)
 create mode 100644 qt-mobile/flightmapsettings.cpp
 create mode 100644 qt-mobile/flightmapsettings.h
 create mode 100644 qt-mobile/qml/DiveMap.qml
 create mode 100644 qt-mobile/qml/DiveMapView.qml

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1ee6aff..f8f244d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -227,6 +227,7 @@ if(${SUBSURFACE_TARGET_EXECUTABLE} MATCHES "MobileExecutable")
 	set(MOBILE_SRC
 		qt-mobile/qmlmanager.cpp
 		qt-mobile/qmlprofile.cpp
+		qt-mobile/flightmapsettings.cpp
 		subsurface-mobile-main.cpp
 		subsurface-mobile-helper.cpp
 	)
diff --git a/qt-mobile/flightmapsettings.cpp b/qt-mobile/flightmapsettings.cpp
new file mode 100644
index 0000000..ea8e6b9
--- /dev/null
+++ b/qt-mobile/flightmapsettings.cpp
@@ -0,0 +1,148 @@
+/*=====================================================================
+
+ QGroundControl Open Source Ground Control Station
+
+ (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
+
+ This file is part of the QGROUNDCONTROL project
+
+ QGROUNDCONTROL is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ QGROUNDCONTROL 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
+
+ ======================================================================*/
+
+#include "flightmapsettings.h"
+
+#include <QSettings>
+#include <QtQml>
+
+const char* _defaultMapProvider =    "Bing";                 // Bing is default since it support full street/satellite/hybrid set
+const char* _settingsGroup =         "FlightMapSettings";
+const char* _mapProviderKey =        "MapProvider";
+const char* _mapTypeKey =            "MapType";
+
+FlightMapSettings::FlightMapSettings(QObject *parent) : QObject(parent)
+    , _mapProvider(_defaultMapProvider)
+{
+	    _supportedMapProviders << "Bing" << "Google" << "OpenStreetMap";
+		_loadSettings();
+}
+
+void FlightMapSettings::_storeSettings(void)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.setValue(_mapProviderKey, _supportedMapProviders.contains(_mapProvider) ? _mapProvider : _defaultMapProvider);
+}
+
+void FlightMapSettings::_loadSettings(void)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    _mapProvider = settings.value(_mapProviderKey, _defaultMapProvider).toString();
+
+    if (!_supportedMapProviders.contains(_mapProvider)) {
+        _mapProvider = _defaultMapProvider;
+    }
+
+    _setMapTypesForCurrentProvider();
+}
+
+QString FlightMapSettings::mapProvider(void)
+{
+    return _mapProvider;
+}
+
+void FlightMapSettings::setMapProvider(const QString& mapProvider)
+{
+    if (_supportedMapProviders.contains(mapProvider)) {
+        _mapProvider = mapProvider;
+        _storeSettings();
+        _setMapTypesForCurrentProvider();
+        emit mapProviderChanged(mapProvider);
+    }
+}
+
+void FlightMapSettings::_setMapTypesForCurrentProvider(void)
+{
+    _mapTypes.clear();
+
+    if (_mapProvider == "Bing") {
+        _mapTypes << "Street Map" << "Satellite Map" << "Hybrid Map";
+    } else if (_mapProvider == "Google") {
+        _mapTypes << "Street Map" << "Satellite Map" << "Terrain Map";
+    } else if (_mapProvider == "OpenStreetMap") {
+        _mapTypes << "Street Map";
+    }
+
+    emit mapTypesChanged(_mapTypes);
+}
+
+QString FlightMapSettings::mapTypeForMapName(const QString& mapName)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    settings.beginGroup(_mapProvider);
+	QString ret = settings.value(_mapTypeKey, "Satellite Map").toString();
+    return ret;
+}
+
+void FlightMapSettings::setMapTypeForMapName(const QString& mapName, const QString& mapType)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    settings.beginGroup(_mapProvider);
+    settings.setValue(_mapTypeKey, mapType);
+}
+
+void FlightMapSettings::saveMapSetting (const QString &mapName, const QString& key, const QString& value)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    settings.setValue(key, value);
+}
+
+QString FlightMapSettings::loadMapSetting (const QString &mapName, const QString& key, const QString& defaultValue)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    return settings.value(key, defaultValue).toString();
+}
+
+void FlightMapSettings::saveBoolMapSetting (const QString &mapName, const QString& key, bool value)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    settings.setValue(key, value);
+}
+
+bool FlightMapSettings::loadBoolMapSetting (const QString &mapName, const QString& key, bool defaultValue)
+{
+    QSettings settings;
+
+    settings.beginGroup(_settingsGroup);
+    settings.beginGroup(mapName);
+    return settings.value(key, defaultValue).toBool();
+}
diff --git a/qt-mobile/flightmapsettings.h b/qt-mobile/flightmapsettings.h
new file mode 100644
index 0000000..3b73bda
--- /dev/null
+++ b/qt-mobile/flightmapsettings.h
@@ -0,0 +1,72 @@
+/*=====================================================================
+
+QGroundControl Open Source Ground Control Station
+
+(c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
+
+This file is part of the QGROUNDCONTROL project
+
+    QGROUNDCONTROL is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    QGROUNDCONTROL 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
+
+======================================================================*/
+
+#ifndef FlightMapSettings_H
+#define FlightMapSettings_H
+
+#include <QObject>
+#include <QStringList>
+
+class FlightMapSettings : public QObject
+{
+    Q_OBJECT
+    /// mapProvider is either Bing, Google or Open to specify to set of maps available
+    Q_PROPERTY(QString      mapProvider     READ mapProvider    WRITE setMapProvider NOTIFY mapProviderChanged)
+
+    /// Map providers
+    Q_PROPERTY(QStringList  mapProviders    READ mapProviders   CONSTANT)
+
+    /// Map types associated with current map provider
+    Q_PROPERTY(QStringList  mapTypes        MEMBER _mapTypes    NOTIFY mapTypesChanged)
+public:
+    FlightMapSettings(QObject *parent = 0);
+
+    // Property accessors
+    QString mapProvider(void);
+    void setMapProvider(const QString& mapProvider);
+
+    QStringList mapProviders() { return _supportedMapProviders; }
+   Q_INVOKABLE QString     mapTypeForMapName   (const QString& mapName);
+    Q_INVOKABLE void        setMapTypeForMapName(const QString& mapName, const QString& mapType);
+
+    Q_INVOKABLE void        saveMapSetting      (const QString &mapName, const QString& key, const QString& value);
+    Q_INVOKABLE QString     loadMapSetting      (const QString &mapName, const QString& key, const QString& defaultValue);
+    Q_INVOKABLE void        saveBoolMapSetting  (const QString &mapName, const QString& key, bool value);
+    Q_INVOKABLE bool        loadBoolMapSetting  (const QString &mapName, const QString& key, bool defaultValue);
+	
+signals:
+    void mapProviderChanged(const QString& mapProvider);
+    void mapTypesChanged(const QStringList& mapTypes);
+
+private:
+    void _storeSettings(void);
+    void _loadSettings(void);
+
+    void _setMapTypesForCurrentProvider(void);
+
+    QString     _mapProvider;               ///< Current map provider
+    QStringList _supportedMapProviders;
+    QStringList _mapTypes;                  ///< Map types associated with current map provider
+};
+
+#endif
diff --git a/qt-mobile/qml/DiveDetailsView.qml b/qt-mobile/qml/DiveDetailsView.qml
index c75fc91..ffd57f7 100644
--- a/qt-mobile/qml/DiveDetailsView.qml
+++ b/qt-mobile/qml/DiveDetailsView.qml
@@ -41,18 +41,11 @@ GridLayout {
 			}
 		}
 	}
-	/*
-	Rectangle {
+
+	DiveMapView {
 		id: mapView
-		width: parent.width
-		height: parents.width * 0.7
-		WebView {
-			id: webView
-			anchors.fill: parent
-			url: "http://www.google.com";
-		}
 	}
-*/
+
 	MobileComponents.Label {
 		Layout.alignment: Qt.AlignRight
 		id: dateLabel
diff --git a/qt-mobile/qml/DiveMap.qml b/qt-mobile/qml/DiveMap.qml
new file mode 100644
index 0000000..1a2140e
--- /dev/null
+++ b/qt-mobile/qml/DiveMap.qml
@@ -0,0 +1,68 @@
+/*=====================================================================
+
+QGroundControl Open Source Ground Control Station
+
+(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
+
+This file is part of the QGROUNDCONTROL project
+
+    QGROUNDCONTROL is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    QGROUNDCONTROL 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
+
+======================================================================*/
+
+/**
+ * @file
+ *   @brief QGC Map Background
+ *   @author Gus Grubba <[email protected]>
+ */
+
+import QtQuick          2.4
+import QtQuick.Controls 1.3
+import QtLocation       5.3
+import QtPositioning    5.3
+
+Map {
+    id: _map
+
+    property string mapName:            'defaultMap'
+    property string mapType:            diveMapSettings.mapTypeForMapName(mapName)
+
+	plugin: Plugin { 
+		name: "QGroundControl"
+	}
+
+    zoomLevel: _map.minimumZoomLevel    
+    gesture.flickDeceleration:  3000
+    gesture.activeGestures:     MapGestureArea.ZoomGesture | MapGestureArea.PanGesture | MapGestureArea.FlickGesture
+	gesture.enabled: true
+
+    Component.onCompleted: onMapTypeChanged
+
+    onMapTypeChanged: {
+        diveMapSettings.setMapTypeForMapName("Satellite Map", mapType)
+        var fullMapName = diveMapSettings.mapProvider + " " + mapType
+        for (var i = 0; i < _map.supportedMapTypes.length; i++) {
+            if (fullMapName === _map.supportedMapTypes[i].name) {
+                _map.activeMapType = _map.supportedMapTypes[i]
+                console.log("setou o mapa correto, eu acho." + _map.activeMapType.name);
+                return
+            }
+        }
+    }
+	
+	
+    
+
+    
+} // Map
diff --git a/qt-mobile/qml/DiveMapView.qml b/qt-mobile/qml/DiveMapView.qml
new file mode 100644
index 0000000..eb1d895
--- /dev/null
+++ b/qt-mobile/qml/DiveMapView.qml
@@ -0,0 +1,55 @@
+/*=====================================================================
+
+QGroundControl Open Source Ground Control Station
+
+(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
+
+This file is part of the QGROUNDCONTROL project
+
+    QGROUNDCONTROL is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    QGROUNDCONTROL 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 General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
+
+======================================================================*/
+
+import QtQuick                      2.4
+import QtQuick.Controls             1.3
+import QtLocation                   5.3
+import QtPositioning                5.2
+
+DiveMap {
+    id:             diveMap
+    anchors.fill:   parent
+
+    /* Dirk, This is the way that QGroundControl uses to place things around. 
+	 * I'm commenting out since we don't support anything on the map *yet* 
+	 * so we have some code to take a look on how we shoud implement it. */
+	/*
+    // Add the vehicles to the map
+    MapItemView {
+        model: multiVehicleManager.vehicles
+        delegate:
+            VehicleMapItem {
+                    vehicle:        object
+                    coordinate:     object.coordinate
+                    isSatellite:    diveMap.isSatelliteMap
+                    size:           _mainIsMap ? ScreenTools.defaultFontPixelHeight * 5 : ScreenTools.defaultFontPixelHeight * 2
+                    z:              QGroundControl.zOrderMapItems
+            }
+    }
+	*/
+
+    // Used to make pinch zoom work
+    MouseArea {
+        anchors.fill: parent
+    }
+}
diff --git a/qt-mobile/qml/mobile-resources.qrc b/qt-mobile/qml/mobile-resources.qrc
index bf38cf0..537a266 100644
--- a/qt-mobile/qml/mobile-resources.qrc
+++ b/qt-mobile/qml/mobile-resources.qrc
@@ -15,6 +15,8 @@
 		<file>ThemeTest.qml</file>
 		<file>StartPage.qml</file>
 		<file>dive.jpg</file>
+		<file>DiveMap.qml</file>
+		<file>DiveMapView.qml</file>
 		<file alias="subsurface-mobile-icon.png">../../icons/subsurface-mobile-icon.png</file>
 		<file alias="main-menu.png">icons/main-menu.png</file>
 		<file alias="context-menu.png">icons/context-menu.png</file>
diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp
index 4e4c6f0..4dfc9d5 100644
--- a/subsurface-mobile-helper.cpp
+++ b/subsurface-mobile-helper.cpp
@@ -19,6 +19,7 @@
 #include "qt-models/divelistmodel.h"
 #include "qt-models/gpslistmodel.h"
 #include "qt-mobile/qmlprofile.h"
+#include "qt-mobile/flightmapsettings.h"
 
 QObject *qqWindowObject = NULL;
 
@@ -32,6 +33,7 @@ void run_ui()
 	Q_IMPORT_PLUGIN(QGeoServiceProviderFactoryQGC);
 	qmlRegisterType<QMLManager>("org.subsurfacedivelog.mobile", 1, 0, "QMLManager");
 	qmlRegisterType<QMLProfile>("org.subsurfacedivelog.mobile", 1, 0, "QMLProfile");
+	qmlRegisterUncreatableType<FlightMapSettings> ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only");
 	QQmlApplicationEngine engine;
 
 #if __APPLE__
@@ -63,6 +65,8 @@ void run_ui()
 	QQmlContext *ctxt = engine.rootContext();
 	ctxt->setContextProperty("diveModel", sortModel);
 	ctxt->setContextProperty("gpsModel", gpsSortModel);
+	ctxt->setContextProperty("diveMapSettings", new FlightMapSettings());
+
 	engine.load(QUrl(QStringLiteral("qrc:///qml/main.qml")));
 	qqWindowObject = engine.rootObjects().value(0);
 	if (!qqWindowObject) {
-- 
2.7.0

From eae1a9ad5517964bed3f8a48adf7b087aaafa723 Mon Sep 17 00:00:00 2001
From: Tomaz Canabrava <[email protected]>
Date: Fri, 8 Jan 2016 19:07:01 -0200
Subject: [PATCH 5/5] Sorry, had forgot to add this file.

Signed-off-by: Tomaz Canabrava <[email protected]>
---
 QtLocationPlugin/CMakeLists.txt | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 QtLocationPlugin/CMakeLists.txt

diff --git a/QtLocationPlugin/CMakeLists.txt b/QtLocationPlugin/CMakeLists.txt
new file mode 100644
index 0000000..bd7b95e
--- /dev/null
+++ b/QtLocationPlugin/CMakeLists.txt
@@ -0,0 +1,15 @@
+include_directories(qtlocation/include/QtLocation/5.5.1)
+include_directories(qtlocation/include/QtPositioning/5.5.1)
+
+set(QT_LOCATION_PLUGIN_SRCS
+    qgeoserviceproviderpluginqgc.cpp 
+    qgeotiledmappingmanagerengineqgc.cpp 
+    qgeotilefetcherqgc.cpp 
+    qgeomapreplyqgc.cpp 
+    qgeocodingmanagerengineqgc.cpp 
+    qgeocodereplyqgc.cpp
+    OpenPilotMaps.cc
+)
+
+add_library(QtLocationPlugin STATIC ${QT_LOCATION_PLUGIN_SRCS})
+target_link_libraries(QtLocationPlugin ${QT_LIBRARIES})
\ No newline at end of file
-- 
2.7.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to