From 8f987866b67a6d7d2ff6e95d80936595ea5d112e Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 25 Sep 2018 08:24:10 +0200 Subject: [PATCH] Project: Introduce BaseIntegerAspect base using spinboxes Basically upstreamed/pimpled from VxWorks::BaseNumberValueAspect Change-Id: I1dbedbbdd55b684fe1bb823e57d4830fb2eb0b0e Reviewed-by: Christian Kandeler --- .../projectconfigurationaspects.cpp | 92 +++++++++++++++++++ .../projectconfigurationaspects.h | 27 ++++++ 2 files changed, 119 insertions(+) diff --git a/src/plugins/projectexplorer/projectconfigurationaspects.cpp b/src/plugins/projectexplorer/projectconfigurationaspects.cpp index 92dd68f60a1..fc295bbec0e 100644 --- a/src/plugins/projectexplorer/projectconfigurationaspects.cpp +++ b/src/plugins/projectexplorer/projectconfigurationaspects.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include using namespace Utils; @@ -77,6 +78,19 @@ public: QPixmap m_labelPixmap; }; +class BaseIntegerAspectPrivate +{ +public: + QVariant m_value; + QVariant m_minimumValue; + QVariant m_maximumValue; + int m_displayIntegerBase = 10; + QString m_label; + QString m_prefix; + QString m_suffix; + QPointer m_spinBox; // Owned by configuration widget +}; + } // Internal /*! @@ -337,4 +351,82 @@ void BaseBoolAspect::setLabel(const QString &label) d->m_label = label; } +/*! + \class ProjectExplorer::BaseIntegerAspect +*/ + +// BaseIntegerAspect + +BaseIntegerAspect::BaseIntegerAspect() + : d(new Internal::BaseIntegerAspectPrivate) +{} + +BaseIntegerAspect::~BaseIntegerAspect() = default; + +void BaseIntegerAspect::addToConfigurationLayout(QFormLayout *layout) +{ + QTC_CHECK(!d->m_spinBox); + d->m_spinBox = new QSpinBox(layout->parentWidget()); + d->m_spinBox->setValue(d->m_value.toInt()); + d->m_spinBox->setDisplayIntegerBase(d->m_displayIntegerBase); + d->m_spinBox->setPrefix(d->m_prefix); + d->m_spinBox->setSuffix(d->m_suffix); + if (d->m_maximumValue.isValid() && d->m_maximumValue.isValid()) + d->m_spinBox->setRange(d->m_minimumValue.toInt(), d->m_maximumValue.toInt()); + layout->addRow(d->m_label, d->m_spinBox); + connect(d->m_spinBox.data(), static_cast(&QSpinBox::valueChanged), + this, [this](int value) { + d->m_value = value; + emit changed(); + }); +} + +void BaseIntegerAspect::fromMap(const QVariantMap &map) +{ + d->m_value = map.value(settingsKey()); +} + +void BaseIntegerAspect::toMap(QVariantMap &data) const +{ + data.insert(settingsKey(), d->m_value); +} + +int BaseIntegerAspect::value() const +{ + return d->m_value.toInt(); +} + +void BaseIntegerAspect::setValue(int value) +{ + d->m_value = value; + if (d->m_spinBox) + d->m_spinBox->setValue(d->m_value.toInt()); +} + +void BaseIntegerAspect::setRange(int min, int max) +{ + d->m_minimumValue = min; + d->m_maximumValue = max; +} + +void BaseIntegerAspect::setLabel(const QString &label) +{ + d->m_label = label; +} + +void BaseIntegerAspect::setPrefix(const QString &prefix) +{ + d->m_prefix = prefix; +} + +void BaseIntegerAspect::setSuffix(const QString &suffix) +{ + d->m_suffix = suffix; +} + +void BaseIntegerAspect::setDisplayIntegerBase(int base) +{ + d->m_displayIntegerBase = base; +} + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/projectconfigurationaspects.h b/src/plugins/projectexplorer/projectconfigurationaspects.h index a058c20ec0f..e47d232f2ee 100644 --- a/src/plugins/projectexplorer/projectconfigurationaspects.h +++ b/src/plugins/projectexplorer/projectconfigurationaspects.h @@ -38,6 +38,7 @@ namespace ProjectExplorer { namespace Internal { class BaseBoolAspectPrivate; class BaseStringAspectPrivate; +class BaseIntegerAspectPrivate; } // Internal class PROJECTEXPLORER_EXPORT BaseBoolAspect : public ProjectConfigurationAspect @@ -106,4 +107,30 @@ private: std::unique_ptr d; }; +class PROJECTEXPLORER_EXPORT BaseIntegerAspect : public ProjectConfigurationAspect +{ + Q_OBJECT + +public: + BaseIntegerAspect(); + ~BaseIntegerAspect() override; + + void addToConfigurationLayout(QFormLayout *layout) override; + + int value() const; + void setValue(int val); + + void setRange(int min, int max); + void setLabel(const QString &label); + void setPrefix(const QString &prefix); + void setSuffix(const QString &suffix); + void setDisplayIntegerBase(int base); + + void fromMap(const QVariantMap &map) override; + void toMap(QVariantMap &map) const override; + +private: + std::unique_ptr d; +}; + } // namespace ProjectExplorer