From 67b33a06628ef4df68c402fc1b2907a556a8d44c Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 13 Jun 2019 18:25:17 +0200 Subject: [PATCH] ProjectExplorer: Introduce a new BaseSelectionAspect To handle an (exclusive) choice within a set of possible options, visualized by a set of QRadioButtons. Use in QdbMakeDefaultAppStep. Change-Id: Icc62a45e8c5986cd9400f90449f92154ed854a22 Reviewed-by: Christian Kandeler --- src/plugins/boot2qt/qdbmakedefaultappstep.cpp | 86 +++---------------- src/plugins/boot2qt/qdbmakedefaultappstep.h | 11 --- .../projectconfigurationaspects.cpp | 82 ++++++++++++++++++ .../projectconfigurationaspects.h | 26 ++++++ 4 files changed, 119 insertions(+), 86 deletions(-) diff --git a/src/plugins/boot2qt/qdbmakedefaultappstep.cpp b/src/plugins/boot2qt/qdbmakedefaultappstep.cpp index 8ff39732ffb..5ddb9fa6c77 100644 --- a/src/plugins/boot2qt/qdbmakedefaultappstep.cpp +++ b/src/plugins/boot2qt/qdbmakedefaultappstep.cpp @@ -27,56 +27,27 @@ #include "qdbmakedefaultappservice.h" -#include -#include +#include + +using namespace ProjectExplorer; namespace Qdb { namespace Internal { -class QdbConfigWidget : public ProjectExplorer::BuildStepConfigWidget -{ -public: - QdbConfigWidget(QdbMakeDefaultAppStep *step) - : BuildStepConfigWidget(step) - { - QVBoxLayout * const mainLayout = new QVBoxLayout(this); - mainLayout->setMargin(0); - - m_makeDefaultBtn.setText( - QdbMakeDefaultAppStep::tr("Set this application to start by default")); - m_resetDefaultBtn.setText( - QdbMakeDefaultAppStep::tr("Reset default application")); - - if (step->makeDefault()) - m_makeDefaultBtn.setChecked(true); - else - m_resetDefaultBtn.setChecked(true); - - mainLayout->addWidget(&m_makeDefaultBtn); - mainLayout->addWidget(&m_resetDefaultBtn); - - connect(&m_makeDefaultBtn, &QRadioButton::clicked, this, [step] { - step->setMakeDefault(true); - }); - connect(&m_resetDefaultBtn, &QRadioButton::clicked, this, [step] { - step->setMakeDefault(false); - }); - } - -private: - QRadioButton m_makeDefaultBtn; - QRadioButton m_resetDefaultBtn; -}; - -QdbMakeDefaultAppStep::QdbMakeDefaultAppStep(ProjectExplorer::BuildStepList *bsl) +QdbMakeDefaultAppStep::QdbMakeDefaultAppStep(BuildStepList *bsl) : AbstractRemoteLinuxDeployStep(bsl, stepId()) { setDefaultDisplayName(stepDisplayName()); auto service = createDeployService(); - setInternalInitializer([this, service] { - service->setMakeDefault(m_makeDefault); + auto selection = addAspect(); + selection->setSettingsKey("QdbMakeDefaultDeployStep.MakeDefault"); + selection->addOption(tr("Set this application to start by default")); + selection->addOption(tr("Reset default application")); + + setInternalInitializer([service, selection] { + service->setMakeDefault(selection->value() == 0); return service->isDeploymentPossible(); }); } @@ -86,45 +57,10 @@ Core::Id QdbMakeDefaultAppStep::stepId() return "Qdb.MakeDefaultAppStep"; } -ProjectExplorer::BuildStepConfigWidget *QdbMakeDefaultAppStep::createConfigWidget() -{ - return new QdbConfigWidget(this); -} - QString QdbMakeDefaultAppStep::stepDisplayName() { return QStringLiteral("Change default application"); } -void QdbMakeDefaultAppStep::setMakeDefault(bool makeDefault) -{ - m_makeDefault = makeDefault; -} - -bool QdbMakeDefaultAppStep::makeDefault() const -{ - return m_makeDefault; -} - -static QString makeDefaultKey() -{ - return QLatin1String("QdbMakeDefaultDeployStep.MakeDefault"); -} - -bool QdbMakeDefaultAppStep::fromMap(const QVariantMap &map) -{ - if (!AbstractRemoteLinuxDeployStep::fromMap(map)) - return false; - m_makeDefault = map.value(makeDefaultKey()).toBool(); - return true; -} - -QVariantMap QdbMakeDefaultAppStep::toMap() const -{ - QVariantMap map = AbstractRemoteLinuxDeployStep::toMap(); - map.insert(makeDefaultKey(), m_makeDefault); - return map; -} - } // namespace Internal } // namespace Qdb diff --git a/src/plugins/boot2qt/qdbmakedefaultappstep.h b/src/plugins/boot2qt/qdbmakedefaultappstep.h index e5f2be8389c..ffaf0dcab6c 100644 --- a/src/plugins/boot2qt/qdbmakedefaultappstep.h +++ b/src/plugins/boot2qt/qdbmakedefaultappstep.h @@ -39,17 +39,6 @@ public: static Core::Id stepId(); static QString stepDisplayName(); - - void setMakeDefault(bool makeDefault); - bool makeDefault() const; - -protected: - ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override; - bool fromMap(const QVariantMap &map) override; - QVariantMap toMap() const override; - -private: - bool m_makeDefault = false; }; } // namespace Internal diff --git a/src/plugins/projectexplorer/projectconfigurationaspects.cpp b/src/plugins/projectexplorer/projectconfigurationaspects.cpp index d9ad7c43346..d1e5a032cb6 100644 --- a/src/plugins/projectexplorer/projectconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/projectconfigurationaspects.cpp @@ -44,6 +44,8 @@ #include #include #include +#include +#include using namespace Utils; @@ -60,6 +62,17 @@ public: QPointer m_checkBox; // Owned by configuration widget }; +class BaseSelectionAspectPrivate +{ +public: + int m_value = 0; + int m_defaultValue = 0; + struct Option { QString displayName; QString tooltip; }; + QVector