Remove RestartDialog in favor of static function

The pattern was always to create the dialog and exec it, which can be
done as well with just a function call.

Change-Id: I3934cf5d869211713902abd333aa64d87ec59f32
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Eike Ziller
2024-01-26 12:23:01 +01:00
parent fca5c4fe96
commit cdef799321
13 changed files with 35 additions and 91 deletions

View File

@@ -53,8 +53,6 @@ add_qtc_plugin(Core
dialogs/promptoverwritedialog.h dialogs/promptoverwritedialog.h
dialogs/readonlyfilesdialog.cpp dialogs/readonlyfilesdialog.cpp
dialogs/readonlyfilesdialog.h dialogs/readonlyfilesdialog.h
dialogs/restartdialog.cpp
dialogs/restartdialog.h
dialogs/saveitemsdialog.cpp dialogs/saveitemsdialog.cpp
dialogs/saveitemsdialog.h dialogs/saveitemsdialog.h
dialogs/settingsdialog.cpp dialogs/settingsdialog.cpp

View File

@@ -205,7 +205,6 @@ QtcPlugin {
"openwithdialog.cpp", "openwithdialog.h", "openwithdialog.cpp", "openwithdialog.h",
"promptoverwritedialog.cpp", "promptoverwritedialog.h", "promptoverwritedialog.cpp", "promptoverwritedialog.h",
"readonlyfilesdialog.cpp", "readonlyfilesdialog.h", "readonlyfilesdialog.cpp", "readonlyfilesdialog.h",
"restartdialog.cpp", "restartdialog.h",
"saveitemsdialog.cpp", "saveitemsdialog.h", "saveitemsdialog.cpp", "saveitemsdialog.h",
"settingsdialog.cpp", "settingsdialog.h", "settingsdialog.cpp", "settingsdialog.h",
"shortcutsettings.cpp", "shortcutsettings.h", "shortcutsettings.cpp", "shortcutsettings.h",

View File

@@ -1,25 +0,0 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "restartdialog.h"
#include "../coreplugintr.h"
#include "../icore.h"
#include <QPushButton>
namespace Core {
RestartDialog::RestartDialog(QWidget *parent, const QString &text)
: QMessageBox(parent)
{
setWindowTitle(Tr::tr("Restart Required"));
setText(text);
setIcon(QMessageBox::Information);
addButton(Tr::tr("Later"), QMessageBox::NoRole);
addButton(Tr::tr("Restart Now"), QMessageBox::YesRole);
connect(this, &QDialog::accepted, ICore::instance(), &ICore::restart, Qt::QueuedConnection);
}
} // namespace Core

View File

@@ -1,19 +0,0 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include "../core_global.h"
#include <QCoreApplication>
#include <QMessageBox>
namespace Core {
class CORE_EXPORT RestartDialog : public QMessageBox
{
public:
RestartDialog(QWidget *parent, const QString &text);
};
} // namespace Core

View File

@@ -1,7 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "dialogs/restartdialog.h"
#include "dialogs/ioptionspage.h" #include "dialogs/ioptionspage.h"
#include "generalsettings.h" #include "generalsettings.h"
#include "coreconstants.h" #include "coreconstants.h"
@@ -296,11 +295,8 @@ QString GeneralSettingsWidget::language()
void GeneralSettingsWidget::setLanguage(const QString &locale) void GeneralSettingsWidget::setLanguage(const QString &locale)
{ {
QtcSettings *settings = ICore::settings(); QtcSettings *settings = ICore::settings();
if (settings->value("General/OverrideLanguage").toString() != locale) { if (settings->value("General/OverrideLanguage").toString() != locale)
RestartDialog dialog(ICore::dialogParent(), ICore::askForRestart(Tr::tr("The language change will take effect after restart."));
Tr::tr("The language change will take effect after restart."));
dialog.exec();
}
settings->setValueWithDefault("General/OverrideLanguage", locale, {}); settings->setValueWithDefault("General/OverrideLanguage", locale, {});
} }
@@ -359,10 +355,8 @@ void GeneralSettingsWidget::setDpiPolicy(Qt::HighDpiScaleFactorRoundingPolicy po
settingsKeyDpiPolicy, settingsKeyDpiPolicy,
int(StyleHelper::defaultHighDpiScaleFactorRoundingPolicy())).value<Policy>(); int(StyleHelper::defaultHighDpiScaleFactorRoundingPolicy())).value<Policy>();
if (policy != previousPolicy) { if (policy != previousPolicy) {
RestartDialog dialog(ICore::dialogParent(), ICore::askForRestart(
Tr::tr("The DPI rounding policy change will take effect after " Tr::tr("The DPI rounding policy change will take effect after restart."));
"restart."));
dialog.exec();
} }
settings->setValueWithDefault(settingsKeyDpiPolicy, int(policy), settings->setValueWithDefault(settingsKeyDpiPolicy, int(policy),
int(StyleHelper::defaultHighDpiScaleFactorRoundingPolicy())); int(StyleHelper::defaultHighDpiScaleFactorRoundingPolicy()));

View File

@@ -907,6 +907,24 @@ Utils::InfoBar *ICore::infoBar()
return d->m_modeStack->infoBar(); return d->m_modeStack->infoBar();
} }
/*!
Shows a modal dialog that asks the user if they want to restart \QC.
Uses \a text as the main text in the dialog, and triggers a restart
of \QC if the user chooses that option.
*/
void ICore::askForRestart(const QString &text)
{
QMessageBox mb(dialogParent());
mb.setWindowTitle(Tr::tr("Restart Required"));
mb.setText(text);
mb.setIcon(QMessageBox::Information);
mb.addButton(Tr::tr("Later"), QMessageBox::NoRole);
mb.addButton(Tr::tr("Restart Now"), QMessageBox::YesRole);
mb.connect(&mb, &QDialog::accepted, ICore::instance(), &ICore::restart, Qt::QueuedConnection);
mb.exec();
}
/*! /*!
Raises and activates the window for \a widget. This contains workarounds Raises and activates the window for \a widget. This contains workarounds
for X11. for X11.

View File

@@ -82,6 +82,8 @@ public:
static QWidget *dialogParent(); static QWidget *dialogParent();
static Utils::InfoBar *infoBar(); static Utils::InfoBar *infoBar();
static void askForRestart(const QString &text);
static void raiseWindow(QWidget *widget); static void raiseWindow(QWidget *widget);
static void raiseMainWindow(); static void raiseMainWindow();

View File

@@ -5,7 +5,6 @@
#include "coreplugin.h" #include "coreplugin.h"
#include "coreplugintr.h" #include "coreplugintr.h"
#include "dialogs/restartdialog.h"
#include "icore.h" #include "icore.h"
#include "plugininstallwizard.h" #include "plugininstallwizard.h"
@@ -92,11 +91,8 @@ void PluginDialog::closeDialog()
for (PluginSpec *plugin : std::as_const(m_softLoad)) for (PluginSpec *plugin : std::as_const(m_softLoad))
CorePlugin::loadMimeFromPlugin(plugin); CorePlugin::loadMimeFromPlugin(plugin);
if (m_isRestartRequired) { if (m_isRestartRequired)
RestartDialog restartDialog(ICore::dialogParent(), ICore::askForRestart(Tr::tr("Plugin changes will take effect after restart."));
Tr::tr("Plugin changes will take effect after restart."));
restartDialog.exec();
}
accept(); accept();
} }

View File

@@ -7,7 +7,6 @@
#include "coreplugin.h" #include "coreplugin.h"
#include "coreplugintr.h" #include "coreplugintr.h"
#include "editormanager/editormanager_p.h" #include "editormanager/editormanager_p.h"
#include "dialogs/restartdialog.h"
#include "dialogs/ioptionspage.h" #include "dialogs/ioptionspage.h"
#include "fileutils.h" #include "fileutils.h"
#include "icore.h" #include "icore.h"
@@ -406,10 +405,8 @@ void SystemSettingsWidget::apply()
m_fileSystemCaseSensitivityChooser->currentData().toInt()); m_fileSystemCaseSensitivityChooser->currentData().toInt());
if (selectedSensitivity != sensitivity) { if (selectedSensitivity != sensitivity) {
EditorManagerPrivate::writeFileSystemSensitivity(settings, selectedSensitivity); EditorManagerPrivate::writeFileSystemSensitivity(settings, selectedSensitivity);
RestartDialog dialog( ICore::askForRestart(
ICore::dialogParent(),
Tr::tr("The file system case sensitivity change will take effect after restart.")); Tr::tr("The file system case sensitivity change will take effect after restart."));
dialog.exec();
} }
} }

View File

@@ -5,7 +5,6 @@
#include "coreconstants.h" #include "coreconstants.h"
#include "coreplugintr.h" #include "coreplugintr.h"
#include "dialogs/restartdialog.h"
#include "icore.h" #include "icore.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -164,9 +163,7 @@ void ThemeChooser::apply()
if (currentThemeId != themeId) { if (currentThemeId != themeId) {
// save filename of selected theme in global config // save filename of selected theme in global config
settings->setValueWithDefault(Constants::SETTINGS_THEME, themeId, defaultThemeId()); settings->setValueWithDefault(Constants::SETTINGS_THEME, themeId, defaultThemeId());
RestartDialog restartDialog(ICore::dialogParent(), ICore::askForRestart(Tr::tr("The theme change will take effect after restart."));
Tr::tr("The theme change will take effect after restart."));
restartDialog.exec();
} }
} }

View File

@@ -6,7 +6,6 @@
#include "../utils/designerpaths.h" #include "../utils/designerpaths.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/dialogs/restartdialog.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
@@ -174,10 +173,8 @@ void StudioSettingsPage::apply()
dirty); dirty);
if (dirty) { if (dirty) {
const QString restartText = tr( Core::ICore::askForRestart(
"The menu visibility change will take effect after restart."); tr("The menu visibility change will take effect after restart."));
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
restartDialog.exec();
} }
QtcSettings *s = Core::ICore::settings(); QtcSettings *s = Core::ICore::settings();
@@ -194,9 +191,7 @@ void StudioSettingsPage::apply()
s->setValue(Paths::bundlesDownloadPath, bundlesPath); s->setValue(Paths::bundlesDownloadPath, bundlesPath);
emit bundlesDownloadPathChanged(bundlesPath); emit bundlesDownloadPathChanged(bundlesPath);
const QString restartText = tr("Changing bundle path will take effect after restart."); Core::ICore::askForRestart(tr("Changing bundle path will take effect after restart."));
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
restartDialog.exec();
} }
} }

View File

@@ -10,7 +10,6 @@
#include "qtversionfactory.h" #include "qtversionfactory.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/dialogs/restartdialog.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -1053,10 +1052,8 @@ void QtSettingsPageWidget::linkWithQt()
askForRestart = true; askForRestart = true;
} }
} }
if (askForRestart) { if (askForRestart)
RestartDialog restartDialog(ICore::dialogParent(), restartText); ICore::askForRestart(restartText);
restartDialog.exec();
}
} }
// QtSettingsPage // QtSettingsPage

View File

@@ -7,7 +7,6 @@
#include "qdsnewdialog.h" #include "qdsnewdialog.h"
#include <coreplugin/coreconstants.h> #include <coreplugin/coreconstants.h>
#include <coreplugin/dialogs/restartdialog.h>
#include <coreplugin/documentmanager.h> #include <coreplugin/documentmanager.h>
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
@@ -180,9 +179,7 @@ public:
Core::ICore::settings()->setValue(CRASH_REPORTER_SETTING, b); Core::ICore::settings()->setValue(CRASH_REPORTER_SETTING, b);
const QString restartText = tr("The change will take effect after restart."); Core::ICore::askForRestart(tr("The change will take effect after restart."));
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
restartDialog.exec();
setupModel(); setupModel();
} }
@@ -196,9 +193,7 @@ public:
settings->setValue(STATISTICS_COLLECTION_MODE, b ? DETAILED_USAGE_STATISTICS : NO_TELEMETRY); settings->setValue(STATISTICS_COLLECTION_MODE, b ? DETAILED_USAGE_STATISTICS : NO_TELEMETRY);
const QString restartText = tr("The change will take effect after restart."); Core::ICore::askForRestart(tr("The change will take effect after restart."));
Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText);
restartDialog.exec();
setupModel(); setupModel();
} }