Skip to content

Commit

Permalink
Fix plot dialog crash when changing plot type.
Browse files Browse the repository at this point in the history
The problem was the fix with in commit
4c6aa2f. It caused an infinite recursion
on the plot dialog where the change signals are directly connected to
the plot updating. The signals are now not dispatched when the text
is interpreted for the value call. Refs #7084
  • Loading branch information
martyngigg committed May 14, 2013
1 parent fb30a48 commit 083aa0f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 2 additions & 6 deletions Code/Mantid/MantidPlot/src/lib/include/DoubleSpinBox.h
Expand Up @@ -56,11 +56,7 @@ class DoubleSpinBox : public QAbstractSpinBox
int decimals(){return d_prec;};
void setDecimals(int prec){if (prec >= 0) d_prec = prec;};

// MAG: Add back interpretText call for Mac 'fix'. The Mac spin boxes
// don't seem to lose focus in the same way the other platforms do
// so if value() is called when the box still has focus it returns
// the original and not the updated value.
double value(){ interpretText(); return d_value;};
double value();
bool setValue(double val);

void setFormat(const char format, int prec = 1){d_format = format; setDecimals(prec);};
Expand All @@ -74,7 +70,7 @@ class DoubleSpinBox : public QAbstractSpinBox
void activated(DoubleSpinBox *);

private slots:
void interpretText();
void interpretText(bool notify=true);

protected:
void stepBy ( int steps );
Expand Down
20 changes: 17 additions & 3 deletions Code/Mantid/MantidPlot/src/lib/src/DoubleSpinBox.cpp
Expand Up @@ -75,23 +75,30 @@ void DoubleSpinBox::setRange(double min, double max)
setMaximum(max);
}

void DoubleSpinBox::interpretText()
/**
* Interpret the text and update the stored value.
* @param notify If true then emit signals to indicate if the value has changed (default=true)
* The default is important so that connected signals ensure the correct updates are pushed
* through but we need to be able to turn them off as there are cases where this causes
* a recursive call.
*/
void DoubleSpinBox::interpretText(bool notify)
{
// RJT: Keep our version of this, which contains a bug fix (see [10521]).
// Also, there are lines referring to methods that don't exist in our (older) MyParser class.
bool ok = false;
double value = locale().toDouble(text(), &ok);
if (ok && setValue(value))
{
emit valueChanged(d_value);
if(notify) emit valueChanged(d_value);
}
else
{
QString val = text().remove(",");
value = locale().toDouble(val, &ok);
if ( ok && setValue(value) )
{
emit valueChanged(d_value);
if(notify) emit valueChanged(d_value);
}
else
{
Expand Down Expand Up @@ -150,6 +157,13 @@ QAbstractSpinBox::StepEnabled DoubleSpinBox::stepEnabled() const
return stepDown | stepUp;
}

double DoubleSpinBox::value()
{
const bool notify(false);
interpretText(notify);
return d_value;
}

bool DoubleSpinBox::setValue(double val)
{
if (val >= d_min_val && val <= d_max_val)
Expand Down

0 comments on commit 083aa0f

Please sign in to comment.