Skip to content

Commit

Permalink
generic: bug fix for menu spinbox
Browse files Browse the repository at this point in the history
fixed bug where you can set bad values for time
fixed bug where disabling scale is ignored on computing input value
added initial value of m_scale for fixed strategy

Signed-off-by: IonutMuthi <[email protected]>
  • Loading branch information
IonutMuthi committed Nov 15, 2024
1 parent e504773 commit 79d0c16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion gui/include/gui/widgets/menuspinbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ class SCOPY_GUI_EXPORT IncrementStrategyPower2 : public IncrementStrategy
class SCOPY_GUI_EXPORT IncrementStrategyFixed : public IncrementStrategy
{
public:
IncrementStrategyFixed(double k = 1) { m_k = k; };
IncrementStrategyFixed(double k = 1)
{
m_k = k;
m_scale = 1;
};
~IncrementStrategyFixed(){};
virtual double increment(double val) override
{
Expand Down
31 changes: 17 additions & 14 deletions gui/src/widgets/menuspinbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,27 @@ void MenuSpinbox::userInput(QString s)
if(!ok)
setValue(m_value); // reset

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(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
if(scale == -1) {
scale = 1; // do not scale the value at all
} else {
val = val * scale; // scale accordingly
}
} else {
val = val * scale; // scale accordingly
val = val *
m_scaleCb->currentData()
.toDouble(); // the user didnt write a scale => use scale in combobox
}
} else {
val = val *
m_scaleCb->currentData().toDouble(); // the user didnt write a scale => use scale in combobox
}

setValue(val);
}

Expand Down
6 changes: 6 additions & 0 deletions plugins/adc/src/time/timeplotmanagersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ 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_xmax->setUnit("samples");
m_xmax->setScaleRange(1, 1e6);
m_plotManager->setXUnit("samples");
for(PlotComponent *plt : m_plotManager->plots()) {
auto p = dynamic_cast<TimePlotComponent *>(plt);
Expand All @@ -190,7 +192,9 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
m_sampleRateSpin->setEnabled(false);
m_sampleRateSpin->setValue(readSampleRate());
m_xmin->setUnit("s");
m_xmin->setScaleRange(0, 1);
m_xmax->setUnit("s");
m_xmax->setScaleRange(0, 1);
m_plotManager->setXUnit("s");

for(PlotComponent *plt : m_plotManager->plots()) {
Expand All @@ -205,7 +209,9 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent)
m_sampleRateSpin->setEnabled(true);

m_xmin->setUnit("s");
m_xmin->setScaleRange(0, 1);
m_xmax->setUnit("s");
m_xmax->setScaleRange(0, 1);
m_plotManager->setXUnit("s");
for(PlotComponent *plt : m_plotManager->plots()) {
auto p = dynamic_cast<TimePlotComponent *>(plt);
Expand Down

0 comments on commit 79d0c16

Please sign in to comment.