From fb9796ae8ab437e88fd086f2360233e33bc530bf Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 19 Mar 2021 13:34:25 +0100 Subject: [PATCH] Bazaar: Aspectify settings Change-Id: I0354698cf3473dd096e57481a945f0f59afc75b3 Reviewed-by: Orgad Shaneh --- src/plugins/bazaar/CMakeLists.txt | 1 - src/plugins/bazaar/bazaar.pro | 3 - src/plugins/bazaar/bazaar.qbs | 3 - src/plugins/bazaar/bazaarclient.cpp | 39 +++--- src/plugins/bazaar/bazaarplugin.cpp | 9 +- src/plugins/bazaar/bazaarsettings.cpp | 149 +++++++++++++++++++--- src/plugins/bazaar/bazaarsettings.h | 24 +++- src/plugins/bazaar/optionspage.cpp | 95 -------------- src/plugins/bazaar/optionspage.h | 42 ------ src/plugins/bazaar/optionspage.ui | 176 -------------------------- 10 files changed, 169 insertions(+), 372 deletions(-) delete mode 100644 src/plugins/bazaar/optionspage.cpp delete mode 100644 src/plugins/bazaar/optionspage.h delete mode 100644 src/plugins/bazaar/optionspage.ui diff --git a/src/plugins/bazaar/CMakeLists.txt b/src/plugins/bazaar/CMakeLists.txt index 6c40d344c39..ac4bcd4ffe3 100644 --- a/src/plugins/bazaar/CMakeLists.txt +++ b/src/plugins/bazaar/CMakeLists.txt @@ -11,7 +11,6 @@ add_qtc_plugin(Bazaar branchinfo.cpp branchinfo.h commiteditor.cpp commiteditor.h constants.h - optionspage.cpp optionspage.h optionspage.ui pullorpushdialog.cpp pullorpushdialog.h pullorpushdialog.ui revertdialog.ui uncommitdialog.ui diff --git a/src/plugins/bazaar/bazaar.pro b/src/plugins/bazaar/bazaar.pro index 6718ab33236..e71f1f8b85d 100644 --- a/src/plugins/bazaar/bazaar.pro +++ b/src/plugins/bazaar/bazaar.pro @@ -2,7 +2,6 @@ include(../../qtcreatorplugin.pri) SOURCES += \ bazaarclient.cpp \ bazaarplugin.cpp \ - optionspage.cpp \ bazaarsettings.cpp \ commiteditor.cpp \ bazaarcommitwidget.cpp \ @@ -15,7 +14,6 @@ HEADERS += \ bazaarclient.h \ constants.h \ bazaarplugin.h \ - optionspage.h \ bazaarsettings.h \ commiteditor.h \ bazaarcommitwidget.h \ @@ -25,7 +23,6 @@ HEADERS += \ branchinfo.h FORMS += \ - optionspage.ui \ revertdialog.ui \ bazaarcommitpanel.ui \ pullorpushdialog.ui \ diff --git a/src/plugins/bazaar/bazaar.qbs b/src/plugins/bazaar/bazaar.qbs index 2e5f9f0ea5e..b7413b2e7c2 100644 --- a/src/plugins/bazaar/bazaar.qbs +++ b/src/plugins/bazaar/bazaar.qbs @@ -29,9 +29,6 @@ QtcPlugin { "commiteditor.cpp", "commiteditor.h", "constants.h", - "optionspage.cpp", - "optionspage.h", - "optionspage.ui", "pullorpushdialog.cpp", "pullorpushdialog.h", "pullorpushdialog.ui", diff --git a/src/plugins/bazaar/bazaarclient.cpp b/src/plugins/bazaar/bazaarclient.cpp index 84ff8c7d7d7..ac855e320cc 100644 --- a/src/plugins/bazaar/bazaarclient.cpp +++ b/src/plugins/bazaar/bazaarclient.cpp @@ -49,13 +49,13 @@ class BazaarDiffConfig : public VcsBaseEditorConfig { Q_OBJECT public: - BazaarDiffConfig(VcsBaseClientSettings &settings, QToolBar *toolBar) : + BazaarDiffConfig(BazaarSettings &settings, QToolBar *toolBar) : VcsBaseEditorConfig(toolBar) { - mapSetting(addToggleButton(QLatin1String("-w"), tr("Ignore Whitespace")), - settings.boolPointer(BazaarSettings::diffIgnoreWhiteSpaceKey)); - mapSetting(addToggleButton(QLatin1String("-B"), tr("Ignore Blank Lines")), - settings.boolPointer(BazaarSettings::diffIgnoreBlankLinesKey)); + mapSetting(addToggleButton("-w", tr("Ignore Whitespace")), + &settings.diffIgnoreWhiteSpace); + mapSetting(addToggleButton("-B", tr("Ignore Blank Lines")), + &settings.diffIgnoreBlankLines); } QStringList arguments() const override @@ -64,8 +64,7 @@ public: // Bazaar wants "--diff-options=-w -B.." const QStringList formatArguments = VcsBaseEditorConfig::arguments(); if (!formatArguments.isEmpty()) { - const QString a = QLatin1String("--diff-options=") - + formatArguments.join(QString(QLatin1Char(' '))); + const QString a = "--diff-options=" + formatArguments.join(' '); args.append(a); } return args; @@ -76,31 +75,31 @@ class BazaarLogConfig : public VcsBaseEditorConfig { Q_OBJECT public: - BazaarLogConfig(VcsBaseClientSettings &settings, QToolBar *toolBar) : + BazaarLogConfig(BazaarSettings &settings, QToolBar *toolBar) : VcsBaseEditorConfig(toolBar) { - mapSetting(addToggleButton(QLatin1String("--verbose"), tr("Verbose"), + mapSetting(addToggleButton("--verbose", tr("Verbose"), tr("Show files changed in each revision.")), - settings.boolPointer(BazaarSettings::logVerboseKey)); - mapSetting(addToggleButton(QLatin1String("--forward"), tr("Forward"), + &settings.logVerbose); + mapSetting(addToggleButton("--forward", tr("Forward"), tr("Show from oldest to newest.")), - settings.boolPointer(BazaarSettings::logForwardKey)); - mapSetting(addToggleButton(QLatin1String("--include-merges"), tr("Include Merges"), + &settings.logForward); + mapSetting(addToggleButton("--include-merges", tr("Include Merges"), tr("Show merged revisions.")), - settings.boolPointer(BazaarSettings::logIncludeMergesKey)); + &settings.logIncludeMerges); const QList logChoices = { - ChoiceItem(tr("Detailed"), QLatin1String("long")), - ChoiceItem(tr("Moderately Short"), QLatin1String("short")), - ChoiceItem(tr("One Line"), QLatin1String("line")), - ChoiceItem(tr("GNU Change Log"), QLatin1String("gnu-changelog")) + {tr("Detailed"), "long"}, + {tr("Moderately Short"), "short"}, + {tr("One Line"), "line"}, + {tr("GNU Change Log"), "gnu-changelog"} }; mapSetting(addChoices(tr("Format"), { "--log-format=%1" }, logChoices), - settings.stringPointer(BazaarSettings::logFormatKey)); + &settings.logFormat); } }; -BazaarClient::BazaarClient(BazaarSettings *settings) : VcsBaseClient(settings) +BazaarClient::BazaarClient(BazaarSettings *settings) : VcsBaseClient(nullptr, settings) { setDiffConfigCreator([settings](QToolBar *toolBar) { return new BazaarDiffConfig(*settings, toolBar); diff --git a/src/plugins/bazaar/bazaarplugin.cpp b/src/plugins/bazaar/bazaarplugin.cpp index 9d1f7724fa9..cc7e3d4cfb7 100644 --- a/src/plugins/bazaar/bazaarplugin.cpp +++ b/src/plugins/bazaar/bazaarplugin.cpp @@ -31,7 +31,6 @@ #include "bazaarsettings.h" #include "commiteditor.h" #include "constants.h" -#include "optionspage.h" #include "pullorpushdialog.h" #include "ui_revertdialog.h" @@ -490,7 +489,7 @@ void BazaarPluginPrivate::logRepository() const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); QStringList extraOptions; - extraOptions += QLatin1String("--limit=") + QString::number(m_settings.intValue(BazaarSettings::logCountKey)); + extraOptions += "--limit=" + QString::number(m_settings.logCount.value()); m_client.log(state.topLevel(), QStringList(), extraOptions); } @@ -677,8 +676,8 @@ void BazaarPluginPrivate::showCommitWidget(const QListsetFields(m_submitRepository, branch, - m_settings.stringValue(BazaarSettings::userNameKey), - m_settings.stringValue(BazaarSettings::userEmailKey), status); + m_settings.userName.value(), + m_settings.userEmail.value(), status); } void BazaarPluginPrivate::diffFromEditorSelected(const QStringList &files) @@ -865,7 +864,7 @@ bool BazaarPluginPrivate::managesFile(const QString &workingDirectory, const QSt bool BazaarPluginPrivate::isConfigured() const { - const Utils::FilePath binary = m_settings.binaryPath(); + const FilePath binary = m_settings.binaryPath.filePath(); if (binary.isEmpty()) return false; QFileInfo fi = binary.toFileInfo(); diff --git a/src/plugins/bazaar/bazaarsettings.cpp b/src/plugins/bazaar/bazaarsettings.cpp index cb7d9762a46..e28e5945ccb 100644 --- a/src/plugins/bazaar/bazaarsettings.cpp +++ b/src/plugins/bazaar/bazaarsettings.cpp @@ -24,36 +24,145 @@ ****************************************************************************/ #include "bazaarsettings.h" + +#include "bazaarclient.h" #include "constants.h" +#include + +#include + +#include + +using namespace Utils; + namespace Bazaar { namespace Internal { -const QLatin1String BazaarSettings::diffIgnoreWhiteSpaceKey("diffIgnoreWhiteSpace"); -const QLatin1String BazaarSettings::diffIgnoreBlankLinesKey("diffIgnoreBlankLines"); -const QLatin1String BazaarSettings::logVerboseKey("logVerbose"); -const QLatin1String BazaarSettings::logForwardKey("logForward"); -const QLatin1String BazaarSettings::logIncludeMergesKey("logIncludeMerges"); -const QLatin1String BazaarSettings::logFormatKey("logFormat"); - BazaarSettings::BazaarSettings() { - setSettingsGroup(QLatin1String(Constants::BAZAAR)); - // Override default binary path - declareKey(binaryPathKey, QLatin1String(Constants::BAZAARDEFAULT)); - declareKey(diffIgnoreWhiteSpaceKey, false); - declareKey(diffIgnoreBlankLinesKey, false); - declareKey(logVerboseKey, false); - declareKey(logForwardKey, false); - declareKey(logIncludeMergesKey, false); - declareKey(logFormatKey, QLatin1String("long")); + setSettingsGroup(Constants::BAZAAR); + setAutoApply(false); + + registerAspect(&binaryPath); + binaryPath.setDisplayStyle(StringAspect::PathChooserDisplay); + binaryPath.setExpectedKind(PathChooser::ExistingCommand); + binaryPath.setDefaultValue(Constants::BAZAARDEFAULT); + binaryPath.setDisplayName(tr("Bazaar Command")); + binaryPath.setHistoryCompleter("Bazaar.Command.History"); + binaryPath.setLabelText(tr("Command:")); + + registerAspect(&diffIgnoreWhiteSpace); + diffIgnoreWhiteSpace.setSettingsKey("diffIgnoreWhiteSpace"); + + registerAspect(&diffIgnoreBlankLines); + diffIgnoreBlankLines.setSettingsKey("diffIgnoreBlankLines"); + + registerAspect(&logVerbose); + logVerbose.setSettingsKey("logVerbose"); + + registerAspect(&logFormat); + logForward.setSettingsKey("logForward"); + + registerAspect(&logIncludeMerges); + logIncludeMerges.setSettingsKey("logIncludeMerges"); + + registerAspect(&logFormat); + logFormat.setDisplayStyle(StringAspect::LineEditDisplay); + logFormat.setSettingsKey("logFormat"); + logFormat.setDefaultValue("long"); + + registerAspect(&userName); + userName.setDisplayStyle(StringAspect::LineEditDisplay); + userName.setLabelText(tr("Default username:")); + userName.setToolTip(tr("Username to use by default on commit.")); + + registerAspect(&userEmail); + userEmail.setDisplayStyle(StringAspect::LineEditDisplay); + userEmail.setLabelText(tr("Default email:")); + userEmail.setToolTip(tr("Email to use by default on commit.")); + + registerAspect(&logCount); + logCount.setLabelText(tr("Log count:")); + logCount.setToolTip(tr("The number of recent commit logs to show. Choose 0 to see all entries.")); + + registerAspect(&logCount); + timeout.setLabelText(tr("Timeout:")); + timeout.setSuffix(tr("s")); } bool BazaarSettings::sameUserId(const BazaarSettings &other) const { - return stringValue(userNameKey) == other.stringValue(userNameKey) - && stringValue(userEmailKey) == other.stringValue(userEmailKey); + return userName.value() == other.userName.value() + && userEmail.value() == other.userEmail.value(); } -} // namespace Internal -} // namespace Bazaar +// OptionsPage + +class OptionsPageWidget final : public Core::IOptionsPageWidget +{ + Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget) + +public: + OptionsPageWidget(const std::function &onApply, BazaarSettings *settings); + + void apply() final; + +private: + const std::function m_onApply; + BazaarSettings *m_settings; +}; + +void OptionsPageWidget::apply() +{ + if (!m_settings->isDirty()) + return; + m_settings->apply(); + m_onApply(); +} + +OptionsPageWidget::OptionsPageWidget(const std::function &onApply, BazaarSettings *settings) + : m_onApply(onApply), m_settings(settings) +{ + BazaarSettings &s = *m_settings; + + using namespace Layouting; + const Break nl; + + Column { + Group { + Title(tr("Configuration")), + Row { s.binaryPath } + }, + + Group { + Title(tr("User")), + Form { + s.userName, nl, + s.userEmail + } + }, + + Group { + Title(tr("Miscellaneous")), + Row { + s.logCount, + s.timeout, + Stretch() + } + }, + Stretch() + + }.attachTo(this); +} + +OptionsPage::OptionsPage(const std::function &onApply, BazaarSettings *settings) +{ + setId(VcsBase::Constants::VCS_ID_BAZAAR); + setDisplayName(OptionsPageWidget::tr("Bazaar")); + setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); }); + setCategory(VcsBase::Constants::VCS_SETTINGS_CATEGORY); +} + +} // Internal +} // Bazaar diff --git a/src/plugins/bazaar/bazaarsettings.h b/src/plugins/bazaar/bazaarsettings.h index 2bc1adc0226..5504e1a9c88 100644 --- a/src/plugins/bazaar/bazaarsettings.h +++ b/src/plugins/bazaar/bazaarsettings.h @@ -25,24 +25,34 @@ #pragma once +#include + +#include + #include namespace Bazaar { namespace Internal { -class BazaarSettings : public VcsBase::VcsBaseClientSettings +class BazaarSettings : public VcsBase::VcsBaseSettings { public: - static const QLatin1String diffIgnoreWhiteSpaceKey; - static const QLatin1String diffIgnoreBlankLinesKey; - static const QLatin1String logVerboseKey; - static const QLatin1String logForwardKey; - static const QLatin1String logIncludeMergesKey; - static const QLatin1String logFormatKey; + Utils::BoolAspect diffIgnoreWhiteSpace; + Utils::BoolAspect diffIgnoreBlankLines; + Utils::BoolAspect logVerbose; + Utils::BoolAspect logForward; + Utils::BoolAspect logIncludeMerges; + Utils::StringAspect logFormat; BazaarSettings(); bool sameUserId(const BazaarSettings &other) const; }; +class OptionsPage final : public Core::IOptionsPage +{ +public: + OptionsPage(const std::function &onApply, BazaarSettings *settings); +}; + } // namespace Internal } // namespace Bazaar diff --git a/src/plugins/bazaar/optionspage.cpp b/src/plugins/bazaar/optionspage.cpp deleted file mode 100644 index b6b41296fc5..00000000000 --- a/src/plugins/bazaar/optionspage.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Hugues Delorme -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "optionspage.h" -#include "bazaarclient.h" -#include "bazaarsettings.h" -#include "bazaarplugin.h" -#include "ui_optionspage.h" - -#include -#include - -using namespace VcsBase; - -namespace Bazaar { -namespace Internal { - -class OptionsPageWidget final : public Core::IOptionsPageWidget -{ - Q_DECLARE_TR_FUNCTIONS(Bazaar::Internal::OptionsPageWidget) - -public: - OptionsPageWidget(const std::function &onApply, BazaarSettings *settings); - - void apply() final; - -private: - Ui::OptionsPage m_ui; - const std::function m_onApply; - BazaarSettings *m_settings; -}; - -void OptionsPageWidget::apply() -{ - BazaarSettings s = *m_settings; - s.setValue(BazaarSettings::binaryPathKey, m_ui.commandChooser->rawPath()); - s.setValue(BazaarSettings::userNameKey, m_ui.defaultUsernameLineEdit->text().trimmed()); - s.setValue(BazaarSettings::userEmailKey, m_ui.defaultEmailLineEdit->text().trimmed()); - s.setValue(BazaarSettings::logCountKey, m_ui.logEntriesCount->value()); - s.setValue(BazaarSettings::timeoutKey, m_ui.timeout->value()); - - if (*m_settings == s) - return; - - *m_settings = s; - m_onApply(); -} - -OptionsPageWidget::OptionsPageWidget(const std::function &onApply, BazaarSettings *settings) - : m_onApply(onApply), m_settings(settings) -{ - m_ui.setupUi(this); - m_ui.commandChooser->setExpectedKind(Utils::PathChooser::ExistingCommand); - m_ui.commandChooser->setPromptDialogTitle(tr("Bazaar Command")); - m_ui.commandChooser->setHistoryCompleter(QLatin1String("Bazaar.Command.History")); - - m_ui.commandChooser->setPath(m_settings->stringValue(BazaarSettings::binaryPathKey)); - m_ui.defaultUsernameLineEdit->setText(m_settings->stringValue(BazaarSettings::userNameKey)); - m_ui.defaultEmailLineEdit->setText(m_settings->stringValue(BazaarSettings::userEmailKey)); - m_ui.logEntriesCount->setValue(m_settings->intValue(BazaarSettings::logCountKey)); - m_ui.timeout->setValue(m_settings->intValue(BazaarSettings::timeoutKey)); -} - -OptionsPage::OptionsPage(const std::function &onApply, BazaarSettings *settings) -{ - setId(VcsBase::Constants::VCS_ID_BAZAAR); - setDisplayName(OptionsPageWidget::tr("Bazaar")); - setWidgetCreator([onApply, settings] { return new OptionsPageWidget(onApply, settings); }); - setCategory(Constants::VCS_SETTINGS_CATEGORY); -} - -} // Internal -} // Bazaar diff --git a/src/plugins/bazaar/optionspage.h b/src/plugins/bazaar/optionspage.h deleted file mode 100644 index 4e6c69e9fbf..00000000000 --- a/src/plugins/bazaar/optionspage.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Hugues Delorme -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#pragma once - -#include - -namespace Bazaar { -namespace Internal { - -class BazaarSettings; - -class OptionsPage final : public Core::IOptionsPage -{ -public: - OptionsPage(const std::function &onApply, BazaarSettings *settings); -}; - -} // namespace Internal -} // namespace Bazaar diff --git a/src/plugins/bazaar/optionspage.ui b/src/plugins/bazaar/optionspage.ui deleted file mode 100644 index 419ce3e94d3..00000000000 --- a/src/plugins/bazaar/optionspage.ui +++ /dev/null @@ -1,176 +0,0 @@ - - - Bazaar::Internal::OptionsPage - - - - 0 - 0 - 649 - 268 - - - - - - - - - - Configuration - - - - QFormLayout::ExpandingFieldsGrow - - - - - Command: - - - - - - - - - - - - - User - - - - QFormLayout::ExpandingFieldsGrow - - - - - Username to use by default on commit. - - - Default username: - - - - - - - Username to use by default on commit. - - - - - - - Email to use by default on commit. - - - Default email: - - - - - - - Email to use by default on commit. - - - - - - - - - - Miscellaneous - - - - - - Log count: - - - - - - - The number of recent commit logs to show. Choose 0 to see all entries. - - - 1000 - - - 1000 - - - - - - - Timeout: - - - - - - - s - - - 360 - - - 30 - - - - - - - Qt::Horizontal - - - - 213 - 20 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 - - editingFinished() - browsingFinished() - -
-
- - -