From f26504f525412d8139e6569496ac26139545310c Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Tue, 27 Oct 2015 13:53:21 -0400 Subject: [PATCH] Saving and Restoring "Map Is Main" --- src/FlightDisplay/FlightDisplayView.qml | 4 +- src/FlightMap/Widgets/QGCInstrumentWidget.qml | 8 ++-- src/QmlControls/QGroundControlQmlGlobal.cc | 44 ++++++++++++++++--- src/QmlControls/QGroundControlQmlGlobal.h | 5 +++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 0265d175a..26efdb2cd 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -56,8 +56,9 @@ Item { readonly property string _mapName: "FlightDisplayView" readonly property string _showMapBackgroundKey: "/showMapBackground" + readonly property string _mainIsMapKey: "MainFlyWindowIsMap" - property bool _mainIsMap: !_controller.hasVideo + property bool _mainIsMap: QGroundControl.loadBoolGlobalSetting(_mainIsMapKey, true) property real _roll: _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll property real _pitch: _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch @@ -158,6 +159,7 @@ Item { _mainIsMap = !_mainIsMap pip.visible = false reloadContents(); + QGroundControl.saveBoolGlobalSetting(_mainIsMapKey, _mainIsMap) } } } diff --git a/src/FlightMap/Widgets/QGCInstrumentWidget.qml b/src/FlightMap/Widgets/QGCInstrumentWidget.qml index 869094f25..3e7b83305 100644 --- a/src/FlightMap/Widgets/QGCInstrumentWidget.qml +++ b/src/FlightMap/Widgets/QGCInstrumentWidget.qml @@ -88,7 +88,7 @@ Item { horizontalAlignment: TextEdit.AlignHCenter } QGCLabel { - text: altitude + text: altitude.toFixed(1) font.weight: Font.DemiBold color: isSatellite ? "black" : "white" } @@ -110,7 +110,7 @@ Item { horizontalAlignment: TextEdit.AlignHCenter } QGCLabel { - text: groundSpeed + text: groundSpeed.toFixed(1) font.weight: Font.DemiBold color: isSatellite ? "black" : "white" } @@ -134,7 +134,7 @@ Item { horizontalAlignment: TextEdit.AlignHCenter } QGCLabel { - text: airSpeed + text: airSpeed.toFixed(1) font.weight: Font.DemiBold color: isSatellite ? "black" : "white" } @@ -156,7 +156,7 @@ Item { horizontalAlignment: TextEdit.AlignHCenter } QGCLabel { - text: climbRate + text: climbRate.toFixed(1) font.weight: Font.DemiBold color: isSatellite ? "black" : "white" } diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index 8912f375e..a9f26fb1a 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -1,24 +1,24 @@ /*===================================================================== - + QGroundControl Open Source Ground Control Station - + (c) 2009 - 2014 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 . - + ======================================================================*/ /// @file @@ -26,6 +26,8 @@ #include "QGroundControlQmlGlobal.h" +static const char* kQmlGlobalKeyName = "QGCQml"; + QGroundControlQmlGlobal::QGroundControlQmlGlobal(QObject* parent) : QObject(parent) , _homePositionManager(HomePositionManager::instance()) @@ -38,3 +40,31 @@ QGroundControlQmlGlobal::~QGroundControlQmlGlobal() { } + +void QGroundControlQmlGlobal::saveGlobalSetting (const QString& key, const QString& value) +{ + QSettings settings; + settings.beginGroup(kQmlGlobalKeyName); + settings.setValue(key, value); +} + +QString QGroundControlQmlGlobal::loadGlobalSetting (const QString& key, const QString& defaultValue) +{ + QSettings settings; + settings.beginGroup(kQmlGlobalKeyName); + return settings.value(key, defaultValue).toString(); +} + +void QGroundControlQmlGlobal::saveBoolGlobalSetting (const QString& key, bool value) +{ + QSettings settings; + settings.beginGroup(kQmlGlobalKeyName); + settings.setValue(key, value); +} + +bool QGroundControlQmlGlobal::loadBoolGlobalSetting (const QString& key, bool defaultValue) +{ + QSettings settings; + settings.beginGroup(kQmlGlobalKeyName); + return settings.value(key, defaultValue).toBool(); +} diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index 3a1260522..52655212a 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -47,6 +47,11 @@ public: Q_PROPERTY(qreal zOrderWidgets READ zOrderWidgets CONSTANT) ///< z order value to widgets, for example: zoom controls, hud widgetss Q_PROPERTY(qreal zOrderMapItems READ zOrderMapItems CONSTANT) ///< z order value for map items, for example: mission item indicators + Q_INVOKABLE void saveGlobalSetting (const QString& key, const QString& value); + Q_INVOKABLE QString loadGlobalSetting (const QString& key, const QString& defaultValue); + Q_INVOKABLE void saveBoolGlobalSetting (const QString& key, bool value); + Q_INVOKABLE bool loadBoolGlobalSetting (const QString& key, bool defaultValue); + // Property accesors HomePositionManager* homePositionManager () { return _homePositionManager; } -- 2.22.0