From c3543f8fdd15cc56f6672d7cad6a52ddb03087ae Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 8 Mar 2015 00:40:22 +0000 Subject: [PATCH] =?UTF-8?q?GUI=20=E2=80=98restore=20defaults=E2=80=99=20su?= =?UTF-8?q?pport.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Hold ‘alt’ on launch to restore defaults, including launcher prefs. --- src/GUI/QtLauncher.cxx | 14 +++++++++++++- src/Main/fg_init.cxx | 25 +++++++++++++++---------- src/Navaids/NavDataCache.cxx | 12 +++++++----- src/Navaids/NavDataCache.hxx | 3 +++ 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/GUI/QtLauncher.cxx b/src/GUI/QtLauncher.cxx index 2d1f167eb..27fd59c20 100644 --- a/src/GUI/QtLauncher.cxx +++ b/src/GUI/QtLauncher.cxx @@ -81,7 +81,7 @@ const int AircraftVariantDescriptionRole = Qt::UserRole + 200; void initNavCache() { - NavDataCache* cache = NavDataCache::instance(); + NavDataCache* cache = NavDataCache::createInstance(); if (cache->isRebuildRequired()) { QProgressDialog rebuildProgress("Initialising navigation data, this may take several minutes", QString() /* cancel text */, @@ -1102,6 +1102,18 @@ void QtLauncher::initApp(int argc, char** argv) // avoid double Apple menu and other weirdness if both Qt and OSG // try to initialise various Cocoa structures. flightgear::WindowBuilder::setPoseAsStandaloneApp(false); + + Qt::KeyboardModifiers mods = app->queryKeyboardModifiers(); + if (mods & Qt::AltModifier) { + qWarning() << "Alt pressed during launch"; + + // wipe out our settings + QSettings settings; + settings.clear(); + + + Options::sharedInstance()->addOption("restore-defaults", ""); + } } } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 41568a42b..c18e2d75d 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -590,17 +590,22 @@ int fgInitAircraft(bool reinit) bool fgInitNav () { - flightgear::NavDataCache* cache = flightgear::NavDataCache::instance(); - static bool doingRebuild = false; - if (doingRebuild || cache->isRebuildRequired()) { - doingRebuild = true; - bool finished = cache->rebuild(); - if (!finished) { - // sleep to give the rebuild thread more time - SGTimeStamp::sleepForMSec(50); - return false; + flightgear::NavDataCache* cache = flightgear::NavDataCache::instance(); + static bool doingRebuild = false; + + if (!cache) { + cache = flightgear::NavDataCache::createInstance(); + doingRebuild = cache->isRebuildRequired(); + } + + if (doingRebuild) { + bool finished = cache->rebuild(); + if (!finished) { + // sleep to give the rebuild thread more time + SGTimeStamp::sleepForMSec(50); + return false; + } } - } // depend on when the NavCache was initialised, scenery paths may not // have been setup. This is a safe place to consistently check the value, diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 18666d4d5..1a5b696ab 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -1121,20 +1121,22 @@ NavDataCache::NavDataCache() d->airwayDatPath = SGPath(globals->get_fg_root()); d->airwayDatPath.append("Navaids/awy.dat.gz"); } - + NavDataCache::~NavDataCache() { assert(static_instance == this); static_instance = NULL; d.reset(); } + +NavDataCache* NavDataCache::createInstance() +{ + static_instance = new NavDataCache; + return static_instance; +} NavDataCache* NavDataCache::instance() { - if (!static_instance) { - static_instance = new NavDataCache; - } - return static_instance; } diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index bf87c2423..47220d073 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -58,6 +58,9 @@ public: // singleton accessor static NavDataCache* instance(); +// static creator + static NavDataCache* createInstance(); + SGPath path() const; /**