diff --git a/gui/include/gui/widgets/incrementstrategy.h b/gui/include/gui/widgets/incrementstrategy.h
new file mode 100644
index 0000000000..e96c8c4fe2
--- /dev/null
+++ b/gui/include/gui/widgets/incrementstrategy.h
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2024 Analog Devices Inc.
+ *
+ * This file is part of Scopy
+ * (see https://www.github.com/analogdevicesinc/scopy).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifndef INCREMENTSTRATEGY_H
+#define INCREMENTSTRATEGY_H
+
+#include
+#include
+
+namespace scopy {
+namespace gui {
+
+class SCOPY_GUI_EXPORT IncrementStrategy
+{
+public:
+ virtual ~IncrementStrategy() {}
+ virtual double increment(double val) = 0;
+ virtual double decrement(double val) = 0;
+ virtual void setScale(double scale) = 0;
+};
+
+class SCOPY_GUI_EXPORT IncrementStrategy125 : public IncrementStrategy
+{
+public:
+ NumberSeries m_steps;
+
+ IncrementStrategy125()
+ : m_steps(1e-9, 1e9, 10)
+ {}
+ ~IncrementStrategy125() {}
+ virtual double increment(double val) override { return m_steps.getNumberAfter(val); }
+ virtual double decrement(double val) override { return m_steps.getNumberBefore(val); }
+
+ double m_scale;
+ void setScale(double scale) override { m_scale = scale; }
+};
+
+class SCOPY_GUI_EXPORT IncrementStrategyPower2 : public IncrementStrategy
+{
+public:
+ QList m_steps;
+ IncrementStrategyPower2()
+ {
+ for(int i = 30; i >= 0; i--) {
+ m_steps.append(-(1 << i));
+ }
+ for(int i = 0; i < 31; i++) {
+ m_steps.append(1 << i);
+ }
+ }
+ ~IncrementStrategyPower2() {}
+ virtual double increment(double val) override
+ {
+ int i = 0;
+ val = val + 1;
+ while(val > m_steps[i]) {
+ i++;
+ }
+ return m_steps[i];
+ }
+ virtual double decrement(double val) override
+ {
+ int i = m_steps.count() - 1;
+ val = val - 1;
+ while(val < m_steps[i]) {
+ i--;
+ }
+ return m_steps[i];
+ }
+ double m_scale;
+
+ void setScale(double scale) override { m_scale = scale; }
+};
+class SCOPY_GUI_EXPORT IncrementStrategyFixed : public IncrementStrategy
+{
+public:
+ IncrementStrategyFixed(double k = 1)
+ {
+ m_k = k;
+ m_scale = 1;
+ }
+ ~IncrementStrategyFixed() {}
+ virtual double increment(double val) override
+ {
+ val = val + m_k * m_scale;
+ return val;
+ }
+ virtual double decrement(double val) override
+ {
+ val = val - m_k * m_scale;
+ return val;
+ }
+ void setK(double val) { m_k = val; }
+ double k() { return m_k; }
+
+private:
+ double m_k;
+ double m_scale;
+
+ void setScale(double scale) override { m_scale = scale; }
+};
+
+class SCOPY_GUI_EXPORT IncrementStrategyTest : public IncrementStrategy
+{
+public:
+ IncrementStrategyTest() { m_scale = 1; }
+ ~IncrementStrategyTest() {}
+ virtual double increment(double val) override
+ {
+ val = val + m_scale;
+ return val;
+ }
+ virtual double decrement(double val) override
+ {
+ val = val - m_scale;
+ return val;
+ }
+
+private:
+ double m_scale;
+
+ void setScale(double scale) override { m_scale = scale; }
+};
+} // namespace gui
+} // namespace scopy
+#endif // INCREMENTSTRATEGY_H
diff --git a/gui/include/gui/widgets/menuspinbox.h b/gui/include/gui/widgets/menuspinbox.h
index 77f3930c41..c18035afe9 100644
--- a/gui/include/gui/widgets/menuspinbox.h
+++ b/gui/include/gui/widgets/menuspinbox.h
@@ -28,112 +28,16 @@
#include
#include
#include
-#include
#include
#include
#include
#include
+#include
+#include
namespace scopy {
namespace gui {
-class SCOPY_GUI_EXPORT IncrementStrategy
-{
-public:
- virtual ~IncrementStrategy(){};
- virtual double increment(double val) = 0;
- virtual double decrement(double val) = 0;
- virtual void setScale(double scale) = 0;
-};
-
-class SCOPY_GUI_EXPORT IncrementStrategy125 : public IncrementStrategy
-{
-public:
- NumberSeries m_steps;
-
- IncrementStrategy125()
- : m_steps(1e-9, 1e9, 10){};
- ~IncrementStrategy125(){};
- virtual double increment(double val) override { return m_steps.getNumberAfter(val); }
- virtual double decrement(double val) override { return m_steps.getNumberBefore(val); }
-
- double m_scale;
- void setScale(double scale) override { m_scale = scale; }
-};
-
-class SCOPY_GUI_EXPORT IncrementStrategyPower2 : public IncrementStrategy
-{
-public:
- QList m_steps;
- IncrementStrategyPower2()
- {
- for(int i = 30; i >= 0; i--) {
- m_steps.append(-(1 << i));
- }
- for(int i = 0; i < 31; i++) {
- m_steps.append(1 << i);
- }
- };
- ~IncrementStrategyPower2(){};
- virtual double increment(double val) override
- {
- int i = 0;
- val = val + 1;
- while(val > m_steps[i]) {
- i++;
- }
- return m_steps[i];
- }
- virtual double decrement(double val) override
- {
- int i = m_steps.count() - 1;
- val = val - 1;
- while(val < m_steps[i]) {
- i--;
- }
- return m_steps[i];
- }
- double m_scale;
-
- void setScale(double scale) override { m_scale = scale; }
-};
-class SCOPY_GUI_EXPORT IncrementStrategyFixed : public IncrementStrategy
-{
-public:
- IncrementStrategyFixed(double k = 1)
- {
- m_k = k;
- m_scale = 1;
- };
- ~IncrementStrategyFixed(){};
- virtual double increment(double val) override
- {
- val = val + m_k * m_scale;
- return val;
- }
- virtual double decrement(double val) override
- {
- val = val - m_k * m_scale;
- return val;
- }
- void setK(double val) { m_k = val; }
- double k() { return m_k; }
-
-private:
- double m_k;
- double m_scale;
-
- void setScale(double scale) override { m_scale = scale; }
-};
-
-class SCOPY_GUI_EXPORT UnitPrefix
-{
-public:
- QString prefix;
- double scale;
- // enum type - metric, hour, logarithmic, etc
-};
-
class SCOPY_GUI_EXPORT MenuSpinbox : public QWidget
{
Q_OBJECT
@@ -157,7 +61,8 @@ class SCOPY_GUI_EXPORT MenuSpinbox : public QWidget
IncrementStrategy *incrementStrategy() const;
QString name() const;
- void setScaleRange(double min, double max);
+ Scale *scale() const;
+ void setScale(Scale *newScale);
public Q_SLOTS:
void setName(const QString &newName);
@@ -169,6 +74,7 @@ public Q_SLOTS:
void setValue(double newValue);
void setIncrementMode(IncrementMode is);
void setScalingEnabled(bool en);
+ bool scallingEnabled();
Q_SIGNALS:
void nameChanged(QString);
@@ -184,10 +90,10 @@ private Q_SLOTS:
void layoutVertically(bool left);
void layoutHorizontally(bool left);
double clamp(double val, double min, double max);
+ void minMaxReached(double val);
QLabel *m_label;
QLineEdit *m_edit;
- QComboBox *m_scaleCb;
QPushButton *m_plus;
QPushButton *m_minus;
MouseWheelWidgetGuard *m_mouseWheelGuard;
@@ -195,19 +101,13 @@ private Q_SLOTS:
IncrementStrategy *m_incrementStrategy;
IncrementMode m_im;
+ Scale *m_scale;
+
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged)
- Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
QString m_name;
double m_value, m_min, m_max;
- double m_scaleMin, m_scaleMax;
- QString m_unit;
-
- QList m_scales;
- // QMap m_scaleMap;
- double getScaleForPrefix(QString prefix, Qt::CaseSensitivity s = Qt::CaseSensitive);
- bool m_scalingEnabled;
};
} // namespace gui
} // namespace scopy
diff --git a/gui/include/gui/widgets/scale.h b/gui/include/gui/widgets/scale.h
new file mode 100644
index 0000000000..ab814a3802
--- /dev/null
+++ b/gui/include/gui/widgets/scale.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2024 Analog Devices Inc.
+ *
+ * This file is part of Scopy
+ * (see https://www.github.com/analogdevicesinc/scopy).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#ifndef SCALE_H
+#define SCALE_H
+
+#include
+#include
+#include
+#include
+#include
+
+namespace scopy {
+namespace gui {
+
+class SCOPY_GUI_EXPORT UnitPrefix
+{
+public:
+ QString prefix;
+ double scale;
+ // enum type - metric, hour, logarithmic, etc
+};
+
+class SCOPY_GUI_EXPORT ScaleOption
+{
+public:
+ QString option;
+ double scale;
+ // enum type - metric, hour, logarithmic, etc
+};
+
+class SCOPY_GUI_EXPORT Scale : public QObject
+{
+ Q_OBJECT
+public:
+ Scale(QString unit, double min, double max, bool hasPrefix = true);
+ ~Scale();
+
+ double getScaleForPrefix(QString prefix, Qt::CaseSensitivity s);
+ double getScaleForUnit(QString unit, Qt::CaseSensitivity s);
+ double getScaleForSymbol(QString symbol);
+
+ QList scalePrefixes() const;
+ void setScalePrefixes(const QList &newScalePrefixes);
+
+ QList scaleOptions() const;
+ void setScaleOptions(const QList &newScaleOptions);
+
+ bool scalingEnabled() const;
+ void setScalingEnabled(bool newScalingEnabled);
+
+ QComboBox *scaleCb() const;
+
+ QString unit() const;
+ void setUnit(const QString &newUnit);
+
+ void computeScale(double val);
+
+ bool hasPrefix() const;
+ void setHasPrefix(bool newHasPrefix);
+
+Q_SIGNALS:
+ void scaleUpdated();
+ void unitChanged(QString unit);
+ void scaleDown(int newScaleIndex);
+
+private:
+ bool m_hasPrefix;
+ bool m_scalingEnabled = true;
+ double m_min, m_max;
+ QString m_unit;
+ QList m_scaleOptions;
+ QList m_scalePrefixes;
+ QComboBox *m_scaleCb;
+ void populateScaleCb();
+
+ Q_PROPERTY(QString unit READ unit WRITE setUnit NOTIFY unitChanged)
+};
+
+} // namespace gui
+} // namespace scopy
+#endif // SCALE_H
diff --git a/gui/src/style.cpp b/gui/src/style.cpp
index 40e23cc7e4..b6c711cee8 100644
--- a/gui/src/style.cpp
+++ b/gui/src/style.cpp
@@ -359,3 +359,5 @@ QString Style::adjustForScaling(QString key, QString value)
return value;
}
+
+#include "moc_style.cpp"
diff --git a/gui/src/widgets/menuplotaxisrangecontrol.cpp b/gui/src/widgets/menuplotaxisrangecontrol.cpp
index 3fc59f435c..40599e3d72 100644
--- a/gui/src/widgets/menuplotaxisrangecontrol.cpp
+++ b/gui/src/widgets/menuplotaxisrangecontrol.cpp
@@ -32,13 +32,17 @@ MenuPlotAxisRangeControl::MenuPlotAxisRangeControl(PlotAxis *m_plotAxis, QWidget
setLayout(minMaxLayout);
minMaxLayout->setMargin(0);
minMaxLayout->setSpacing(10);
- QString unit = m_plotAxis->getUnits();
m_min = new MenuSpinbox("Min", 0, "counts", -1e9, 1e9, true, false, this);
m_max = new MenuSpinbox("Max", 0, "counts", -1e9, 1e9, true, false, this);
- m_min->setScaleRange(1, 1e9);
- m_max->setScaleRange(1, 1e9);
+ m_min->setIncrementMode(MenuSpinbox::IS_POW2);
+ m_max->setIncrementMode(MenuSpinbox::IS_POW2);
+
+ m_min->scale()->setScalePrefixes(
+ {{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}, {QString("G"), 1e9}});
+ m_max->scale()->setScalePrefixes(
+ {{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}, {QString("G"), 1e9}});
addAxis(m_plotAxis);
minMaxLayout->addWidget(m_min);
diff --git a/gui/src/widgets/menuspinbox.cpp b/gui/src/widgets/menuspinbox.cpp
index 317543eb07..381eca9672 100644
--- a/gui/src/widgets/menuspinbox.cpp
+++ b/gui/src/widgets/menuspinbox.cpp
@@ -28,16 +28,23 @@ namespace gui {
MenuSpinbox::MenuSpinbox(QString name, double val, QString unit, double min, double max, bool vertical, bool left,
QWidget *parent)
- : QWidget(parent)
+ : m_name(name)
+ , m_min(min)
+ , m_max(max)
+ , QWidget(parent)
{
m_label = new QLabel(name, parent);
m_edit = new QLineEdit("0", parent);
- m_scaleCb = new QComboBox(parent);
m_plus = new QPushButton("", parent);
m_minus = new QPushButton("", parent);
m_mouseWheelGuard = new MouseWheelWidgetGuard(this);
+ ////SCALE
+ m_scale = new Scale(unit, min, max);
+
+ m_incrementStrategy = new IncrementStrategyFixed();
+
m_plus->setAutoRepeat(true);
m_plus->setAutoRepeatDelay(300);
m_plus->setAutoRepeatInterval(20);
@@ -52,35 +59,36 @@ MenuSpinbox::MenuSpinbox(QString name, double val, QString unit, double min, dou
layoutHorizontally(left);
}
- m_incrementStrategy = new IncrementStrategyPower2();
+ setValue(val);
connect(m_plus, &QAbstractButton::clicked, this, [=]() { setValue(m_incrementStrategy->increment(m_value)); });
- connect(m_minus, &QAbstractButton::clicked, this, [=]() { setValue(m_incrementStrategy->decrement(m_value)); });
-
- connect(m_edit, &QLineEdit::editingFinished, this, [=]() { userInput(m_edit->text()); });
-
- connect(m_scaleCb, qOverload(&QComboBox::currentIndexChanged), this, [=](int idx) {
- m_incrementStrategy->setScale(m_scaleCb->itemData(idx).toDouble());
+ connect(m_minus, &QAbstractButton::clicked, this, [=]() {
+ double newValue = m_incrementStrategy->decrement(m_value);
+ if(m_scale->scalingEnabled()) {
+ // if value would be 0 check if lower scale available
+ int idx = m_scale->scaleCb()->currentIndex();
+ if(newValue == 0 && (idx - 1) >= 0) {
+ // found lower scale update value based on that
+ setValue(m_value - (1 * m_scale->scaleCb()->itemData(idx - 1).toDouble()));
+ } else {
+ setValue(newValue);
+ }
+ } else {
+ setValue(newValue);
+ }
+ });
+ connect(m_edit, &QLineEdit::editingFinished, this, [=]() {
+ m_edit->blockSignals(true);
userInput(m_edit->text());
+ m_edit->blockSignals(false);
});
- m_scales.append({QString("n"), 1e-9});
- m_scales.append({QString("u"), 1e-6});
- m_scales.append({QString("m"), 1e-3});
- m_scales.append({QString(""), 1e0});
- m_scales.append({QString("k"), 1e3});
- m_scales.append({QString("M"), 1e6});
- m_scales.append({QString("G"), 1e9});
-
- m_name = name;
- m_unit = unit;
- m_min = min;
- m_max = max;
- m_scaleMin = min;
- m_scaleMax = max;
- setScaleRange(m_scaleMin, m_scaleMax);
- setValue(val);
- m_scalingEnabled = true;
+ connect(m_scale->scaleCb(), qOverload(&QComboBox::currentIndexChanged), this,
+ [=]() { userInput(m_edit->text()); });
+
+ connect(m_scale, &Scale::unitChanged, this, &MenuSpinbox::unitChanged);
+ connect(m_scale, &Scale::scaleUpdated, this, &MenuSpinbox::populateWidgets);
+
m_mouseWheelGuard->installEventRecursively(this);
}
@@ -111,7 +119,7 @@ void MenuSpinbox::layoutVertically(bool left)
editLay->addWidget(m_label);
editLay->addWidget(m_edit);
- editLay->addWidget(m_scaleCb);
+ editLay->addWidget(m_scale->scaleCb());
if(left) {
lay->addLayout(btnLay);
@@ -122,7 +130,7 @@ void MenuSpinbox::layoutVertically(bool left)
}
Style::setStyle(m_label, style::properties::label::subtle);
- Style::setStyle(m_scaleCb, style::properties::widget::noBorder);
+ Style::setStyle(m_scale->scaleCb(), style::properties::widget::noBorder);
int size = Style::getDimension(json::global::unit_2_5);
m_plus->setIcon(Style::getPixmap(":/gui/icons/plus.svg", Style::getColor(json::theme::content_inverse)));
@@ -164,7 +172,7 @@ void MenuSpinbox::layoutHorizontally(bool left)
editLay->addWidget(m_label);
editLay->addWidget(m_edit);
- editLay->addWidget(m_scaleCb);
+ editLay->addWidget(m_scale->scaleCb());
lineLay->addLayout(lay);
if(left) {
@@ -193,8 +201,20 @@ void MenuSpinbox::setValue(double newValue) { setValueForce(newValue, 0); }
void MenuSpinbox::setValueForce(double newValue, bool force)
{
- if(qFuzzyCompare(m_value, newValue) || force)
+ // when force is true value does not consider min/max limits
+ if(force) {
+ m_value = newValue;
+ populateWidgets();
+ Q_EMIT valueChanged(m_value);
return;
+ }
+
+ if(qFuzzyCompare(m_value, newValue)) {
+ // check if text in edit changed even if value does not
+ if(QString::number(m_value).compare(m_edit->text()) != 0)
+ populateWidgets(); // reset value
+ return;
+ }
m_value = clamp(newValue, m_min, m_max);
populateWidgets();
@@ -203,16 +223,9 @@ void MenuSpinbox::setValueForce(double newValue, bool force)
void MenuSpinbox::setValueString(QString s) { userInput(s); }
-QString MenuSpinbox::unit() const { return m_unit; }
+QString MenuSpinbox::unit() const { return m_scale->unit(); }
-void MenuSpinbox::setUnit(const QString &newUnit)
-{
- if(m_unit == newUnit)
- return;
- m_unit = newUnit;
- setScaleRange(m_scaleMin, m_scaleMax);
- Q_EMIT unitChanged(newUnit);
-}
+void MenuSpinbox::setUnit(const QString &newUnit) { m_scale->setUnit(newUnit); }
void MenuSpinbox::setMinValue(double min) { m_min = min; }
@@ -240,15 +253,27 @@ void MenuSpinbox::setIncrementMode(IncrementMode im)
m_incrementStrategy = new IncrementStrategyFixed();
break;
}
- m_incrementStrategy->setScale(m_scaleCb->currentData().toDouble());
+
+ // when scalling is not enbaled scale will be set to 1
+ if(scallingEnabled()) {
+ m_incrementStrategy->setScale(m_scale->scaleCb()->currentData().toDouble());
+ } else {
+ m_incrementStrategy->setScale(1);
+ }
}
void MenuSpinbox::setScalingEnabled(bool en)
{
- m_scalingEnabled = en;
- m_scaleCb->setVisible(en);
+ m_scale->setScalingEnabled(en);
+ if(en) {
+ m_incrementStrategy->setScale(m_scale->scaleCb()->currentData().toDouble());
+ } else {
+ m_incrementStrategy->setScale(1);
+ }
}
+bool MenuSpinbox::scallingEnabled() { return m_scale->scalingEnabled(); }
+
void MenuSpinbox::userInput(QString s)
{
// remove whitespace
@@ -262,84 +287,57 @@ void MenuSpinbox::userInput(QString s)
bool ok;
double val = nr.toDouble(&ok);
if(!ok)
- setValue(m_value); // reset
-
- if(m_scalingEnabled) {
- QString unit = s.mid(i + 1, 1); // isolate prefix and unit from the whole string (mV)
- if(unit.length() > 0) { // user wrote a prefix and/or a unit
- double scale = getScaleForPrefix(unit, Qt::CaseSensitive); // find the unit in the map
- if(scale == -1) {
- scale = getScaleForPrefix(
- unit,
- Qt::CaseInsensitive); // the user may have written 30K instead of 30k
- }
-
- if(scale == -1) {
- scale = 1; // do not scale the value at all
+ populateWidgets(); // reset
+
+ if(m_scale->scalingEnabled()) {
+ QString unit = s.mid(i + 1, s.length() - 1); // isolate unit from the whole string (min)
+ if(unit.length() > 0) { // user wrote a unit
+ double scaleValue = m_scale->getScaleForSymbol(unit); // find the unit in the map
+ if(scaleValue == -1) {
+ populateWidgets(); // inputed prefix is invalid
} else {
- val = val * scale; // scale accordingly
+ val = val * scaleValue; // scale accordingly
}
+
} else {
- val = val *
- m_scaleCb->currentData()
- .toDouble(); // the user didnt write a scale => use scale in combobox
+ // Apply current scale to value
+ double scaleValue = m_scale->scaleCb()->currentData().toDouble();
+ val = val * scaleValue;
}
}
+
setValue(val);
}
void MenuSpinbox::populateWidgets()
{
- // TODO: Review this function
- if(!m_scalingEnabled) {
- QSignalBlocker sb1(m_edit);
- QSignalBlocker sb2(m_scaleCb);
- m_edit->setText(Util::doubleToQString(m_value));
+ // block all signals that affect value changes before updating widgets
+ // update values for edittext
+ m_edit->blockSignals(true);
+
+ if(m_scale->scalingEnabled()) {
+
+ m_scale->scaleCb()->blockSignals(true);
+ m_scale->computeScale(m_value);
+ double scale = m_scale->scaleCb()->currentData().toDouble();
+
+ // print value based on scale
+ m_edit->setText(QString::number(m_value / scale));
setToolTip(QString::number(m_value, 'f', 6)); // set tooltip
- return;
- }
- int i = 0;
- double scale = 1;
- double absvalue = abs(m_value);
- if(qFuzzyCompare(absvalue, 0)) {
- scale = 1;
- for(i = m_scaleCb->count() - 1; i >= 0; i--) { // find most suitable scale
- if(m_scaleCb->itemData(i).toDouble() == 1)
- break;
- }
+ // update scale for increment strategy
+ m_incrementStrategy->setScale(scale);
+ m_scale->scaleCb()->blockSignals(false);
+
} else {
- for(i = m_scaleCb->count() - 1; i >= 0; i--) { // find most suitable scale
- scale = m_scaleCb->itemData(i).toDouble();
- if(absvalue / scale >= 10)
- break;
- }
- if(i < 0) {
- i = 0;
- scale = m_scaleCb->itemData(i).toDouble();
- }
+ // when no scaling is enabled we just update value
+ m_edit->setText(QString::number(m_value));
}
+ m_edit->blockSignals(false);
- QSignalBlocker sb1(m_edit);
- QSignalBlocker sb2(m_scaleCb);
- m_edit->setText(QString::number(m_value / scale)); // reduce number to a meaningful value
- m_scaleCb->setCurrentIndex(i); // set apropriate scale in combobox
- m_incrementStrategy->setScale(m_scaleCb->currentData().toDouble());
setToolTip(QString::number(m_value, 'f', 6)); // set tooltip
}
-void MenuSpinbox::setScaleRange(double min, double max)
-{
- m_scaleCb->clear();
- for(int i = 0; i < m_scales.count(); i++) {
- auto scale = m_scales[i].scale;
- if(scale >= min && scale <= max) {
- m_scaleCb->addItem(m_scales[i].prefix + m_unit, scale);
- }
- }
- m_incrementStrategy->setScale(m_scaleCb->currentData().toDouble());
-}
-
int MenuSpinbox::findLastDigit(QString str)
{
for(int i = str.length() - 1; i >= 0; --i) {
@@ -354,9 +352,31 @@ double MenuSpinbox::clamp(double val, double min, double max)
{
val = std::max(val, min);
val = std::min(val, max);
+ minMaxReached(val);
return val;
}
+void MenuSpinbox::minMaxReached(double val)
+{
+ // disable decrement button if min is reached
+ if(val == m_min) {
+ m_minus->setEnabled(false);
+ } else {
+ m_minus->setEnabled(true);
+ }
+
+ // disable increment button if max is reached
+ if(val == m_max) {
+ m_plus->setEnabled(false);
+ } else {
+ m_plus->setEnabled(true);
+ }
+}
+
+Scale *MenuSpinbox::scale() const { return m_scale; }
+
+void MenuSpinbox::setScale(Scale *newScale) { m_scale = newScale; }
+
QString MenuSpinbox::name() const { return m_name; }
void MenuSpinbox::setName(const QString &newName)
@@ -368,22 +388,6 @@ void MenuSpinbox::setName(const QString &newName)
Q_EMIT nameChanged(newName);
}
-double MenuSpinbox::getScaleForPrefix(QString prefix, Qt::CaseSensitivity s)
-{
- for(int i = 0; i < m_scales.count(); i++) {
- if(s == Qt::CaseSensitive) {
- if(m_scales[i].prefix == prefix) {
- return m_scales[i].scale;
- }
- } else {
- if(m_scales[i].prefix.toLower() == prefix.toLower()) {
- return m_scales[i].scale;
- }
- }
- }
- return -1;
-}
-
} // namespace gui
} // namespace scopy
diff --git a/gui/src/widgets/scale.cpp b/gui/src/widgets/scale.cpp
new file mode 100644
index 0000000000..e953cc876f
--- /dev/null
+++ b/gui/src/widgets/scale.cpp
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2024 Analog Devices Inc.
+ *
+ * This file is part of Scopy
+ * (see https://www.github.com/analogdevicesinc/scopy).
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+#include "scale.h"
+
+namespace scopy {
+namespace gui {
+
+Scale::Scale(QString unit, double min, double max, bool hasPrefix)
+ : m_unit(unit)
+ , m_min(min)
+ , m_max(max)
+ , m_hasPrefix(hasPrefix)
+{
+ m_scaleCb = new QComboBox();
+
+ if(hasPrefix) {
+ // PRESET METRIC PREFIX
+ m_scalePrefixes.append({QString("n"), 1e-9});
+ m_scalePrefixes.append({QString("u"), 1e-6});
+ m_scalePrefixes.append({QString("m"), 1e-3});
+ m_scalePrefixes.append({QString(""), 1e0});
+ m_scalePrefixes.append({QString("k"), 1e3});
+ m_scalePrefixes.append({QString("M"), 1e6});
+ m_scalePrefixes.append({QString("G"), 1e9});
+ }
+
+ m_scaleOptions.append({m_unit, 1e0});
+ populateScaleCb();
+ m_scaleCb->setCurrentIndex(0);
+}
+
+Scale::~Scale()
+{
+ m_scaleOptions.clear();
+ m_scalePrefixes.clear();
+}
+
+double Scale::getScaleForPrefix(QString prefix, Qt::CaseSensitivity s)
+{
+ for(int i = 0; i < m_scalePrefixes.count(); i++) {
+
+ if(s == Qt::CaseSensitive) {
+ if(m_scalePrefixes[i].prefix == prefix) {
+ return m_scalePrefixes[i].scale;
+ }
+ } else {
+ if(m_scalePrefixes[i].prefix.toLower() == prefix.toLower()) {
+ return m_scalePrefixes[i].scale;
+ }
+ }
+ }
+ return -1;
+}
+
+double Scale::getScaleForUnit(QString unit, Qt::CaseSensitivity s)
+{
+ for(int i = 0; i < m_scaleOptions.count(); i++) {
+ if(s == Qt::CaseSensitive) {
+ if(m_scaleOptions[i].option == unit) {
+ return m_scaleOptions[i].scale;
+ }
+ } else {
+ if(m_scaleOptions[i].option.toLower() == unit.toLower()) {
+ return m_scaleOptions[i].scale;
+ }
+ }
+ }
+ return -1;
+}
+
+double Scale::getScaleForSymbol(QString symbol)
+{
+ if(m_hasPrefix) {
+ // TODO apply some filters for unit of measure ??
+ double value = getScaleForPrefix(symbol.mid(0, 1), Qt::CaseSensitive);
+ if(value == -1) {
+ value = getScaleForPrefix(symbol.mid(0, 1), Qt::CaseInsensitive);
+ }
+ return value;
+ } else {
+ double value = getScaleForUnit(symbol, Qt::CaseSensitive);
+ if(value == -1) {
+ value = getScaleForUnit(symbol, Qt::CaseInsensitive);
+ }
+ return value;
+ }
+}
+
+bool Scale::scalingEnabled() const { return m_scalingEnabled; }
+
+void Scale::setScalingEnabled(bool newScalingEnabled)
+{
+ m_scalingEnabled = newScalingEnabled;
+ m_scaleCb->setVisible(newScalingEnabled);
+}
+
+QComboBox *Scale::scaleCb() const { return m_scaleCb; }
+
+QString Scale::unit() const { return m_unit; }
+
+void Scale::setUnit(const QString &newUnit)
+{
+ m_unit = newUnit;
+ // when using custom scales changing the unit also resets the scale
+ if(!m_hasPrefix) {
+ // reset scale options to new unit
+ m_scaleOptions.clear();
+ m_scaleOptions.append({m_unit, 1e0});
+ }
+ populateScaleCb();
+}
+
+void Scale::computeScale(double value)
+{
+ // if there is only one option in the scale use that
+ if(m_scaleCb->count() == 0) {
+ return;
+ }
+ // use absolute value when computing scale
+ double val = abs(value);
+ // check if value can be upscaled or downscaled if scaled is changed update scale
+ int curretnScaleIndex = m_scaleCb->currentIndex();
+ // value is bigger than current scale
+ if(val > m_scaleCb->itemData(curretnScaleIndex).toDouble()) {
+ if(curretnScaleIndex != m_scaleCb->count() - 1) {
+ int i = 0;
+ // find coresponding upper scale
+ while((val >= m_scaleCb->itemData(curretnScaleIndex + i).toDouble()) &&
+ ((curretnScaleIndex + i) <= m_scaleCb->count() - 1)) {
+ i++;
+ }
+ m_scaleCb->setCurrentIndex(curretnScaleIndex + i - 1);
+ }
+ } else {
+ // value is lower than current scale
+ int i = curretnScaleIndex;
+ // find coresponding lower scale
+ while((val < m_scaleCb->itemData(i).toDouble()) && (i > 0)) {
+ i--;
+ }
+ m_scaleCb->setCurrentIndex(i);
+ }
+}
+
+bool Scale::hasPrefix() const { return m_hasPrefix; }
+
+void Scale::setHasPrefix(bool newHasPrefix)
+{
+ m_hasPrefix = newHasPrefix;
+ populateScaleCb();
+}
+
+void Scale::populateScaleCb()
+{
+ m_scaleCb->clear();
+ if(m_hasPrefix) {
+ for(int i = 0; i < m_scalePrefixes.count(); i++) {
+ auto scale = m_scalePrefixes[i].scale;
+ m_scaleCb->addItem(m_scalePrefixes[i].prefix + m_unit, scale);
+ }
+ } else {
+ for(int i = 0; i < m_scaleOptions.count(); i++) {
+ m_scaleCb->addItem(m_scaleOptions[i].option, m_scaleOptions[i].scale);
+ }
+ }
+
+ Q_EMIT scaleUpdated();
+}
+
+QList Scale::scalePrefixes() const { return m_scalePrefixes; }
+
+void Scale::setScalePrefixes(const QList &newScalePrefixes)
+{
+ m_scalePrefixes = newScalePrefixes;
+ populateScaleCb();
+}
+
+QList Scale::scaleOptions() const { return m_scaleOptions; }
+
+void Scale::setScaleOptions(const QList &newScaleOptions)
+{
+ m_scaleOptions = newScaleOptions;
+ populateScaleCb();
+}
+
+} // namespace gui
+} // namespace scopy
+
+#include "moc_scale.cpp"
diff --git a/iio-widgets/src/guistrategy/rangeguistrategy.cpp b/iio-widgets/src/guistrategy/rangeguistrategy.cpp
index 1a01bfcc45..da48929b99 100644
--- a/iio-widgets/src/guistrategy/rangeguistrategy.cpp
+++ b/iio-widgets/src/guistrategy/rangeguistrategy.cpp
@@ -39,8 +39,6 @@ RangeAttrUi::RangeAttrUi(IIOWidgetFactoryRecipe recipe, bool isCompact, QWidget
m_ui->layout()->setContentsMargins(0, 0, 0, 0);
m_spinBox = new gui::MenuSpinbox(m_recipe.data.toUpper(), 0, "", 0, 1, true, false, m_ui);
- m_spinBox->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
- m_spinBox->setScaleRange(1, 1);
m_spinBox->setScalingEnabled(false);
m_ui->layout()->addWidget(m_spinBox);
diff --git a/plugins/adc/src/freq/fftplotcomponentsettings.cpp b/plugins/adc/src/freq/fftplotcomponentsettings.cpp
index e778b438f5..60a924395a 100644
--- a/plugins/adc/src/freq/fftplotcomponentsettings.cpp
+++ b/plugins/adc/src/freq/fftplotcomponentsettings.cpp
@@ -68,6 +68,8 @@ FFTPlotComponentSettings::FFTPlotComponentSettings(FFTPlotComponent *plt, QWidge
MenuCollapseSection::MHW_BASEWIDGET, parent);
m_yCtrl = new MenuPlotAxisRangeControl(m_plotComponent->fftPlot()->yAxis(), this);
+ m_yCtrl->minSpinbox()->scale()->setHasPrefix(false);
+ m_yCtrl->maxSpinbox()->scale()->setHasPrefix(false);
m_yCtrl->minSpinbox()->setIncrementMode(MenuSpinbox::IS_FIXED);
m_yCtrl->maxSpinbox()->setIncrementMode(MenuSpinbox::IS_FIXED);
m_yCtrl->minSpinbox()->setUnit("dB");
@@ -76,8 +78,6 @@ FFTPlotComponentSettings::FFTPlotComponentSettings(FFTPlotComponent *plt, QWidge
m_yCtrl->maxSpinbox()->setMinValue(-1000);
m_yCtrl->minSpinbox()->setMaxValue(1000);
m_yCtrl->maxSpinbox()->setMaxValue(1000);
- m_yCtrl->minSpinbox()->setScaleRange(1, 1);
- m_yCtrl->maxSpinbox()->setScaleRange(1, 1);
MenuOnOffSwitch *m_autoscaleBtn = new MenuOnOffSwitch(tr("AUTOSCALE"), plotMenu, false);
m_autoscaler = new PlotAutoscaler(this);
@@ -96,8 +96,7 @@ FFTPlotComponentSettings::FFTPlotComponentSettings(FFTPlotComponent *plt, QWidge
m_plotComponent->fftPlot()->yAxis()->getFormatter()->setTwoDecimalMode(false);
m_yPwrOffset = new MenuSpinbox("Power Offset", 0, "dB", -300, 300, true, false, yaxis);
- m_yPwrOffset->setScaleRange(1, 1);
- m_yPwrOffset->setIncrementMode(MenuSpinbox::IS_FIXED);
+ m_yPwrOffset->scale()->setHasPrefix(false);
m_windowCb = new MenuCombo("Window", yaxis);
diff --git a/plugins/adc/src/freq/fftplotmanagersettings.cpp b/plugins/adc/src/freq/fftplotmanagersettings.cpp
index a0b9bae744..1ec2bcd531 100644
--- a/plugins/adc/src/freq/fftplotmanagersettings.cpp
+++ b/plugins/adc/src/freq/fftplotmanagersettings.cpp
@@ -108,7 +108,8 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
MenuCollapseSection::MHW_BASEWIDGET, parent);
m_bufferSizeSpin = new MenuSpinbox("Buffer Size", 16, "samples", 0, 4000000, true, false, section);
- m_bufferSizeSpin->setScaleRange(1, 1e6);
+ m_bufferSizeSpin->setIncrementMode(MenuSpinbox::IS_POW2);
+ m_bufferSizeSpin->scale()->setScalePrefixes({{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
connect(m_bufferSizeSpin, &MenuSpinbox::valueChanged, this, [=](double val) { setBufferSize((uint32_t)val); });
QWidget *xMinMax = new QWidget(section);
@@ -118,10 +119,7 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
xMinMax->setLayout(xMinMaxLayout);
m_xmin = new MenuSpinbox("XMin", 0, "samples", -DBL_MAX, DBL_MAX, true, false, xMinMax);
- m_xmin->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
-
m_xmax = new MenuSpinbox("XMax", 0, "samples", -DBL_MAX, DBL_MAX, true, false, xMinMax);
- m_xmax->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
connect(m_xmin, &MenuSpinbox::valueChanged, this,
[=](double min) { m_plotManager->setXInterval(m_xmin->value(), m_xmax->value()); });
@@ -194,6 +192,7 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
m_sampleRateSpin = new MenuSpinbox("Sample Rate", 1, "Hz", 0, DBL_MAX, true, false, section);
m_sampleRateSpin->setIncrementMode(MenuSpinbox::IS_125);
+ m_sampleRateSpin->scale()->setHasPrefix(false);
m_sampleRateSpin->setValue(10);
m_sampleRateSpin->setEnabled(false);
@@ -201,6 +200,7 @@ QWidget *FFTPlotManagerSettings::createXAxisMenu(QWidget *parent)
m_freqOffsetSpin = new MenuSpinbox("Frequency Offset", 1, "Hz", 0, DBL_MAX, true, false, section);
m_freqOffsetSpin->setIncrementMode(MenuSpinbox::IS_125);
+ m_freqOffsetSpin->scale()->setHasPrefix(false);
m_freqOffsetSpin->setValue(0);
m_freqOffsetSpin->setEnabled(false);
diff --git a/plugins/adc/src/freq/grfftchannelcomponent.cpp b/plugins/adc/src/freq/grfftchannelcomponent.cpp
index df2d1cc8b0..7ecd239fc4 100644
--- a/plugins/adc/src/freq/grfftchannelcomponent.cpp
+++ b/plugins/adc/src/freq/grfftchannelcomponent.cpp
@@ -239,8 +239,7 @@ QWidget *GRFFTChannelComponent::createMarkerMenu(QWidget *parent)
fixedMarkerEditBtn->setVisible(false);
MenuSpinbox *markerCnt = new MenuSpinbox("Marker count", 5, "markers", 0, 9, true, false, section);
- markerCnt->setIncrementMode(MenuSpinbox::IS_FIXED);
- markerCnt->setScaleRange(1, 10);
+ markerCnt->scale()->setHasPrefix(false);
markerCnt->setValue(5);
connect(markerCnt, &MenuSpinbox::valueChanged, this,
diff --git a/plugins/adc/src/time/timeplotmanagersettings.cpp b/plugins/adc/src/time/timeplotmanagersettings.cpp
index 6909aa68d2..3074411d1f 100644
--- a/plugins/adc/src/time/timeplotmanagersettings.cpp
+++ b/plugins/adc/src/time/timeplotmanagersettings.cpp
@@ -109,7 +109,8 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
bufferPlotSize->setLayout(bufferPlotSizeLayout);
m_bufferSizeSpin = new MenuSpinbox("Buffer Size", 16, "samples", 16, 4000000, true, false, bufferPlotSize);
- m_bufferSizeSpin->setScaleRange(1, 1e6);
+ m_bufferSizeSpin->setIncrementMode(MenuSpinbox::IS_POW2);
+ m_bufferSizeSpin->scale()->setScalePrefixes({{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
connect(m_bufferSizeSpin, &MenuSpinbox::valueChanged, this, [=](double val) {
if(m_plotSizeSpin->value() < val) {
@@ -122,7 +123,8 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
connect(this, &TimePlotManagerSettings::bufferSizeChanged, m_bufferSizeSpin, &MenuSpinbox::setValue);
m_plotSizeSpin = new MenuSpinbox("Plot Size", 16, "samples", 0, 4000000, true, false, bufferPlotSize);
- m_plotSizeSpin->setScaleRange(1, 1e6);
+ m_plotSizeSpin->setIncrementMode(MenuSpinbox::IS_POW2);
+ m_plotSizeSpin->scale()->setScalePrefixes({{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
connect(m_plotSizeSpin, &MenuSpinbox::valueChanged, this, [=](double val) { setPlotSize((uint32_t)val); });
@@ -153,10 +155,7 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
xMinMax->setLayout(xMinMaxLayout);
m_xmin = new MenuSpinbox("XMin", -1, "samples", -DBL_MAX, DBL_MAX, true, false, xMinMax);
- m_xmin->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
-
m_xmax = new MenuSpinbox("XMax", -1, "samples", -DBL_MAX, DBL_MAX, true, false, xMinMax);
- m_xmax->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
connect(m_xmin, &MenuSpinbox::valueChanged, this,
[=](double min) { m_plotManager->setXInterval(m_xmin->value(), m_xmax->value()); });
@@ -177,9 +176,14 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
if(xcb->itemData(idx) == XMODE_SAMPLES) {
m_sampleRateSpin->setValue(1);
m_xmin->setUnit("samples");
- m_xmin->setScaleRange(1, 1e6);
+ m_xmin->scale()->setHasPrefix(true);
+ m_xmin->scale()->setScalePrefixes(
+ {{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
+
m_xmax->setUnit("samples");
- m_xmax->setScaleRange(1, 1e6);
+ m_xmax->scale()->setHasPrefix(true);
+ m_xmax->scale()->setScalePrefixes(
+ {{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
m_plotManager->setXUnit("samples");
for(PlotComponent *plt : m_plotManager->plots()) {
auto p = dynamic_cast(plt);
@@ -191,10 +195,21 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
m_sampleRateSpin->setVisible(true);
m_sampleRateSpin->setEnabled(false);
m_sampleRateSpin->setValue(readSampleRate());
+
m_xmin->setUnit("s");
- m_xmin->setScaleRange(0, 1);
+ m_xmin->scale()->setHasPrefix(false);
+ m_xmin->scale()->setScaleOptions({{QString("ns"), 1e-9},
+ {QString("us"), 1e-6},
+ {QString("ms"), 1e-3},
+ {QString("s"), 1}});
+
m_xmax->setUnit("s");
- m_xmax->setScaleRange(0, 1);
+ m_xmax->scale()->setHasPrefix(false);
+ m_xmax->scale()->setScaleOptions({{QString("ns"), 1e-9},
+ {QString("us"), 1e-6},
+ {QString("ms"), 1e-3},
+ {QString("s"), 1}});
+
m_plotManager->setXUnit("s");
for(PlotComponent *plt : m_plotManager->plots()) {
@@ -209,9 +224,15 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
m_sampleRateSpin->setEnabled(true);
m_xmin->setUnit("s");
- m_xmin->setScaleRange(0, 1);
+ m_xmin->scale()->setHasPrefix(false);
+ m_xmin->scale()->setScaleOptions(
+ {{QString("s"), 1}, {QString("min"), 60}, {QString("h"), 3600}});
+
m_xmax->setUnit("s");
- m_xmax->setScaleRange(0, 1);
+ m_xmax->scale()->setHasPrefix(false);
+ m_xmax->scale()->setScaleOptions(
+ {{QString("s"), 1}, {QString("min"), 60}, {QString("h"), 3600}});
+
m_plotManager->setXUnit("s");
for(PlotComponent *plt : m_plotManager->plots()) {
auto p = dynamic_cast(plt);
diff --git a/plugins/dac/src/bufferdacaddon.cpp b/plugins/dac/src/bufferdacaddon.cpp
index 51ae43652b..1c2163e864 100644
--- a/plugins/dac/src/bufferdacaddon.cpp
+++ b/plugins/dac/src/bufferdacaddon.cpp
@@ -80,6 +80,7 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
buffersizeContainer->setProperty("tutorial_name", "BUFFERSIZE");
m_bufferSizeSpin =
new MenuSpinbox("Buffer size", 0, "samples", 16, 16 * 1024 * 1024, true, false, buffersizeContainer);
+ m_bufferSizeSpin->scale()->setScalePrefixes({{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
StyleHelper::BackgroundWidget(m_bufferSizeSpin);
connect(m_bufferSizeSpin, &MenuSpinbox::valueChanged, this,
[&](double value) { m_model->setBuffersize(value); });
@@ -91,7 +92,7 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
MenuSectionWidget *kernelContainer = new MenuSectionWidget(this);
kernelContainer->setProperty("tutorial_name", "KERNEL_BUFFERS");
m_kernelCountSpin = new MenuSpinbox("Kernel buffers", 0, "", 1, 64, true, false, buffersizeContainer);
- m_kernelCountSpin->setIncrementMode(MenuSpinbox::IS_FIXED);
+ m_kernelCountSpin->setScalingEnabled(false);
StyleHelper::BackgroundWidget(m_kernelCountSpin);
connect(m_kernelCountSpin, &MenuSpinbox::valueChanged, this,
[&](double value) { m_model->setKernelBuffersCount(value); });
@@ -101,6 +102,7 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
// Decimation section - hidden for now
MenuSpinbox *decimationSpin = new MenuSpinbox("Decimation", 0, "", 1, 1000, true, false, bufferConfigSection);
+ decimationSpin->setIncrementMode(MenuSpinbox::IS_POW2);
StyleHelper::BackgroundWidget(decimationSpin);
connect(decimationSpin, &MenuSpinbox::valueChanged, this, [&](double value) { m_model->setDecimation(value); });
decimationSpin->setValue(1);
@@ -152,12 +154,11 @@ BufferDacAddon::BufferDacAddon(DacDataModel *model, QWidget *parent)
filesizeContainer->setProperty("tutorial_name", "FILESIZE");
m_fileSizeSpin =
new MenuSpinbox("File size", 0, "samples", 16, 16 * 1024 * 1024, false, false, filesizeContainer);
- m_fileSizeSpin->setIncrementMode(MenuSpinbox::IS_FIXED);
StyleHelper::BackgroundWidget(m_fileSizeSpin);
connect(
m_fileSizeSpin, &MenuSpinbox::valueChanged, this, [&](double value) { m_model->setFilesize(value); },
Qt::QueuedConnection);
- m_fileSizeSpin->setScaleRange(1, 16 * 1024 * 1024);
+ m_fileSizeSpin->scale()->setScalePrefixes({{QString(""), 1e0}, {QString("k"), 1e3}, {QString("M"), 1e6}});
m_fileSizeSpin->setValue(16);
filesizeContainer->contentLayout()->addWidget(m_fileSizeSpin);
filesizeContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
diff --git a/plugins/datalogger/src/menus/plottimeaxiscontroller.cpp b/plugins/datalogger/src/menus/plottimeaxiscontroller.cpp
index cf7e4ee1a4..5afca03802 100644
--- a/plugins/datalogger/src/menus/plottimeaxiscontroller.cpp
+++ b/plugins/datalogger/src/menus/plottimeaxiscontroller.cpp
@@ -61,8 +61,8 @@ PlotTimeAxisController::PlotTimeAxisController(MonitorPlot *m_plot, QWidget *par
m_xdelta = new gui::MenuSpinbox("Delta", DataMonitorUtils::getAxisDefaultMaxValue(), "s", 0, DBL_MAX, false,
false, xAxisContainer);
- m_xdelta->setScaleRange(1, 1);
- m_xdelta->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
+ m_xdelta->scale()->setHasPrefix(false);
+ m_xdelta->scale()->setScaleOptions({{QString("s"), 1}, {QString("min"), 60}, {QString("h"), 3600}});
m_xdelta->setValue(DataMonitorUtils::getAxisDefaultMaxValue());
auto &&timeTracker = TimeManager::GetInstance();
diff --git a/plugins/pqm/src/waveforminstrument.cpp b/plugins/pqm/src/waveforminstrument.cpp
index cef56836fc..04556d5ce3 100644
--- a/plugins/pqm/src/waveforminstrument.cpp
+++ b/plugins/pqm/src/waveforminstrument.cpp
@@ -178,7 +178,6 @@ QWidget *WaveformInstrument::createMenuPlotSection(QWidget *parent)
// timespan
m_timespanSpin = new gui::MenuSpinbox(tr("Timespan"), 1, "s", 0.02, 10, true, false, plotSection);
- m_timespanSpin->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
m_timespanSpin->setValue(1);
connect(m_timespanSpin, &gui::MenuSpinbox::valueChanged, this, [=, this](double value) {
m_voltagePlot->xAxis()->setMin(-value);
diff --git a/plugins/swiot/src/ad74413r/ad74413r.cpp b/plugins/swiot/src/ad74413r/ad74413r.cpp
index af449c6eee..ce24fe8ed3 100644
--- a/plugins/swiot/src/ad74413r/ad74413r.cpp
+++ b/plugins/swiot/src/ad74413r/ad74413r.cpp
@@ -705,7 +705,7 @@ QWidget *Ad74413r::createSettingsMenu(QWidget *parent)
// timespan
m_timespanSpin = new MenuSpinbox(tr("Timespan"), 1, "s", 0.1, 10, true, false, plotTimespanSection);
- m_timespanSpin->setIncrementMode(MenuSpinbox::IS_FIXED);
+ m_timespanSpin->scale()->setHasPrefix(false);
connect(m_timespanSpin, &MenuSpinbox::valueChanged, this,
[=, this](double value) { m_plot->xAxis()->setMin(-value); });
diff --git a/plugins/swiot/src/ad74413r/buffermenuview.cpp b/plugins/swiot/src/ad74413r/buffermenuview.cpp
index 08413cf42d..ff7209314f 100644
--- a/plugins/swiot/src/ad74413r/buffermenuview.cpp
+++ b/plugins/swiot/src/ad74413r/buffermenuview.cpp
@@ -140,11 +140,7 @@ QWidget *BufferMenuView::createVerticalSettingsMenu(QString unit, double yMin, d
"Y-AXIS", MenuCollapseSection::MHCW_NONE, MenuCollapseSection::MHW_BASEWIDGET, verticalContainer);
auto m_yMin = new MenuSpinbox("YMin", yMin, unit, -DBL_MAX, DBL_MAX, true, false, verticalContainer);
- m_yMin->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
-
auto m_yMax = new MenuSpinbox("YMax", yMax, unit, -DBL_MAX, DBL_MAX, true, false, verticalContainer);
- m_yMax->setIncrementMode(gui::MenuSpinbox::IS_FIXED);
-
layout->addWidget(m_yMin);
layout->addWidget(m_yMax);
diff --git a/plugins/swiot/src/max14906/diosettingstab.cpp b/plugins/swiot/src/max14906/diosettingstab.cpp
index 6506c3095a..3f02e841ba 100644
--- a/plugins/swiot/src/max14906/diosettingstab.cpp
+++ b/plugins/swiot/src/max14906/diosettingstab.cpp
@@ -51,8 +51,7 @@ DioSettingsTab::DioSettingsTab(QWidget *parent)
// timespan
m_maxSpinButton = new MenuSpinbox(tr("Timespan"), 10, "s", 1, 300, true, false, this);
- m_maxSpinButton->setIncrementMode(MenuSpinbox::IS_FIXED);
- m_maxSpinButton->setScaleRange(1, 1);
+ m_maxSpinButton->scale()->setHasPrefix(false);
connect(m_maxSpinButton, &MenuSpinbox::valueChanged, this,
[this]() { Q_EMIT timeValueChanged(m_maxSpinButton->value()); });