diff --git a/src/QGCConfig.h b/src/QGCConfig.h index 79c3f7a8b017439812caf8c8d66a6104b19afc3c..df51e216be53ec037afd841929d31825004f745f 100644 --- a/src/QGCConfig.h +++ b/src/QGCConfig.h @@ -10,6 +10,10 @@ #define MAVLINK_HEARTBEAT_DEFAULT_RATE 1 #define WITH_TEXT_TO_SPEECH 1 +// If you need to make an incompatible changes to stored settings, bump this version number +// up by 1. This will caused store settings to be cleared on next boot. +#define QGC_SETTINGS_VERSION 1 + #define QGC_APPLICATION_NAME "QGroundControl" #define QGC_APPLICATION_VERSION_BASE "v2.0.3" diff --git a/src/QGCCore.cc b/src/QGCCore.cc index fbbb7ab26da6a0874089869978eba4df95138d6a..939834db165d1a76566ccc51b1fb7881a2cbe4d9 100644 --- a/src/QGCCore.cc +++ b/src/QGCCore.cc @@ -55,6 +55,7 @@ This file is part of the QGROUNDCONTROL project #include "MAVLinkSimulationLink.h" #include "SerialLink.h" +const char* QGCCore::_settingsVersionKey = "SettingsVersion"; /** * @brief Constructor for the main application. @@ -108,31 +109,25 @@ bool QGCCore::init(void) // Exit main application when last window is closed connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit())); - - // Show user an upgrade message if QGC got upgraded (see code below, after splash screen) - bool upgraded = false; + // Show user an upgrade message if the settings version has been bumped up + bool settingsUpgraded = false; enum MainWindow::CUSTOM_MODE mode = MainWindow::CUSTOM_MODE_PX4; - QString lastApplicationVersion(""); - if (settings.contains("QGC_APPLICATION_VERSION")) - { - QString qgcVersion = settings.value("QGC_APPLICATION_VERSION").toString(); - if (qgcVersion != QGC_APPLICATION_VERSION) - { - lastApplicationVersion = qgcVersion; - settings.clear(); // Clear settings from different version - // Write current application version - settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION); - upgraded = true; - } else { - mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt(); + if (settings.contains(_settingsVersionKey)) { + if (settings.value(_settingsVersionKey).toInt() != QGC_SETTINGS_VERSION) { + settingsUpgraded = true; } - } else { - // If application version is not set, clear settings anyway + } else if (settings.allKeys().count()) { + // Settings version key is missing and there are settings. This is an upgrade scenario. + settingsUpgraded = true; + } + + if (settingsUpgraded) { settings.clear(); - // Write current application version - settings.setValue("QGC_APPLICATION_VERSION", QGC_APPLICATION_VERSION); + settings.setValue(_settingsVersionKey, QGC_SETTINGS_VERSION); } + mode = (enum MainWindow::CUSTOM_MODE) settings.value("QGC_CUSTOM_MODE", (int)MainWindow::CUSTOM_MODE_PX4).toInt(); + settings.sync(); // Show splash screen @@ -192,8 +187,11 @@ bool QGCCore::init(void) // Remove splash screen splashScreen->finish(_mainWindow); - if (upgraded) _mainWindow->showInfoMessage(tr("Default Settings Loaded"), - tr("qgroundcontrol has been upgraded from version %1 to version %2. Some of your user preferences have been reset to defaults for safety reasons. Please adjust them where needed.").arg(lastApplicationVersion).arg(QGC_APPLICATION_VERSION)); + if (settingsUpgraded) { + _mainWindow->showInfoMessage(tr("Settings Cleared"), + tr("The format for QGroundControl saved settings has been modified. " + "Your saved settings have been reset to defaults.")); + } // Check if link could be connected if (udpLink && !udpLink->connect()) diff --git a/src/QGCCore.h b/src/QGCCore.h index c6c3c4186712f98940508723153673f0b7d71cd4..b1f73ce935719185f24292a89c0d01fe661d503d 100644 --- a/src/QGCCore.h +++ b/src/QGCCore.h @@ -72,7 +72,8 @@ protected: void startUASManager(); private: - MainWindow* _mainWindow; + MainWindow* _mainWindow; + static const char* _settingsVersionKey; }; #endif /* _CORE_H_ */