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 {
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)
}
......
......@@ -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)
}
}
......
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