ProjectExplorer: Make BaseIntegerAspect operate on qint64

... and add a way to scale displayed values.

Change-Id: Icd342935c80cc4f2077df95d856b5d7ab38448f2
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-04-24 12:15:31 +02:00
parent 4832a22b6b
commit ceff49ec40
2 changed files with 21 additions and 13 deletions

View File

@@ -84,10 +84,11 @@ public:
class BaseIntegerAspectPrivate
{
public:
QVariant m_value;
qint64 m_value = 0;
QVariant m_minimumValue;
QVariant m_maximumValue;
int m_displayIntegerBase = 10;
qint64 m_displayScaleFactor = 1;
QString m_label;
QString m_prefix;
QString m_suffix;
@@ -402,23 +403,24 @@ 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->setValue(int(d->m_value / d->m_displayScaleFactor));
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());
d->m_spinBox->setRange(int(d->m_minimumValue.toLongLong() / d->m_displayScaleFactor),
int(d->m_maximumValue.toLongLong() / d->m_displayScaleFactor));
layout->addRow(d->m_label, d->m_spinBox);
connect(d->m_spinBox.data(), QOverload<int>::of(&QSpinBox::valueChanged),
this, [this](int value) {
d->m_value = value;
d->m_value = value * d->m_displayScaleFactor;
emit changed();
});
}
void BaseIntegerAspect::fromMap(const QVariantMap &map)
{
d->m_value = map.value(settingsKey());
d->m_value = map.value(settingsKey()).toLongLong();
}
void BaseIntegerAspect::toMap(QVariantMap &data) const
@@ -426,19 +428,19 @@ void BaseIntegerAspect::toMap(QVariantMap &data) const
data.insert(settingsKey(), d->m_value);
}
int BaseIntegerAspect::value() const
qint64 BaseIntegerAspect::value() const
{
return d->m_value.toInt();
return d->m_value;
}
void BaseIntegerAspect::setValue(int value)
void BaseIntegerAspect::setValue(qint64 value)
{
d->m_value = value;
if (d->m_spinBox)
d->m_spinBox->setValue(d->m_value.toInt());
d->m_spinBox->setValue(int(d->m_value / d->m_displayScaleFactor));
}
void BaseIntegerAspect::setRange(int min, int max)
void BaseIntegerAspect::setRange(qint64 min, qint64 max)
{
d->m_minimumValue = min;
d->m_maximumValue = max;
@@ -464,4 +466,9 @@ void BaseIntegerAspect::setDisplayIntegerBase(int base)
d->m_displayIntegerBase = base;
}
void BaseIntegerAspect::setDisplayScaleFactor(qint64 factor)
{
d->m_displayScaleFactor = factor;
}
} // namespace ProjectExplorer

View File

@@ -123,14 +123,15 @@ public:
void addToConfigurationLayout(QFormLayout *layout) override;
int value() const;
void setValue(int val);
qint64 value() const;
void setValue(qint64 val);
void setRange(int min, int max);
void setRange(qint64 min, qint64 max);
void setLabel(const QString &label);
void setPrefix(const QString &prefix);
void setSuffix(const QString &suffix);
void setDisplayIntegerBase(int base);
void setDisplayScaleFactor(qint64 factor);
void fromMap(const QVariantMap &map) override;
void toMap(QVariantMap &map) const override;