From d740a355bb1954714234edd13194ce158540bcc0 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 19 May 2023 10:09:59 +0200 Subject: [PATCH] Utils: Rework CheckableMessageBox Remove function overloads, thes are hard to read, to use and to extend. I'd even argue this should be a plain default ctor and a few setters + exec(), pretty much like Process::start() nowadays. Move "decider" magic into a structure that can be filled ad-hoc outside checkablemessagebox.cpp paving the ground for: ...removing aspect dependency from CheckableMessageBox, Instead, add a convenience function to BoolAspect. Arguably, the latter is not needed and could be done on the user side. Use pointers instead of mutable references for in-out parameter. Makes the "specialness" visible on the user side. Pass ICore::settings() centrally as done elsewhere to reduce line noise on the user side. Change-Id: Ibb366353d1ea35401723fd05ce05672617a0a8fd Reviewed-by: Marcus Tillmanns --- src/libs/utils/aspects.cpp | 12 +- src/libs/utils/aspects.h | 4 +- src/libs/utils/checkablemessagebox.cpp | 141 ++++++------ src/libs/utils/checkablemessagebox.h | 201 ++---------------- src/plugins/bookmarks/bookmarkmanager.cpp | 3 +- src/plugins/clangtools/clangtool.cpp | 3 +- src/plugins/clangtools/clangtoolsutils.cpp | 3 +- .../cmakebuildconfiguration.cpp | 2 +- .../cmakeprojectmanager.cpp | 2 +- src/plugins/coreplugin/coreplugin.cpp | 1 + .../editormanager/editormanager.cpp | 2 +- src/plugins/coreplugin/generalsettings.cpp | 5 +- .../coreplugin/locator/filesystemfilter.cpp | 3 +- src/plugins/debugger/breakhandler.cpp | 3 +- src/plugins/debugger/cdb/cdbengine.cpp | 6 +- src/plugins/debugger/debuggerengine.cpp | 9 +- src/plugins/debugger/debuggerplugin.cpp | 3 +- src/plugins/debugger/debuggerruncontrol.cpp | 2 +- src/plugins/debugger/watchhandler.cpp | 3 +- src/plugins/git/gitclient.cpp | 3 +- src/plugins/projectexplorer/runcontrol.cpp | 5 +- .../propertyeditor/aligndistribute.cpp | 3 +- src/plugins/squish/squishnavigationwidget.cpp | 3 +- .../studiowelcome/studiowelcomeplugin.cpp | 6 +- src/plugins/valgrind/memchecktool.cpp | 3 +- src/plugins/welcome/introductionwidget.cpp | 5 +- src/plugins/welcome/introductionwidget.h | 3 +- src/plugins/welcome/welcomeplugin.cpp | 3 +- .../crashhandlerdialog.cpp | 6 +- 29 files changed, 129 insertions(+), 319 deletions(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index 082f4f8244a..e96014eba14 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -4,6 +4,7 @@ #include "aspects.h" #include "algorithm.h" +#include "checkablemessagebox.h" #include "environment.h" #include "fancylineedit.h" #include "layoutbuilder.h" @@ -1358,11 +1359,10 @@ FilePathAspect::FilePathAspect() The color aspect is displayed using a QtColorButton. */ -ColorAspect::ColorAspect(const QString &settingsKey) +ColorAspect::ColorAspect() : d(new Internal::ColorAspectPrivate) { setDefaultValue(QColor::fromRgb(0, 0, 0)); - setSettingsKey(settingsKey); setSpan(1, 1); addDataExtractor(this, &ColorAspect::value, &Data::value); @@ -1587,6 +1587,14 @@ void BoolAspect::setLabelPlacement(BoolAspect::LabelPlacement labelPlacement) d->m_labelPlacement = labelPlacement; } +CheckableDecider BoolAspect::checkableDecider() +{ + return CheckableDecider( + [this] { return !value(); }, + [this] { setValue(true); } + ); +} + /*! \class Utils::SelectionAspect \inmodule QtCreator diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index f6a35fa4ef8..1086c7445b6 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -24,6 +24,7 @@ namespace Utils { class AspectContainer; class BoolAspect; +class CheckableDecider; namespace Internal { class AspectContainerPrivate; @@ -222,6 +223,7 @@ public: void addToLayout(Layouting::LayoutItem &parent) override; std::function groupChecker(); + Utils::CheckableDecider checkableDecider(); QAction *action() override; @@ -255,7 +257,7 @@ class QTCREATOR_UTILS_EXPORT ColorAspect : public BaseAspect Q_OBJECT public: - explicit ColorAspect(const QString &settingsKey = QString()); + ColorAspect(); ~ColorAspect() override; struct Data : BaseAspect::Data diff --git a/src/libs/utils/checkablemessagebox.cpp b/src/libs/utils/checkablemessagebox.cpp index bf566e53a8a..d09c2941752 100644 --- a/src/libs/utils/checkablemessagebox.cpp +++ b/src/libs/utils/checkablemessagebox.cpp @@ -31,16 +31,19 @@ static const char kDoNotAskAgainKey[] = "DoNotAskAgain"; namespace Utils { +static QSettings *theSettings; + static QMessageBox::StandardButton exec( QWidget *parent, QMessageBox::Icon icon, const QString &title, const QString &text, - std::optional decider, + const CheckableDecider &decider, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton, QMessageBox::StandardButton acceptButton, - QMap buttonTextOverrides) + QMap buttonTextOverrides, + const QString &msg) { QMessageBox msgBox(parent); msgBox.setWindowTitle(title); @@ -59,18 +62,13 @@ static QMessageBox::StandardButton exec( } } - if (decider) { - if (!CheckableMessageBox::shouldAskAgain(*decider)) + if (decider.shouldAskAgain) { + if (!decider.shouldAskAgain()) return acceptButton; msgBox.setCheckBox(new QCheckBox); msgBox.checkBox()->setChecked(false); - - std::visit( - [&msgBox](auto &&decider) { - msgBox.checkBox()->setText(decider.text); - }, - *decider); + msgBox.checkBox()->setText(msg); } msgBox.setStandardButtons(buttons); @@ -81,21 +79,44 @@ static QMessageBox::StandardButton exec( QMessageBox::StandardButton clickedBtn = msgBox.standardButton(msgBox.clickedButton()); - if (decider && msgBox.checkBox()->isChecked() + if (decider.doNotAskAgain && msgBox.checkBox()->isChecked() && (acceptButton == QMessageBox::NoButton || clickedBtn == acceptButton)) - CheckableMessageBox::doNotAskAgain(*decider); + decider.doNotAskAgain(); return clickedBtn; } +CheckableDecider::CheckableDecider(const QString &settingsSubKey) +{ + QTC_ASSERT(theSettings, return); + shouldAskAgain = [settingsSubKey] { + theSettings->beginGroup(QLatin1String(kDoNotAskAgainKey)); + bool shouldNotAsk = theSettings->value(settingsSubKey, false).toBool(); + theSettings->endGroup(); + return !shouldNotAsk; + }; + doNotAskAgain = [settingsSubKey] { + theSettings->beginGroup(QLatin1String(kDoNotAskAgainKey)); + theSettings->setValue(settingsSubKey, true); + theSettings->endGroup(); + }; +} + +CheckableDecider::CheckableDecider(bool *storage) +{ + shouldAskAgain = [storage] { return !*storage; }; + doNotAskAgain = [storage] { *storage = true; }; +} + QMessageBox::StandardButton CheckableMessageBox::question( QWidget *parent, const QString &title, const QString &question, - std::optional decider, + const CheckableDecider &decider, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton, QMessageBox::StandardButton acceptButton, - QMap buttonTextOverrides) + QMap buttonTextOverrides, + const QString &msg) { return exec(parent, QMessageBox::Question, @@ -105,17 +126,19 @@ QMessageBox::StandardButton CheckableMessageBox::question( buttons, defaultButton, acceptButton, - buttonTextOverrides); + buttonTextOverrides, + msg.isEmpty() ? msgDoNotAskAgain() : msg); } QMessageBox::StandardButton CheckableMessageBox::information( QWidget *parent, const QString &title, const QString &text, - std::optional decider, + const CheckableDecider &decider, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton, - QMap buttonTextOverrides) + QMap buttonTextOverrides, + const QString &msg) { return exec(parent, QMessageBox::Information, @@ -125,82 +148,33 @@ QMessageBox::StandardButton CheckableMessageBox::information( buttons, defaultButton, QMessageBox::NoButton, - buttonTextOverrides); -} - -void CheckableMessageBox::doNotAskAgain(Decider &decider) -{ - std::visit( - [](auto &&decider) { - using T = std::decay_t; - if constexpr (std::is_same_v) { - decider.doNotAskAgain = true; - } else if constexpr (std::is_same_v) { - decider.settings->beginGroup(QLatin1String(kDoNotAskAgainKey)); - decider.settings->setValue(decider.settingsSubKey, true); - decider.settings->endGroup(); - } else if constexpr (std::is_same_v) { - decider.aspect.setValue(true); - } - }, - decider); -} - -bool CheckableMessageBox::shouldAskAgain(const Decider &decider) -{ - bool result = std::visit( - [](auto &&decider) { - using T = std::decay_t; - if constexpr (std::is_same_v) { - return !decider.doNotAskAgain; - } else if constexpr (std::is_same_v) { - decider.settings->beginGroup(QLatin1String(kDoNotAskAgainKey)); - bool shouldNotAsk = decider.settings->value(decider.settingsSubKey, false).toBool(); - decider.settings->endGroup(); - return !shouldNotAsk; - } else if constexpr (std::is_same_v) { - return !decider.aspect.value(); - } - }, - decider); - - return result; -} - -bool CheckableMessageBox::shouldAskAgain(QSettings *settings, const QString &key) -{ - return shouldAskAgain(make_decider(settings, key)); -} - -void CheckableMessageBox::doNotAskAgain(QSettings *settings, const QString &key) -{ - Decider decider = make_decider(settings, key); - return doNotAskAgain(decider); + buttonTextOverrides, + msg.isEmpty() ? msgDoNotShowAgain() : msg); } /*! - Resets all suppression settings for doNotAskAgainQuestion() found in \a settings, + Resets all suppression settings for doNotAskAgainQuestion() so all these message boxes are shown again. */ -void CheckableMessageBox::resetAllDoNotAskAgainQuestions(QSettings *settings) +void CheckableMessageBox::resetAllDoNotAskAgainQuestions() { - QTC_ASSERT(settings, return); - settings->beginGroup(QLatin1String(kDoNotAskAgainKey)); - settings->remove(QString()); - settings->endGroup(); + QTC_ASSERT(theSettings, return); + theSettings->beginGroup(QLatin1String(kDoNotAskAgainKey)); + theSettings->remove(QString()); + theSettings->endGroup(); } /*! Returns whether any message boxes from doNotAskAgainQuestion() are suppressed - in the \a settings. + in the settings. */ -bool CheckableMessageBox::hasSuppressedQuestions(QSettings *settings) +bool CheckableMessageBox::hasSuppressedQuestions() { - QTC_ASSERT(settings, return false); - settings->beginGroup(QLatin1String(kDoNotAskAgainKey)); - const bool hasSuppressed = !settings->childKeys().isEmpty() - || !settings->childGroups().isEmpty(); - settings->endGroup(); + QTC_ASSERT(theSettings, return false); + theSettings->beginGroup(QLatin1String(kDoNotAskAgainKey)); + const bool hasSuppressed = !theSettings->childKeys().isEmpty() + || !theSettings->childGroups().isEmpty(); + theSettings->endGroup(); return hasSuppressed; } @@ -222,4 +196,9 @@ QString CheckableMessageBox::msgDoNotShowAgain() return Tr::tr("Do not &show again"); } +void CheckableMessageBox::initialize(QSettings *settings) +{ + theSettings = settings; +} + } // namespace Utils diff --git a/src/libs/utils/checkablemessagebox.h b/src/libs/utils/checkablemessagebox.h index 1f4c84e1a79..3f156b2de1a 100644 --- a/src/libs/utils/checkablemessagebox.h +++ b/src/libs/utils/checkablemessagebox.h @@ -5,8 +5,6 @@ #include "utils_global.h" -#include "aspects.h" - #include QT_BEGIN_NAMESPACE @@ -15,208 +13,51 @@ QT_END_NAMESPACE namespace Utils { -class CheckableMessageBoxPrivate; +class QTCREATOR_UTILS_EXPORT CheckableDecider +{ +public: + CheckableDecider() = default; + CheckableDecider(const QString &settingsSubKey); + CheckableDecider(bool *doNotAskAgain); + CheckableDecider(const std::function &should, const std::function &doNot) + : shouldAskAgain(should), doNotAskAgain(doNot) + {} + + std::function shouldAskAgain; + std::function doNotAskAgain; +}; class QTCREATOR_UTILS_EXPORT CheckableMessageBox { public: - struct BoolDecision - { - QString text; - bool &doNotAskAgain; - }; - - struct SettingsDecision - { - QString text; - QSettings *settings; - QString settingsSubKey; - }; - - struct AspectDecision - { - QString text; - BoolAspect &aspect; - }; - - using Decider = std::variant; - - static Decider make_decider(QSettings *settings, - const QString &settingsSubKey, - const QString &text = msgDoNotAskAgain()) - { - return Decider{SettingsDecision{text, settings, settingsSubKey}}; - } - - static Decider make_decider(bool &doNotAskAgain, const QString &text = msgDoNotAskAgain()) - { - return Decider{BoolDecision{text, doNotAskAgain}}; - } - - static Decider make_decider(BoolAspect &aspect, const QString &text = msgDoNotAskAgain()) - { - return Decider{AspectDecision{text, aspect}}; - } - static QMessageBox::StandardButton question( QWidget *parent, const QString &title, const QString &question, - std::optional decider = std::nullopt, - QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, - QMessageBox::StandardButton defaultButton = QMessageBox::No, - QMessageBox::StandardButton acceptButton = QMessageBox::Yes, - QMap buttonTextOverrides = {}); - - static QMessageBox::StandardButton question( - QWidget *parent, - const QString &title, - const QString &question, - bool &value, + const CheckableDecider &decider, QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, QMessageBox::StandardButton defaultButton = QMessageBox::No, QMessageBox::StandardButton acceptButton = QMessageBox::Yes, QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(value, text); - return CheckableMessageBox::question(parent, - title, - question, - decider, - buttons, - defaultButton, - acceptButton, - buttonTextOverrides); - } - - static QMessageBox::StandardButton question( - QWidget *parent, - const QString &title, - const QString &question, - QSettings *settings, - const QString &settingsSubKey, - QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, - QMessageBox::StandardButton defaultButton = QMessageBox::No, - QMessageBox::StandardButton acceptButton = QMessageBox::Yes, - QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(settings, settingsSubKey, text); - return CheckableMessageBox::question(parent, - title, - question, - decider, - buttons, - defaultButton, - acceptButton, - buttonTextOverrides); - } - - static QMessageBox::StandardButton question( - QWidget *parent, - const QString &title, - const QString &question, - BoolAspect &aspect, - QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No, - QMessageBox::StandardButton defaultButton = QMessageBox::No, - QMessageBox::StandardButton acceptButton = QMessageBox::Yes, - QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(aspect, text); - return CheckableMessageBox::question(parent, - title, - question, - decider, - buttons, - defaultButton, - acceptButton, - buttonTextOverrides); - } + const QString &msg = {}); static QMessageBox::StandardButton information( QWidget *parent, const QString &title, const QString &text, - std::optional decider = std::nullopt, - QMessageBox::StandardButtons buttons = QMessageBox::Ok, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton, - QMap buttonTextOverrides = {}); - - static QMessageBox::StandardButton information( - QWidget *parent, - const QString &title, - const QString &information, - bool &value, + const CheckableDecider &decider, QMessageBox::StandardButtons buttons = QMessageBox::Ok, QMessageBox::StandardButton defaultButton = QMessageBox::NoButton, QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(value, text); - return CheckableMessageBox::information(parent, - title, - information, - decider, - buttons, - defaultButton, - buttonTextOverrides); - } - - static QMessageBox::StandardButton information( - QWidget *parent, - const QString &title, - const QString &information, - QSettings *settings, - const QString &settingsSubKey, - QMessageBox::StandardButtons buttons = QMessageBox::Ok, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton, - QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(settings, settingsSubKey, text); - return CheckableMessageBox::information(parent, - title, - information, - decider, - buttons, - defaultButton, - buttonTextOverrides); - } - - static QMessageBox::StandardButton information( - QWidget *parent, - const QString &title, - const QString &information, - BoolAspect &aspect, - QMessageBox::StandardButtons buttons = QMessageBox::Ok, - QMessageBox::StandardButton defaultButton = QMessageBox::NoButton, - QMap buttonTextOverrides = {}, - const QString &text = msgDoNotAskAgain()) - { - Decider decider = make_decider(aspect, text); - return CheckableMessageBox::information(parent, - title, - information, - decider, - buttons, - defaultButton, - buttonTextOverrides); - } - - // check and set "ask again" status - static bool shouldAskAgain(const Decider &decider); - static void doNotAskAgain(Decider &decider); - - static bool shouldAskAgain(QSettings *settings, const QString &key); - static void doNotAskAgain(QSettings *settings, const QString &key); + const QString &msg = {}); // Conversion convenience - static void resetAllDoNotAskAgainQuestions(QSettings *settings); - static bool hasSuppressedQuestions(QSettings *settings); + static void resetAllDoNotAskAgainQuestions(); + static bool hasSuppressedQuestions(); static QString msgDoNotAskAgain(); static QString msgDoNotShowAgain(); + + static void initialize(QSettings *settings); }; } // namespace Utils diff --git a/src/plugins/bookmarks/bookmarkmanager.cpp b/src/plugins/bookmarks/bookmarkmanager.cpp index 77bb0f41518..791455d619a 100644 --- a/src/plugins/bookmarks/bookmarkmanager.cpp +++ b/src/plugins/bookmarks/bookmarkmanager.cpp @@ -261,8 +261,7 @@ void BookmarkView::removeAll() Tr::tr("Remove All Bookmarks"), Tr::tr("Are you sure you want to remove all bookmarks from " "all files in the current session?"), - ICore::settings(), - QLatin1String("RemoveAllBookmarks")) + QString("RemoveAllBookmarks")) != QMessageBox::Yes) return; diff --git a/src/plugins/clangtools/clangtool.cpp b/src/plugins/clangtools/clangtool.cpp index 343849458aa..00da4bb880e 100644 --- a/src/plugins/clangtools/clangtool.cpp +++ b/src/plugins/clangtools/clangtool.cpp @@ -602,8 +602,7 @@ static bool continueDespiteReleaseBuild(const QString &toolName) return CheckableMessageBox::question(ICore::dialogParent(), title, message, - ICore::settings(), - "ClangToolsCorrectModeWarning") + QString("ClangToolsCorrectModeWarning")) == QMessageBox::Yes; } diff --git a/src/plugins/clangtools/clangtoolsutils.cpp b/src/plugins/clangtools/clangtoolsutils.cpp index a2cdd5fc7ba..de3ac2b9cba 100644 --- a/src/plugins/clangtools/clangtoolsutils.cpp +++ b/src/plugins/clangtools/clangtoolsutils.cpp @@ -141,8 +141,7 @@ void showHintAboutBuildBeforeAnalysis() Utils::CheckableMessageBox::information(Core::ICore::dialogParent(), Tr::tr("Info About Build the Project Before Analysis"), hintAboutBuildBeforeAnalysis(), - Core::ICore::settings(), - "ClangToolsDisablingBuildBeforeAnalysisHint"); + QString("ClangToolsDisablingBuildBeforeAnalysisHint")); } FilePath fullPath(const FilePath &executable) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp index 7a6a192e80f..5ddc68c1c23 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildconfiguration.cpp @@ -594,7 +594,7 @@ void CMakeBuildSettingsWidget::reconfigureWithInitialParameters() Core::ICore::dialogParent(), Tr::tr("Re-configure with Initial Parameters"), Tr::tr("Clear CMake configuration and configure with initial parameters?"), - settings->askBeforeReConfigureInitialParams, + settings->askBeforeReConfigureInitialParams.checkableDecider(), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index a1950b6bccd..c43c7978a61 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -238,7 +238,7 @@ void CMakeManager::reloadCMakePresets() Tr::tr("Reload CMake Presets"), Tr::tr("Re-generates the CMake presets kits. The manual " "CMake project modifications will be lost."), - settings->askBeforePresetsReload, + settings->askBeforePresetsReload.checkableDecider(), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::Yes, diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index bf8e09b67b5..1a4ec33ef87 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -148,6 +148,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) Theme::setInitialPalette(theme); // Initialize palette before setting it setCreatorTheme(theme); InfoBar::initialize(ICore::settings()); + CheckableMessageBox::initialize(ICore::settings()); new ActionManager(this); ActionManager::setPresentationModeEnabled(args.presentationMode); m_mainWindow = new MainWindow; diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 107ce249e1e..227ffba28c8 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -753,7 +753,7 @@ bool EditorManagerPrivate::skipOpeningBigTextFile(const FilePath &filePath) .arg(fileSizeInMB, 0, 'f', 2); bool askAgain = true; - auto decider = CheckableMessageBox::make_decider(askAgain); + CheckableDecider decider(&askAgain); QMessageBox::StandardButton clickedButton = CheckableMessageBox::question(ICore::dialogParent(), title, text, decider); diff --git a/src/plugins/coreplugin/generalsettings.cpp b/src/plugins/coreplugin/generalsettings.cpp index e97797c9fc7..19b66e64497 100644 --- a/src/plugins/coreplugin/generalsettings.cpp +++ b/src/plugins/coreplugin/generalsettings.cpp @@ -226,14 +226,13 @@ void GeneralSettingsWidget::resetInterfaceColor() void GeneralSettingsWidget::resetWarnings() { InfoBar::clearGloballySuppressed(); - CheckableMessageBox::resetAllDoNotAskAgainQuestions(ICore::settings()); + CheckableMessageBox::resetAllDoNotAskAgainQuestions(); m_resetWarningsButton->setEnabled(false); } bool GeneralSettingsWidget::canResetWarnings() { - return InfoBar::anyGloballySuppressed() - || CheckableMessageBox::hasSuppressedQuestions(ICore::settings()); + return InfoBar::anyGloballySuppressed() || CheckableMessageBox::hasSuppressedQuestions(); } void GeneralSettingsWidget::resetLanguage() diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp index 32ad0a2a2bf..7c6ac13abda 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.cpp +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -63,8 +63,7 @@ static bool askForCreating(const QString &title, const FilePath &filePath) = CheckableMessageBox::question(ICore::dialogParent(), title, Tr::tr("Create \"%1\"?").arg(filePath.shortNativePath()), - ICore::settings(), - kAlwaysCreate, + QString(kAlwaysCreate), QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Cancel, QMessageBox::Yes, diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index 2b21db5be53..e08b155d8e7 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -2697,8 +2697,7 @@ void BreakpointManager::executeDeleteAllBreakpointsDialog() Tr::tr("Remove All Breakpoints"), Tr::tr("Are you sure you want to remove all breakpoints " "from all files in the current session?"), - ICore::settings(), - "RemoveAllBreakpoints"); + QString("RemoveAllBreakpoints")); if (pressed != QMessageBox::Yes) return; diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp index 52e6d71fe6a..e6d54ad2e5c 100644 --- a/src/plugins/debugger/cdb/cdbengine.cpp +++ b/src/plugins/debugger/cdb/cdbengine.cpp @@ -2265,8 +2265,7 @@ void CdbEngine::checkQtSdkPdbFiles(const QString &module) CheckableMessageBox::information(Core::ICore::dialogParent(), Tr::tr("Missing Qt Debug Information"), message, - Core::ICore::settings(), - "CdbQtSdkPdbHint"); + QString("CdbQtSdkPdbHint")); showMessage("Missing Qt Debug Information Files package for " + qtName, LogMisc); }; @@ -2294,8 +2293,7 @@ void CdbEngine::parseOutputLine(QString line) "Make sure that your antivirus solution is up to date and if that does not work " "consider adding an exception for %1.") .arg(m_extensionFileName), - Core::ICore::settings(), - "SecureInfoCdbextCannotBeLoaded"); + QString("SecureInfoCdbextCannotBeLoaded")); notifyEngineSetupFailed(); } static const QString creatorExtPrefix = "|"; diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp index 28d218929a6..27c1373c99e 100644 --- a/src/plugins/debugger/debuggerengine.cpp +++ b/src/plugins/debugger/debuggerengine.cpp @@ -2716,17 +2716,14 @@ Context CppDebuggerEngine::languageContext() const void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp) { static const QString warnOnInappropriateDebuggerKey = "DebuggerWarnOnInappropriateDebugger"; - QtcSettings *coreSettings = Core::ICore::settings(); const bool warnOnRelease = debuggerSettings()->warnOnReleaseBuilds.value() && rp.toolChainAbi.osFlavor() != Abi::AndroidLinuxFlavor; bool warnOnInappropriateDebugger = false; QString detailedWarning; - auto shouldAskAgain = CheckableMessageBox::make_decider(coreSettings, - warnOnInappropriateDebuggerKey); switch (rp.toolChainAbi.binaryFormat()) { case Abi::PEFormat: { - if (CheckableMessageBox::shouldAskAgain(shouldAskAgain)) { + if (CheckableDecider(warnOnInappropriateDebuggerKey).shouldAskAgain()) { QString preferredDebugger; if (rp.toolChainAbi.osFlavor() == Abi::WindowsMSysFlavor) { if (rp.cppEngineType == CdbEngineType) @@ -2766,7 +2763,7 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp) break; } case Abi::ElfFormat: { - if (CheckableMessageBox::shouldAskAgain(shouldAskAgain)) { + if (CheckableDecider(warnOnInappropriateDebuggerKey).shouldAskAgain()) { if (rp.cppEngineType == CdbEngineType) { warnOnInappropriateDebugger = true; detailedWarning = Tr::tr( @@ -2879,7 +2876,7 @@ void CppDebuggerEngine::validateRunParameters(DebuggerRunParameters &rp) "Examining symbols and setting breakpoints by file name and line number " "may fail.\n") + '\n' + detailedWarning, - shouldAskAgain); + warnOnInappropriateDebuggerKey); } else if (warnOnRelease) { AsynchronousMessageBox::information(Tr::tr("Warning"), Tr::tr("This does not seem to be a \"Debug\" build.\n" diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 8b14ff0e236..87ae84dd8d6 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -2243,8 +2243,7 @@ bool wantRunTool(ToolMode toolMode, const QString &toolName) if (Utils::CheckableMessageBox::question(ICore::dialogParent(), title, message, - ICore::settings(), - "AnalyzerCorrectModeWarning") + QString("AnalyzerCorrectModeWarning")) != QMessageBox::Yes) return false; } diff --git a/src/plugins/debugger/debuggerruncontrol.cpp b/src/plugins/debugger/debuggerruncontrol.cpp index 17da601429d..e3feb04e393 100644 --- a/src/plugins/debugger/debuggerruncontrol.cpp +++ b/src/plugins/debugger/debuggerruncontrol.cpp @@ -620,7 +620,7 @@ void DebuggerRunTool::start() CheckableMessageBox::information(Core::ICore::dialogParent(), Tr::tr("Debugger"), warningMessage, - doNotShowAgain, + &doNotShowAgain, QMessageBox::Ok); } } diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index d533a0d4f63..734bab3b3ca 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -2576,8 +2576,7 @@ void WatchModel::clearWatches() ICore::dialogParent(), Tr::tr("Remove All Expression Evaluators"), Tr::tr("Are you sure you want to remove all expression evaluators?"), - ICore::settings(), - "RemoveAllWatchers"); + QString("RemoveAllWatchers")); if (ret != QMessageBox::Yes) return; diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 5c1d82d359f..4a7a43a689f 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1297,8 +1297,7 @@ QStringList GitClient::setupCheckoutArguments(const FilePath &workingDirectory, ICore::dialogParent() /*parent*/, Tr::tr("Create Local Branch") /*title*/, Tr::tr("Would you like to create a local branch?") /*message*/, - ICore::settings(), - "Git.CreateLocalBranchOnCheckout" /*setting*/, + QString("Git.CreateLocalBranchOnCheckout"), /* decider */ QMessageBox::Yes | QMessageBox::No /*buttons*/, QMessageBox::No /*default button*/, QMessageBox::No /*button to save*/) diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index fde831943bb..f9bafd234ad 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -1057,8 +1057,9 @@ bool RunControl::showPromptToStopDialog(const QString &title, if (!cancelButtonText.isEmpty()) buttonTexts[QMessageBox::Cancel] = cancelButtonText; - std::optional decider - = prompt ? make_optional(CheckableMessageBox::make_decider(*prompt)) : std::nullopt; + CheckableDecider decider; + if (prompt) + decider = CheckableDecider(prompt); auto selected = CheckableMessageBox::question(Core::ICore::dialogParent(), title, diff --git a/src/plugins/qmldesigner/components/propertyeditor/aligndistribute.cpp b/src/plugins/qmldesigner/components/propertyeditor/aligndistribute.cpp index f71f04fd398..5d8400b47e2 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/aligndistribute.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/aligndistribute.cpp @@ -663,8 +663,7 @@ AlignDistribute::Dimension AlignDistribute::getDimension(Target target) const bool AlignDistribute::executePixelPerfectDialog() const { - auto decider = Utils::CheckableMessageBox::make_decider(Core::ICore::settings(), - "WarnAboutPixelPerfectDistribution"); + Utils::CheckableDecider decider(QString("WarnAboutPixelPerfectDistribution")); QMessageBox::StandardButton pressed = Utils::CheckableMessageBox::question( Core::ICore::dialogParent(), diff --git a/src/plugins/squish/squishnavigationwidget.cpp b/src/plugins/squish/squishnavigationwidget.cpp index 1b99c338f16..5e51e5980e9 100644 --- a/src/plugins/squish/squishnavigationwidget.cpp +++ b/src/plugins/squish/squishnavigationwidget.cpp @@ -302,8 +302,7 @@ void SquishNavigationWidget::onRecordTestCase(const QString &suiteName, const QS Tr::tr("Do you want to record over the test case \"%1\"? The existing content will " "be overwritten by the recorded script.") .arg(testCase), - Core::ICore::settings(), - "RecordWithoutApproval"); + QString("RecordWithoutApproval")); if (pressed != QMessageBox::Yes) return; diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index ba58c0bd742..9604c0f1ec6 100644 --- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp +++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp @@ -489,8 +489,7 @@ private: void StudioWelcomePlugin::closeSplashScreen() { - Utils::CheckableMessageBox::doNotAskAgain(Core::ICore::settings(), - DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY); + Utils::CheckableDecider(DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY).doNotAskAgain(); if (!s_viewWindow.isNull()) s_viewWindow->deleteLater(); @@ -538,8 +537,7 @@ static bool showSplashScreen() return true; } - return Utils::CheckableMessageBox::shouldAskAgain(Core::ICore::settings(), - DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY); + return Utils::CheckableDecider(DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY).shouldAskAgain(); } void StudioWelcomePlugin::extensionsInitialized() diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 552d5a28233..21a0c2290c1 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -808,8 +808,7 @@ void MemcheckToolPrivate::heobAction() .arg( "Dwarfstack"), - ICore::settings(), - "HeobDwarfstackInfo", + QString("HeobDwarfstackInfo"), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok) != QMessageBox::Ok) diff --git a/src/plugins/welcome/introductionwidget.cpp b/src/plugins/welcome/introductionwidget.cpp index 4ee3e7868b3..ef56d9ab3ed 100644 --- a/src/plugins/welcome/introductionwidget.cpp +++ b/src/plugins/welcome/introductionwidget.cpp @@ -26,11 +26,10 @@ const char kTakeTourSetting[] = "TakeUITour"; namespace Welcome { namespace Internal { -void IntroductionWidget::askUserAboutIntroduction(QWidget *parent, QSettings *settings) +void IntroductionWidget::askUserAboutIntroduction(QWidget *parent) { - auto decider = CheckableMessageBox::make_decider(settings, kTakeTourSetting); // CheckableMessageBox for compatibility with Qt Creator < 4.11 - if (!CheckableMessageBox::shouldAskAgain(decider) + if (!CheckableDecider(QString(kTakeTourSetting)).shouldAskAgain() || !Core::ICore::infoBar()->canInfoBeAdded(kTakeTourSetting)) return; diff --git a/src/plugins/welcome/introductionwidget.h b/src/plugins/welcome/introductionwidget.h index a11069003a0..4b1f99c5ae3 100644 --- a/src/plugins/welcome/introductionwidget.h +++ b/src/plugins/welcome/introductionwidget.h @@ -11,7 +11,6 @@ QT_BEGIN_NAMESPACE class QLabel; -class QSettings; QT_END_NAMESPACE namespace Welcome { @@ -31,7 +30,7 @@ class IntroductionWidget : public QWidget public: explicit IntroductionWidget(QWidget *parent = nullptr); - static void askUserAboutIntroduction(QWidget *parent, QSettings *settings); + static void askUserAboutIntroduction(QWidget *parent); protected: bool event(QEvent *e) override; diff --git a/src/plugins/welcome/welcomeplugin.cpp b/src/plugins/welcome/welcomeplugin.cpp index 1a1a1aa647f..915695dafa2 100644 --- a/src/plugins/welcome/welcomeplugin.cpp +++ b/src/plugins/welcome/welcomeplugin.cpp @@ -132,8 +132,7 @@ public: if (!arguments.contains("-notour")) { connect(ICore::instance(), &ICore::coreOpened, this, []() { - IntroductionWidget::askUserAboutIntroduction(ICore::dialogParent(), - ICore::settings()); + IntroductionWidget::askUserAboutIntroduction(ICore::dialogParent()); }, Qt::QueuedConnection); } diff --git a/src/tools/qtcreatorcrashhandler/crashhandlerdialog.cpp b/src/tools/qtcreatorcrashhandler/crashhandlerdialog.cpp index 61d1fd4230d..c8853f53459 100644 --- a/src/tools/qtcreatorcrashhandler/crashhandlerdialog.cpp +++ b/src/tools/qtcreatorcrashhandler/crashhandlerdialog.cpp @@ -209,6 +209,8 @@ bool CrashHandlerDialog::runDebuggerWhileBacktraceNotFinished() QSettings::UserScope, QLatin1String(Core::Constants::IDE_SETTINGSVARIANT_STR), QLatin1String(SettingsApplication)); + Utils::CheckableMessageBox::initialize(&settings); + // Ask user. const QString title = tr("Run Debugger And Abort Collecting Backtrace?"); const QString message = tr( @@ -222,9 +224,7 @@ bool CrashHandlerDialog::runDebuggerWhileBacktraceNotFinished() = Utils::CheckableMessageBox::question(this, title, message, - &settings, - QLatin1String( - SettingsKeySkipWarningAbortingBacktrace), + QString(SettingsKeySkipWarningAbortingBacktrace), QMessageBox::Yes | QMessageBox::No, QMessageBox::No);