Core: Give a hint why saving of settings are requested

Not all requests are the same, handling code might want to act
differently on different request reasons.

Main driver here is the handling of the debugger/analyzer main window
state savings which depends on actual visibility of certain windows.

Change-Id: I87b2a9149e3d09d27bc14b44aace9f2e0686db04
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2019-06-03 09:32:15 +02:00
parent 23c222f61b
commit 4742216feb
5 changed files with 15 additions and 8 deletions

View File

@@ -726,7 +726,7 @@ void SettingsDialog::done(int val)
QSettings *settings = ICore::settings();
settings->setValue(QLatin1String(pageKeyC), m_currentPage.toSetting());
ICore::saveSettings(); // save all settings
ICore::saveSettings(ICore::SettingsDialogDone); // save all settings
// exit event loops in reverse order of addition
for (QEventLoop *eventLoop : m_eventLoops)

View File

@@ -330,7 +330,7 @@ ICore::ICore(MainWindow *mainwindow)
m_mainwindow = mainwindow;
// Save settings once after all plugins are initialized:
connect(PluginManager::instance(), &PluginManager::initializationDone,
this, &ICore::saveSettings);
this, [] { ICore::saveSettings(ICore::InitializationDone); });
connect(PluginManager::instance(), &PluginManager::testsFinished, [this] (int failedTests) {
emit coreAboutToClose();
if (failedTests != 0)
@@ -690,9 +690,9 @@ void ICore::setupScreenShooter(const QString &name, QWidget *w, const QRect &rc)
new ScreenShooter(w, name, rc);
}
void ICore::saveSettings()
void ICore::saveSettings(SaveSettingsReason reason)
{
emit m_instance->saveSettingsRequested();
emit m_instance->saveSettingsRequested(reason);
m_mainwindow->saveSettings();
ICore::settings(QSettings::SystemScope)->sync();

View File

@@ -141,14 +141,21 @@ public:
static QString systemInformation();
static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
enum SaveSettingsReason {
InitializationDone,
SettingsDialogDone,
ModeChanged,
MainWindowClosing,
};
public slots:
static void saveSettings();
static void saveSettings(SaveSettingsReason reason);
signals:
void coreAboutToOpen();
void coreOpened();
void newItemDialogStateChanged();
void saveSettingsRequested();
void saveSettingsRequested(SaveSettingsReason reason);
void coreAboutToClose();
void contextAboutToChange(const QList<Core::IContext *> &context);
void contextChanged(const Core::Context &context);

View File

@@ -322,7 +322,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
return;
}
ICore::saveSettings();
ICore::saveSettings(ICore::MainWindowClosing);
// Save opened files
if (!DocumentManager::saveAllModifiedDocuments()) {

View File

@@ -2098,7 +2098,7 @@ void ProjectExplorerPluginPrivate::currentModeChanged(Id mode, Id oldMode)
// Saving settings directly in a mode change is not a good idea, since the mode change
// can be part of a bigger change. Save settings after that bigger change had a chance to
// complete.
QTimer::singleShot(0, ICore::instance(), &ICore::saveSettings);
QTimer::singleShot(0, ICore::instance(), [] { ICore::saveSettings(ICore::ModeChanged); });
}
if (mode == Core::Constants::MODE_WELCOME)
updateWelcomePage();