1
0
Fork 0

Map widget: tweaks to property creation

Allow these values to be auto-saved without getting over-written.
This commit is contained in:
James Turner 2021-03-26 10:44:27 +00:00
parent f88f38ec53
commit 3276c9a754

View file

@ -485,6 +485,14 @@ MapWidget::~MapWidget()
clearData(); clearData();
} }
static void createPropertyIfRequired(SGPropertyNode_ptr p, const std::string& name, bool defaultValue)
{
auto existing = p->getChild(name);
if (!existing) {
p->setBoolValue(name, defaultValue);
}
}
void MapWidget::setProperty(SGPropertyNode_ptr prop) void MapWidget::setProperty(SGPropertyNode_ptr prop)
{ {
_root = prop; _root = prop;
@ -495,17 +503,12 @@ void MapWidget::setProperty(SGPropertyNode_ptr prop)
// expose MAX_ZOOM to the UI // expose MAX_ZOOM to the UI
_root->setIntValue("max-zoom", MAX_ZOOM); _root->setIntValue("max-zoom", MAX_ZOOM);
_root->setBoolValue("centre-on-aircraft", true);
_root->setBoolValue("draw-data", false);
_root->setBoolValue("draw-flight-history", false);
_root->setBoolValue("magnetic-headings", true);
/* If /gui/map/key-pan is undefined, fgdata's gui/dialogs/map.xml will set it createPropertyIfRequired(_root, "centre-on-aircraft", true);
to "" when it opens map, so if we see this we change to default value of 1. createPropertyIfRequired(_root, "draw-data", false);
*/ createPropertyIfRequired(_root, "draw-flight-history", false);
if (!strcmp( _root->getStringValue("key-pan"), "")) { createPropertyIfRequired(_root, "magnetic-headings", true);
_root->setIntValue("key-pan", 1); createPropertyIfRequired(_root, "key-pan", true);
}
} }
void MapWidget::setSize(int w, int h) void MapWidget::setSize(int w, int h)