diff --git a/QGCApplication.pro b/QGCApplication.pro index cd9af36b4629a1ea59f200caaa469f9e02538e81..ae1829ba555f78593a25aa387fe558bb4fba0f54 100644 --- a/QGCApplication.pro +++ b/QGCApplication.pro @@ -141,6 +141,7 @@ INCLUDEPATH += \ src/AutoPilotPlugins \ src/comm \ src/FlightDisplay \ + src/FlightMap \ src/input \ src/Joystick \ src/lib/qmapcontrol \ @@ -239,6 +240,7 @@ HEADERS += \ src/comm/UDPLink.h \ src/FlightDisplay/FlightDisplayWidget.h \ src/FlightDisplay/FlightDisplayView.h \ + src/FlightMap/FlightMapSettings.h \ src/GAudioOutput.h \ src/HomePositionManager.h \ src/Joystick/Joystick.h \ @@ -374,6 +376,7 @@ SOURCES += \ src/comm/UDPLink.cc \ src/FlightDisplay/FlightDisplayWidget.cc \ src/FlightDisplay/FlightDisplayView.cc \ + src/FlightMap/FlightMapSettings.cc \ src/GAudioOutput.cc \ src/HomePositionManager.cc \ src/Joystick/Joystick.cc \ diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 545f877164c8bb935b8ec2634ea861931d9c5b02..ec28c1de35a78b2d72903a3e6921c9823fc0ae65 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -43,6 +43,7 @@ src/AutoPilotPlugins/PX4/Images/PowerComponentBattery_04cell.svg src/AutoPilotPlugins/PX4/Images/PowerComponentBattery_05cell.svg src/AutoPilotPlugins/PX4/Images/PowerComponentBattery_06cell.svg + src/FlightMap/Images/attitudeDial.svg src/FlightMap/Images/attitudeInstrument.svg src//FlightMap/Images/attitudePointer.svg @@ -61,6 +62,8 @@ src/FlightMap/Images/scale_end.png src/FlightMap/Images/airplaneOutline.svg src/FlightMap/Images/airplaneOpaque.svg + src/FlightMap/Images/MapType.svg + src/FlightMap/Images/MapCenter.svg src/test.qml @@ -102,6 +105,7 @@ src/QmlControls/MissionItemSummary.qml src/QmlControls/MissionItemEditor.qml src/QmlControls/DropButton.qml + src/QmlControls/QGCCanvas.qml src/VehicleSetup/SetupView.qml diff --git a/src/FlightDisplay/FlightDisplayView.cc b/src/FlightDisplay/FlightDisplayView.cc index 34cfa13e84c0935cbeca98de1dfea13f5b977613..8b19e357ec4a743635991f74e44426d28db4cf2c 100644 --- a/src/FlightDisplay/FlightDisplayView.cc +++ b/src/FlightDisplay/FlightDisplayView.cc @@ -91,19 +91,3 @@ FlightDisplayView::FlightDisplayView(QWidget *parent) FlightDisplayView::~FlightDisplayView() { } - -void FlightDisplayView::saveSetting(const QString &name, const QString& value) -{ - QSettings settings; - QString key(kMainFlightDisplayViewGroup); - key += "/" + name; - settings.setValue(key, value); -} - -QString FlightDisplayView::loadSetting(const QString &name, const QString& defaultValue) -{ - QSettings settings; - QString key(kMainFlightDisplayViewGroup); - key += "/" + name; - return settings.value(key, defaultValue).toString(); -} diff --git a/src/FlightDisplay/FlightDisplayView.h b/src/FlightDisplay/FlightDisplayView.h index e97c290015370a173bd7eaec8ea700aec1fc4080..7fe374b2ed7847c7bedb7be05ef721386d9d9f95 100644 --- a/src/FlightDisplay/FlightDisplayView.h +++ b/src/FlightDisplay/FlightDisplayView.h @@ -38,9 +38,6 @@ public: Q_PROPERTY(bool hasVideo READ hasVideo CONSTANT) - Q_INVOKABLE void saveSetting (const QString &key, const QString& value); - Q_INVOKABLE QString loadSetting (const QString &key, const QString& defaultValue); - #if defined(QGC_GST_STREAMING) bool hasVideo () { return true; } #else diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 70bc9d13645b30c65cb38f1339bf578267f95c58..49e279cadfd98506c36817cdf153a159ecc42527 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -27,6 +27,7 @@ import QtQuick.Controls.Styles 1.2 import QtQuick.Dialogs 1.2 import QtLocation 5.3 +import QGroundControl 1.0 import QGroundControl.FlightMap 1.0 import QGroundControl.ScreenTools 1.0 import QGroundControl.Controls 1.0 @@ -66,7 +67,7 @@ Item { property real _airSpeed: _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed property real _climbRate: _activeVehicle ? _activeVehicle.climbRate : _defaultClimbRate - property bool _showMap: getBool(multiVehicleManager.loadSetting(_mapName + _showMapBackgroundKey, "1")) + property bool _showMap: getBool(QGroundControl.flightMapSettings.loadMapSetting(flightMap.mapName, _showMapBackgroundKey, "1")) // Validate _showMap setting Component.onCompleted: _setShowMap(_showMap) @@ -81,7 +82,7 @@ Item { function _setShowMap(showMap) { _showMap = flightDisplay.hasVideo ? showMap : true - multiVehicleManager.saveSetting(_mapName + _showMapBackgroundKey, setBool(_showMap)) + QGroundControl.flightMapSettings.saveMapSetting(flightMap.mapName, _showMapBackgroundKey, setBool(_showMap)) } FlightMap { @@ -141,7 +142,6 @@ Item { size: ScreenTools.defaultFontPixelSize * (13.3) heading: _heading active: multiVehicleManager.activeVehicleAvailable - z: flightMap.z + 2 } QGCAttitudeWidget { @@ -152,8 +152,39 @@ Item { rollAngle: _roll pitchAngle: _pitch active: multiVehicleManager.activeVehicleAvailable - z: flightMap.z + 2 } + + DropButton { + id: mapTypeButton + anchors.margins: ScreenTools.defaultFontPixelHeight + anchors.top: parent.top + anchors.right: parent.right + dropDirection: dropDown + buttonImage: "/qmlimages/MapType.svg" + viewportMargins: ScreenTools.defaultFontPixelWidth / 2 + + dropDownComponent: Component { + Row { + spacing: ScreenTools.defaultFontPixelWidth + + Repeater { + model: QGroundControl.flightMapSettings.mapTypes + + QGCButton { + checkable: true + checked: flightMap.mapType == text + text: modelData + + onClicked: { + flightMap.mapType = text + mapTypeButton.hideDropDown() + } + } + } + } + } + } + } // Flight Map QGCVideoBackground { @@ -280,8 +311,6 @@ Item { MenuSeparator { visible: flightDisplay.hasVideo && _showMap } - - Component.onCompleted: flightMap.addMapMenuItems(optionsMenu) } } } diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index a764bb8e72e33296b237476db01a873a20152c0e..b95d2c15d3e7aaed18ead77de7548b8fecd3963a 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -32,6 +32,7 @@ import QtQuick.Controls 1.3 import QtLocation 5.3 import QtPositioning 5.3 +import QGroundControl 1.0 import QGroundControl.Controls 1.0 import QGroundControl.FlightMap 1.0 import QGroundControl.ScreenTools 1.0 @@ -47,6 +48,7 @@ Map { property real heading: 0 property bool interactive: true property string mapName: 'defaultMap' + property string mapType: QGroundControl.flightMapSettings.mapTypeForMapName(mapName) property alias mapWidgets: controlWidgets property bool isSatelliteMap: false @@ -61,45 +63,20 @@ Map { plugin: Plugin { name: "QGroundControl" } ExclusiveGroup { id: mapTypeGroup } - - // Map type selection MenuItem - Component { - id: menuItemComponent - - MenuItem { - checkable: true - checked: text == _map.activeMapType.name - exclusiveGroup: mapTypeGroup - visible: _map.visible - - onTriggered: setCurrentMap(text) - } - } - - // Set the current map type to the specified type name - function setCurrentMap(name) { + + Component.onCompleted: onMapTypeChanged + + onMapTypeChanged: { + QGroundControl.flightMapSettings.setMapTypeForMapName(mapName, mapType) + var fullMapName = QGroundControl.flightMapSettings.mapProvider + " " + mapType for (var i = 0; i < _map.supportedMapTypes.length; i++) { - if (name === _map.supportedMapTypes[i].name) { + if (fullMapName === _map.supportedMapTypes[i].name) { _map.activeMapType = _map.supportedMapTypes[i] - multiVehicleManager.saveSetting(_map.mapName + "/currentMapType", name); - return; + return } } } - - // Add menu map types to the specified menu and sets the current map type from settings - function addMapMenuItems(menu) { - var savedMapName = multiVehicleManager.loadSetting(_map.mapName + "/currentMapType", "") - - setCurrentMap(savedMapName) - - for (var i = 0; i < _map.supportedMapTypes.length; i++) { - var menuItem = menuItemComponent.createObject() - menuItem.text = _map.supportedMapTypes[i].name - menu.insertItem(menu.items.length, menuItem) - } - } - + /// Map control widgets Column { id: controlWidgets diff --git a/src/FlightMap/FlightMapSettings.cc b/src/FlightMap/FlightMapSettings.cc new file mode 100644 index 0000000000000000000000000000000000000000..a27e5978fca1e969e16470795ec051fb5777e6bc --- /dev/null +++ b/src/FlightMap/FlightMapSettings.cc @@ -0,0 +1,140 @@ +/*===================================================================== + + QGroundControl Open Source Ground Control Station + + (c) 2009 - 2015 QGROUNDCONTROL PROJECT + + 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 . + + ======================================================================*/ + +#include "FlightMapSettings.h" + +#include +#include + +IMPLEMENT_QGC_SINGLETON(FlightMapSettings, FlightMapSettings) + +const char* FlightMapSettings::_defaultMapProvider = "Bing"; // Bing is default since it support full street/satellite/hybrid set +const char* FlightMapSettings::_settingsGroup = "FlightMapSettings"; +const char* FlightMapSettings::_mapProviderKey = "MapProvider"; +const char* FlightMapSettings::_mapTypeKey = "MapType"; + +FlightMapSettings::FlightMapSettings(QObject* parent) + : QObject(parent) + , _mapProvider(_defaultMapProvider) +{ + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "FlightMapSetting", "Reference only"); + + _supportedMapProviders << "Bing" << "Google" << "Open"; + + _loadSettings(); +} + +FlightMapSettings::~FlightMapSettings() +{ + +} + +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 == "Open") { + _mapTypes << "Street Map"; + } + + emit mapTypesChanged(_mapTypes); +} + +QString FlightMapSettings::mapTypeForMapName(const QString& mapName) +{ + QSettings settings; + + settings.beginGroup(_settingsGroup); + settings.beginGroup(mapName); + settings.beginGroup(_mapProvider); + return settings.value(_mapTypeKey, "Street Map").toString(); +} + +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(); +} diff --git a/src/FlightMap/FlightMapSettings.h b/src/FlightMap/FlightMapSettings.h new file mode 100644 index 0000000000000000000000000000000000000000..8de843e7cc2a80c86df5cbf0db14ab8884caab43 --- /dev/null +++ b/src/FlightMap/FlightMapSettings.h @@ -0,0 +1,79 @@ +/*===================================================================== + +QGroundControl Open Source Ground Control Station + +(c) 2009 - 2015 QGROUNDCONTROL PROJECT + +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 . + +======================================================================*/ + +#ifndef FlightMapSettings_H +#define FlightMapSettings_H + +#include "QGCSingleton.h" + +#include + +class FlightMapSettings : public QObject +{ + Q_OBJECT + + DECLARE_QGC_SINGLETON(FlightMapSettings, FlightMapSettings) + +public: + /// 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 types associated with current map provider + Q_PROPERTY(QStringList mapTypes MEMBER _mapTypes NOTIFY mapTypesChanged) + + 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); + + // Property accessors + + QString mapProvider(void); + void setMapProvider(const QString& mapProvider); + +signals: + void mapProviderChanged(const QString& mapProvider); + void mapTypesChanged(const QStringList& mapTypes); + +private: + /// @brief All access to FlightMapSettings singleton is through FlightMapSettings::instance + FlightMapSettings(QObject* parent = NULL); + ~FlightMapSettings(); + + 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 + + static const char* _defaultMapProvider; + static const char* _settingsGroup; + static const char* _mapProviderKey; + static const char* _mapTypeKey; +}; + +#endif diff --git a/src/HomePositionManager.cc b/src/HomePositionManager.cc index d8ca76e011d501c7a218243e6b79cf04acccde63..5c07db78c234ec23200cf78e5c8163c38483be03 100644 --- a/src/HomePositionManager.cc +++ b/src/HomePositionManager.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include "UAS.h" #include "UASInterface.h" @@ -51,6 +52,8 @@ HomePositionManager::HomePositionManager(QObject* parent) , homeLon(8.549444) , homeAlt(470.0) { + qmlRegisterUncreatableType ("QGroundControl", 1, 0, "HomePositionManager", "Reference only"); + _loadSettings(); } diff --git a/src/MissionEditor/MissionEditor.qml b/src/MissionEditor/MissionEditor.qml index 5ac9325dbf77e8b73338facf29fd57f89ec1888e..2293d27406686315b1c0fcd0b12b5b249e9174a5 100644 --- a/src/MissionEditor/MissionEditor.qml +++ b/src/MissionEditor/MissionEditor.qml @@ -104,7 +104,7 @@ QGCView { anchors.right: mapTypeButton.left anchors.top: mapTypeButton.top dropDirection: dropDown - label: "C" + buttonImage: "/qmlimages/MapCenter.svg" viewportMargins: ScreenTools.defaultFontPixelWidth / 2 dropDownComponent: Component { @@ -114,14 +114,48 @@ QGCView { QGCButton { text: "Home" - onClicked: centerMapButton.hideDropDown() + onClicked: { + centerMapButton.hideDropDown() + editorMap.center = QtPositioning.coordinate(_homePositionCoordinate.latitude, _homePositionCoordinate.longitude) + _showHomePositionManager = true + } } +/* + +This code will need to wait for Qml 5.5 support since Map.visibleRegion is only in Qt 5.5 + QGCButton { text: "All Items" - onClicked: centerMapButton.hideDropDown() + onClicked: { + centerMapButton.hideDropDown() + + // Begin with only the home position in the region + var region = QtPositioning.rectangle(QtPositioning.coordinate(_homePositionCoordinate.latitude, _homePositionCoordinate.longitude), + QtPositioning.coordinate(_homePositionCoordinate.latitude, _homePositionCoordinate.longitude)) + + // Now expand the region to include all mission items + for (var i=0; i<_missionItems.count; i++) { + var missionItem = _missionItems.get(i) + + region.topLeft.latitude = Math.max(missionItem.coordinate.latitude, region.topLeft.latitude) + region.topLeft.longitude = Math.min(missionItem.coordinate.longitude, region.topLeft.longitude) + + region.topRight.latitude = Math.max(missionItem.coordinate.latitude, region.topRight.latitude) + region.topRight.longitude = Math.max(missionItem.coordinate.longitude, region.topRight.longitude) + + region.bottomLeft.latitude = Math.min(missionItem.coordinate.latitude, region.bottomLeft.latitude) + region.bottomLeft.longitude = Math.min(missionItem.coordinate.longitude, region.bottomLeft.longitude) + + region.bottomRight.latitude = Math.min(missionItem.coordinate.latitude, region.bottomRight.latitude) + region.bottomRight.longitude = Math.max(missionItem.coordinate.longitude, region.bottomRight.longitude) + } + + editorMap.visibleRegion = region + } } +*/ } } } @@ -132,29 +166,26 @@ QGCView { anchors.top: parent.top anchors.right: parent.right dropDirection: dropDown - label: "M" + buttonImage: "/qmlimages/MapType.svg" viewportMargins: ScreenTools.defaultFontPixelWidth / 2 dropDownComponent: Component { Row { spacing: ScreenTools.defaultFontPixelWidth - QGCButton { - text: "Street" - - onClicked: mapTypeButton.hideDropDown() - } - - QGCButton { - text: "Satellite" - - onClicked: mapTypeButton.hideDropDown() - } + Repeater { + model: QGroundControl.flightMapSettings.mapTypes - QGCButton { - text: "Hybrid" + QGCButton { + checkable: true + checked: editorMap.mapType == text + text: modelData - onClicked: mapTypeButton.hideDropDown() + onClicked: { + editorMap.mapType = text + mapTypeButton.hideDropDown() + } + } } } } diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index c795fe0282a5b244fc96bcc72e19d6954266c981..099c023ffab1f181a52185f6a5cf5d2bc9b689cd 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -83,6 +83,7 @@ #include "MissionManager.h" #include "QGroundControlQmlGlobal.h" #include "HomePositionManager.h" +#include "FlightMapSettings.h" #ifndef __ios__ #include "SerialLink.h" @@ -313,7 +314,6 @@ void QGCApplication::_initCommon(void) qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "JoystickManager", "Reference only"); qmlRegisterUncreatableType ("QGroundControl.JoystickManager", 1, 0, "Joystick", "Reference only"); qmlRegisterUncreatableType ("QGroundControl", 1, 0, "QmlObjectListModel", "Reference only"); - qmlRegisterUncreatableType ("QGroundControl", 1, 0, "HomePositionManager", "Reference only"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ViewWidgetController"); qmlRegisterType ("QGroundControl.Controllers", 1, 0, "ParameterEditorController"); @@ -550,6 +550,16 @@ void QGCApplication::_createSingletons(void) { // The order here is important since the singletons reference each other + // No dependencies + FlightMapSettings* flightMapSettings = FlightMapSettings::_createSingleton(); + Q_UNUSED(flightMapSettings); + Q_ASSERT(flightMapSettings); + + // No dependencies + HomePositionManager* homePositionManager = HomePositionManager::_createSingleton(); + Q_UNUSED(homePositionManager); + Q_ASSERT(homePositionManager); + // No dependencies FirmwarePlugin* firmwarePlugin = GenericFirmwarePlugin::_createSingleton(); Q_UNUSED(firmwarePlugin); @@ -584,22 +594,17 @@ void QGCApplication::_createSingletons(void) Q_UNUSED(linkManager); Q_ASSERT(linkManager); - // Needs LinkManager - HomePositionManager* uasManager = HomePositionManager::_createSingleton(); - Q_UNUSED(uasManager); - Q_ASSERT(uasManager); - - // Need HomePositionManager + // Need MultiVehicleManager AutoPilotPluginManager* pluginManager = AutoPilotPluginManager::_createSingleton(); Q_UNUSED(pluginManager); Q_ASSERT(pluginManager); - // Need HomePositionManager + // Need MultiVehicleManager UASMessageHandler* messageHandler = UASMessageHandler::_createSingleton(); Q_UNUSED(messageHandler); Q_ASSERT(messageHandler); - // Needs HomePositionManager + // Needs MultiVehicleManager FactSystem* factSystem = FactSystem::_createSingleton(); Q_UNUSED(factSystem); Q_ASSERT(factSystem); @@ -631,7 +636,6 @@ void QGCApplication::_destroySingletons(void) FactSystem::_deleteSingleton(); UASMessageHandler::_deleteSingleton(); AutoPilotPluginManager::_deleteSingleton(); - HomePositionManager::_deleteSingleton(); LinkManager::_deleteSingleton(); GAudioOutput::_deleteSingleton(); JoystickManager::_deleteSingleton(); @@ -640,6 +644,8 @@ void QGCApplication::_destroySingletons(void) GenericFirmwarePlugin::_deleteSingleton(); PX4FirmwarePlugin::_deleteSingleton(); APMFirmwarePlugin::_deleteSingleton(); + HomePositionManager::_deleteSingleton(); + FlightMapSettings::_deleteSingleton(); } void QGCApplication::informationMessageBoxOnMainThread(const QString& title, const QString& msg) diff --git a/src/QmlControls/DropButton.qml b/src/QmlControls/DropButton.qml index 7a2acd1858ebdbe6f02ea87df54264107f5e12db..540e99e9d8551f87b7be0865ecf6dabc209866be 100644 --- a/src/QmlControls/DropButton.qml +++ b/src/QmlControls/DropButton.qml @@ -8,8 +8,8 @@ import QGroundControl.Palette 1.0 Item { id: _root - property alias label: buttonLabel.text - property alias radius: button.radius + property alias buttonImage: button.source + property real radius: (ScreenTools.defaultFontPixelHeight * 3) / 2 property int dropDirection: dropDown property alias dropDownComponent: dropDownLoader.sourceComponent property real viewportMargins: 0 @@ -144,33 +144,24 @@ Item { } // Button - Rectangle { + Image { id: button anchors.fill: parent - radius: (ScreenTools.defaultFontPixelHeight * 3) / 2 - color: qgcPal.button + fillMode: Image.PreserveAspectFit opacity: _showDropDown ? 1.0 : 0.75 - QGCLabel { - id: buttonLabel - anchors.fill: parent - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - color: "white" - } - MouseArea { anchors.fill: parent onClicked: _showDropDown = !_showDropDown } - } // Rectangle - button + } // Image - button Item { id: dropDownItem visible: _showDropDown - Canvas { + QGCCanvas { id: arrowCanvas anchors.fill: parent @@ -224,6 +215,13 @@ Item { id: dropDownLoader x: _dropMargin y: _dropMargin + + Connections { + target: dropDownLoader.item + + onWidthChanged: _calcPositions() + onHeightChanged: _calcPositions() + } } } } // Item - dropDownItem diff --git a/src/QmlControls/QGCCanvas.qml b/src/QmlControls/QGCCanvas.qml new file mode 100644 index 0000000000000000000000000000000000000000..1b7d6e3b9808e49e9ce3c3e351bb201ac3393e9d --- /dev/null +++ b/src/QmlControls/QGCCanvas.qml @@ -0,0 +1,17 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 + +import QGroundControl.Palette 1.0 +import QGroundControl.ScreenTools 1.0 + +/// Canvas has some sort of bug in it which can cause it to not paint when top level Views +/// are switched. In order to fix this we ahve a signal hacked into ScreenTools to force +/// a repaint. +Canvas { + Connections { + target: ScreenTools + + onRepaintRequested: arrowCanvas.requestPaint() + } +} diff --git a/src/QmlControls/QGroundControl.Controls.qmldir b/src/QmlControls/QGroundControl.Controls.qmldir index cc9b94af863eb80dbf383a5ef39b88434e96cf10..5d72b54cccfab741ef85519db4002ba3a19598ce 100644 --- a/src/QmlControls/QGroundControl.Controls.qmldir +++ b/src/QmlControls/QGroundControl.Controls.qmldir @@ -9,6 +9,7 @@ QGCComboBox 1.0 QGCComboBox.qml QGCColoredImage 1.0 QGCColoredImage.qml QGCToolBarButton 1.0 QGCToolBarButton.qml QGCMovableItem 1.0 QGCMovableItem.qml +QGCCanvas 1.0 QGCCanvas.qml SubMenuButton 1.0 SubMenuButton.qml IndicatorButton 1.0 IndicatorButton.qml diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index 1261e059b0c20632d00e3f633dfef4926db13c59..8912f375e19db8e1567fc4ef248d9a16f6f50530 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -29,6 +29,7 @@ QGroundControlQmlGlobal::QGroundControlQmlGlobal(QObject* parent) : QObject(parent) , _homePositionManager(HomePositionManager::instance()) + , _flightMapSettings(FlightMapSettings::instance()) { } diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index 72fcfff8d83af3681fd6a1ee8e27ee7ff0b9ce45..5091dae4661d6a7d8f16da6ef337b87f8adce9dd 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -30,6 +30,7 @@ #include #include "HomePositionManager.h" +#include "FlightMapSettings.h" class QGroundControlQmlGlobal : public QObject { @@ -39,14 +40,17 @@ public: QGroundControlQmlGlobal(QObject* parent = NULL); ~QGroundControlQmlGlobal(); - Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager CONSTANT) + Q_PROPERTY(HomePositionManager* homePositionManager READ homePositionManager CONSTANT) + Q_PROPERTY(FlightMapSettings* flightMapSettings READ flightMapSettings CONSTANT) // Property accesors - HomePositionManager* homePositionManager(void) { return _homePositionManager; } + HomePositionManager* homePositionManager(void) { return _homePositionManager; } + FlightMapSettings* flightMapSettings(void) { return _flightMapSettings; } private: HomePositionManager* _homePositionManager; + FlightMapSettings* _flightMapSettings; }; #endif diff --git a/src/ui/SettingsDialog.cc b/src/ui/SettingsDialog.cc index 8200c9f69dd611a533238f3b31bbe6312455a505..ea9862b5f4a8b2b09c9d4a2cb5aa1da8a77f616e 100644 --- a/src/ui/SettingsDialog.cc +++ b/src/ui/SettingsDialog.cc @@ -37,6 +37,7 @@ #include "QGCFileDialog.h" #include "QGCMessageBox.h" #include "MainToolBar.h" +#include "FlightMapSettings.h" SettingsDialog::SettingsDialog(QWidget *parent, int showTab, Qt::WindowFlags flags) : QDialog(parent, flags), @@ -94,7 +95,18 @@ _ui(new Ui::SettingsDialog) connect(_ui->styleChooser, SIGNAL(currentIndexChanged(int)), this, SLOT(styleChanged(int))); connect(_ui->browseSavedFilesLocation, &QPushButton::clicked, this, &SettingsDialog::_selectSavedFilesDirectory); connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::_validateBeforeClose); - + + // Flight Map settings + + FlightMapSettings* fmSettings = FlightMapSettings::instance(); + _ui->bingMapRadio->setChecked(fmSettings->mapProvider() == "Bing"); + _ui->googleMapRadio->setChecked(fmSettings->mapProvider() == "Google"); + _ui->openMapRadio->setChecked(fmSettings->mapProvider() == "Open"); + + connect(_ui->bingMapRadio, &QRadioButton::clicked, this, &SettingsDialog::_bingMapRadioClicked); + connect(_ui->googleMapRadio, &QRadioButton::clicked, this, &SettingsDialog::_googleMapRadioClicked); + connect(_ui->openMapRadio, &QRadioButton::clicked, this, &SettingsDialog::_openMapRadioClicked); + switch (showTab) { case ShowCommLinks: _ui->tabWidget->setCurrentWidget(pLinkConf); @@ -193,3 +205,24 @@ void SettingsDialog::on_showRSSI_clicked(bool checked) { _mainWindow->getMainToolBar()->viewStateChanged(TOOL_BAR_SHOW_RSSI, checked); } + +void SettingsDialog::_bingMapRadioClicked(bool checked) +{ + if (checked) { + FlightMapSettings::instance()->setMapProvider("Bing"); + } +} + +void SettingsDialog::_googleMapRadioClicked(bool checked) +{ + if (checked) { + FlightMapSettings::instance()->setMapProvider("Google"); + } +} + +void SettingsDialog::_openMapRadioClicked(bool checked) +{ + if (checked) { + FlightMapSettings::instance()->setMapProvider("Open"); + } +} diff --git a/src/ui/SettingsDialog.h b/src/ui/SettingsDialog.h index ac1a31108ea065452367adf75ff2e0d74048538a..f991e9b79ab402d920f39275ccd0489da065292a 100644 --- a/src/ui/SettingsDialog.h +++ b/src/ui/SettingsDialog.h @@ -62,6 +62,10 @@ private slots: void on_showMav_clicked(bool checked); void on_showRSSI_clicked(bool checked); + + void _bingMapRadioClicked(bool checked); + void _googleMapRadioClicked(bool checked); + void _openMapRadioClicked(bool checked); private: MainWindow* _mainWindow; diff --git a/src/ui/SettingsDialog.ui b/src/ui/SettingsDialog.ui index 036595c8181c5e781afccf83a1b511923c1bf39a..0db0fa3fffed2086d347cccfc6379857d337a94c 100644 --- a/src/ui/SettingsDialog.ui +++ b/src/ui/SettingsDialog.ui @@ -7,7 +7,7 @@ 0 0 500 - 596 + 689 @@ -115,6 +115,36 @@ + + + + Map Provider + + + + + + Bing + + + + + + + Google + + + + + + + Open Streets + + + + + +