diff --git a/src/FlightDisplay/FlightDisplayView.qml b/src/FlightDisplay/FlightDisplayView.qml index 4cb5b1ecd3fef7b813656168f0da2aeaf1fb5530..70bc9d13645b30c65cb38f1339bf578267f95c58 100644 --- a/src/FlightDisplay/FlightDisplayView.qml +++ b/src/FlightDisplay/FlightDisplayView.qml @@ -51,6 +51,9 @@ Item { readonly property real _defaultAirSpeed: 0 readonly property real _defaultClimbRate: 0 + readonly property string _mapName: "FlightDisplayView" + readonly property string _showMapBackgroundKey: "/showMapBackground" + property real _roll: _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll property real _pitch: _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch property real _heading: _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading @@ -63,7 +66,10 @@ Item { property real _airSpeed: _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed property real _climbRate: _activeVehicle ? _activeVehicle.climbRate : _defaultClimbRate - property bool _showMap: true + property bool _showMap: getBool(multiVehicleManager.loadSetting(_mapName + _showMapBackgroundKey, "1")) + + // Validate _showMap setting + Component.onCompleted: _setShowMap(_showMap) function getBool(value) { return value === '0' ? false : true; @@ -73,10 +79,15 @@ Item { return value ? "1" : "0"; } + function _setShowMap(showMap) { + _showMap = flightDisplay.hasVideo ? showMap : true + multiVehicleManager.saveSetting(_mapName + _showMapBackgroundKey, setBool(_showMap)) + } + FlightMap { id: flightMap anchors.fill: parent - mapName: "FlightDisplayView" + mapName: _mapName latitude: parent._latitude longitude: parent._longitude visible: _showMap @@ -157,7 +168,7 @@ Item { x: root.width * 0.5 - ScreenTools.defaultFontPixelSize * (5) width: ScreenTools.defaultFontPixelSize * (10) height: ScreenTools.defaultFontPixelSize * (10) - heading: root.heading + heading: _heading active: multiVehicleManager.activeVehicleAvailable z: 70 } @@ -250,8 +261,9 @@ Item { checkable: true checked: _showMap text: "Show map as background" + visible: flightDisplay.hasVideo - onTriggered: _showMap = true + onTriggered: _setShowMap(true) } MenuItem { @@ -260,11 +272,14 @@ Item { checkable: true checked: !_showMap text: "Show video as background" + visible: flightDisplay.hasVideo - onTriggered: _showMap = false + onTriggered: _setShowMap(false) } - MenuSeparator { } + MenuSeparator { + visible: flightDisplay.hasVideo && _showMap + } Component.onCompleted: flightMap.addMapMenuItems(optionsMenu) } diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index 32fd7452e6e274686609c1d814116a39a3fdf61f..5ded1bfdab38db15c748060db5151709a897fb47 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -63,48 +63,41 @@ Map { ExclusiveGroup { id: mapTypeGroup } - /* - function setCurrentMap(mapID) { + // 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) { for (var i = 0; i < _map.supportedMapTypes.length; i++) { - if (mapID === _map.supportedMapTypes[i].name) { + if (name === _map.supportedMapTypes[i].name) { _map.activeMapType = _map.supportedMapTypes[i] - multiVehicleManager.saveSetting(_map.mapName + "/currentMapType", mapID); + multiVehicleManager.saveSetting(_map.mapName + "/currentMapType", name); return; } } } - function addMap(mapID, checked) { - var mItem = mapTypeMenu.addItem(mapID); - mItem.checkable = true - mItem.checked = checked - mItem.exclusiveGroup = currMapType - var menuSlot = function() {setCurrentMap(mapID);}; - mItem.triggered.connect(menuSlot); - } - + // Add menu map types to the specified menu and sets the current map type from settings function addMapMenuItems(menu) { - var mapID = '' - if (_map.supportedMapTypes.length > 0) - mapID = _map.activeMapType.name; - mapID = multiVehicleManager.loadSetting(_map.mapName + "/currentMapType", mapID); + var savedMapName = multiVehicleManager.loadSetting(_map.mapName + "/currentMapType", "") + + setCurrentMap(savedMapName) + for (var i = 0; i < _map.supportedMapTypes.length; i++) { - var name = _map.supportedMapTypes[i].name; - addMap(name, mapID === name); - } - if(mapID != '') - setCurrentMap(mapID); - } - */ - - function addMapMenuItems(menu) { - for (var i= 0; i < _map.supportedMapTypes.length; i++) { - var name = _map.supportedMapTypes[i].name; - var mItem = menu.addItem(name); - mItem.checkable = true - mItem.exclusiveGroup = mapTypeGroup - //var menuSlot = function() {setCurrentMap(mapID);}; - //mItem.triggered.connect(menuSlot); + var menuItem = menuItemComponent.createObject() + menuItem.text = _map.supportedMapTypes[i].name + menu.insertItem(menu.items.length, menuItem) } }