Project: Introduce BaseIntegerAspect base using spinboxes

Basically upstreamed/pimpled from VxWorks::BaseNumberValueAspect

Change-Id: I1dbedbbdd55b684fe1bb823e57d4830fb2eb0b0e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2018-09-25 08:24:10 +02:00
parent 10262574d4
commit 8f987866b6
2 changed files with 119 additions and 0 deletions

View File

@@ -41,6 +41,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QFormLayout>
#include <QSpinBox>
#include <QToolButton>
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<QSpinBox> 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<void (QSpinBox::*)(int)>(&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

View File

@@ -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<Internal::BaseStringAspectPrivate> 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<Internal::BaseIntegerAspectPrivate> d;
};
} // namespace ProjectExplorer