Commit 82b91759 authored by Don Gagne's avatar Don Gagne

Map menu fixes

- Only show video option if supported
- Persist settings
- Show/Hide/Add items correctly
parent f323f850
...@@ -51,6 +51,9 @@ Item { ...@@ -51,6 +51,9 @@ Item {
readonly property real _defaultAirSpeed: 0 readonly property real _defaultAirSpeed: 0
readonly property real _defaultClimbRate: 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 _roll: _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll
property real _pitch: _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch property real _pitch: _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch
property real _heading: _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading property real _heading: _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading
...@@ -63,7 +66,10 @@ Item { ...@@ -63,7 +66,10 @@ Item {
property real _airSpeed: _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed property real _airSpeed: _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed
property real _climbRate: _activeVehicle ? _activeVehicle.climbRate : _defaultClimbRate 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) { function getBool(value) {
return value === '0' ? false : true; return value === '0' ? false : true;
...@@ -73,10 +79,15 @@ Item { ...@@ -73,10 +79,15 @@ Item {
return value ? "1" : "0"; return value ? "1" : "0";
} }
function _setShowMap(showMap) {
_showMap = flightDisplay.hasVideo ? showMap : true
multiVehicleManager.saveSetting(_mapName + _showMapBackgroundKey, setBool(_showMap))
}
FlightMap { FlightMap {
id: flightMap id: flightMap
anchors.fill: parent anchors.fill: parent
mapName: "FlightDisplayView" mapName: _mapName
latitude: parent._latitude latitude: parent._latitude
longitude: parent._longitude longitude: parent._longitude
visible: _showMap visible: _showMap
...@@ -157,7 +168,7 @@ Item { ...@@ -157,7 +168,7 @@ Item {
x: root.width * 0.5 - ScreenTools.defaultFontPixelSize * (5) x: root.width * 0.5 - ScreenTools.defaultFontPixelSize * (5)
width: ScreenTools.defaultFontPixelSize * (10) width: ScreenTools.defaultFontPixelSize * (10)
height: ScreenTools.defaultFontPixelSize * (10) height: ScreenTools.defaultFontPixelSize * (10)
heading: root.heading heading: _heading
active: multiVehicleManager.activeVehicleAvailable active: multiVehicleManager.activeVehicleAvailable
z: 70 z: 70
} }
...@@ -250,8 +261,9 @@ Item { ...@@ -250,8 +261,9 @@ Item {
checkable: true checkable: true
checked: _showMap checked: _showMap
text: "Show map as background" text: "Show map as background"
visible: flightDisplay.hasVideo
onTriggered: _showMap = true onTriggered: _setShowMap(true)
} }
MenuItem { MenuItem {
...@@ -260,11 +272,14 @@ Item { ...@@ -260,11 +272,14 @@ Item {
checkable: true checkable: true
checked: !_showMap checked: !_showMap
text: "Show video as background" 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) Component.onCompleted: flightMap.addMapMenuItems(optionsMenu)
} }
......
...@@ -63,48 +63,41 @@ Map { ...@@ -63,48 +63,41 @@ Map {
ExclusiveGroup { id: mapTypeGroup } ExclusiveGroup { id: mapTypeGroup }
/* // Map type selection MenuItem
function setCurrentMap(mapID) { 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++) { 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] _map.activeMapType = _map.supportedMapTypes[i]
multiVehicleManager.saveSetting(_map.mapName + "/currentMapType", mapID); multiVehicleManager.saveSetting(_map.mapName + "/currentMapType", name);
return; return;
} }
} }
} }
function addMap(mapID, checked) { // Add menu map types to the specified menu and sets the current map type from settings
var mItem = mapTypeMenu.addItem(mapID);
mItem.checkable = true
mItem.checked = checked
mItem.exclusiveGroup = currMapType
var menuSlot = function() {setCurrentMap(mapID);};
mItem.triggered.connect(menuSlot);
}
function addMapMenuItems(menu) { function addMapMenuItems(menu) {
var mapID = '' var savedMapName = multiVehicleManager.loadSetting(_map.mapName + "/currentMapType", "")
if (_map.supportedMapTypes.length > 0)
mapID = _map.activeMapType.name; setCurrentMap(savedMapName)
mapID = multiVehicleManager.loadSetting(_map.mapName + "/currentMapType", mapID);
for (var i = 0; i < _map.supportedMapTypes.length; i++) { for (var i = 0; i < _map.supportedMapTypes.length; i++) {
var name = _map.supportedMapTypes[i].name; var menuItem = menuItemComponent.createObject()
addMap(name, mapID === name); menuItem.text = _map.supportedMapTypes[i].name
} menu.insertItem(menu.items.length, menuItem)
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);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment