Skip to content
Snippets Groups Projects
Commit d0b69864 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov Committed by Wuttke, Joachim
Browse files

Make instrument spinboxes safe (closes #476)

parent 9392c159
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ BornAgain-21.0, in preparation ...@@ -20,6 +20,7 @@ BornAgain-21.0, in preparation
> Bug fixes: > Bug fixes:
* Fix averaging magnetic materials (#76) * Fix averaging magnetic materials (#76)
* Repair polarization analysis in GUI (#190) * Repair polarization analysis in GUI (#190)
* Protect all spinboxes from accidental scrolling (#476)
* Repair specular intensity for polarized GISANS (#541) * Repair specular intensity for polarized GISANS (#541)
* Repair axis ticks display in linear scale in GUI (#575) * Repair axis ticks display in linear scale in GUI (#575)
* Prevent crash in QRE loader (#589) * Prevent crash in QRE loader (#589)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "GUI/View/Device/SphericalAxisForm.h" #include "GUI/View/Device/SphericalAxisForm.h"
#include "GUI/Model/Axis/BasicAxisItem.h" #include "GUI/Model/Axis/BasicAxisItem.h"
#include "GUI/View/Numeric/SafeSpinBox.h" #include "GUI/View/Numeric/SafeSpinBox.h"
#include "GUI/View/Numeric/ScientificSpinBox.h"
SphericalAxisForm::SphericalAxisForm(QFormLayout* form, QWidget* parent) SphericalAxisForm::SphericalAxisForm(QFormLayout* form, QWidget* parent)
: QObject(parent) : QObject(parent)
...@@ -26,19 +27,21 @@ SphericalAxisForm::SphericalAxisForm(QFormLayout* form, QWidget* parent) ...@@ -26,19 +27,21 @@ SphericalAxisForm::SphericalAxisForm(QFormLayout* form, QWidget* parent)
&SphericalAxisForm::onNbinsValueChanged); &SphericalAxisForm::onNbinsValueChanged);
form->addRow("# scan points:", m_nbinsSpinBox); form->addRow("# scan points:", m_nbinsSpinBox);
m_minimumSpinBox = new QDoubleSpinBox(parent); m_minimumSpinBox = new ScientificSpinBox(parent);
m_minimumSpinBox->setRange(0, 90); m_minimumSpinBox->setMinimum(0);
m_minimumSpinBox->setDecimals(3); m_minimumSpinBox->setMaximum(90);
m_minimumSpinBox->setDecimals(5);
m_minimumSpinBox->setSingleStep(0.01); m_minimumSpinBox->setSingleStep(0.01);
connect(m_minimumSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, connect(m_minimumSpinBox, &ScientificSpinBox::valueChanged, this,
&SphericalAxisForm::onMinimumValueChanged); &SphericalAxisForm::onMinimumValueChanged);
form->addRow("Initial angle [deg]:", m_minimumSpinBox); form->addRow("Initial angle [deg]:", m_minimumSpinBox);
m_maximumSpinBox = new QDoubleSpinBox(parent); m_maximumSpinBox = new ScientificSpinBox(parent);
m_maximumSpinBox->setRange(0, 90); m_maximumSpinBox->setMinimum(0);
m_maximumSpinBox->setDecimals(3); m_maximumSpinBox->setMaximum(90);
m_maximumSpinBox->setDecimals(5);
m_maximumSpinBox->setSingleStep(0.01); m_maximumSpinBox->setSingleStep(0.01);
connect(m_maximumSpinBox, qOverload<double>(&QDoubleSpinBox::valueChanged), this, connect(m_maximumSpinBox, &ScientificSpinBox::valueChanged, this,
&SphericalAxisForm::onMaximumValueChanged); &SphericalAxisForm::onMaximumValueChanged);
form->addRow("Final angle [deg]:", m_maximumSpinBox); form->addRow("Final angle [deg]:", m_maximumSpinBox);
} }
......
...@@ -15,12 +15,11 @@ ...@@ -15,12 +15,11 @@
#ifndef BORNAGAIN_GUI_VIEW_DEVICE_SPHERICALAXISFORM_H #ifndef BORNAGAIN_GUI_VIEW_DEVICE_SPHERICALAXISFORM_H
#define BORNAGAIN_GUI_VIEW_DEVICE_SPHERICALAXISFORM_H #define BORNAGAIN_GUI_VIEW_DEVICE_SPHERICALAXISFORM_H
#include <QDoubleSpinBox>
#include <QFormLayout> #include <QFormLayout>
#include <QWidget>
class BasicAxisItem; class BasicAxisItem;
class SafeSpinBox; class SafeSpinBox;
class ScientificSpinBox;
/// The form for a spherical axis: contains the bare bone widgets for the user to enter /// The form for a spherical axis: contains the bare bone widgets for the user to enter
/// the number of bins and to select the range in degrees (minimum & maximum) /// the number of bins and to select the range in degrees (minimum & maximum)
...@@ -46,8 +45,8 @@ private slots: ...@@ -46,8 +45,8 @@ private slots:
private: private:
SafeSpinBox* m_nbinsSpinBox; SafeSpinBox* m_nbinsSpinBox;
QDoubleSpinBox* m_minimumSpinBox; ScientificSpinBox* m_minimumSpinBox;
QDoubleSpinBox* m_maximumSpinBox; ScientificSpinBox* m_maximumSpinBox;
BasicAxisItem* m_axisItem; BasicAxisItem* m_axisItem;
}; };
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, QWidget* parent) DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, QWidget* parent)
: QDoubleSpinBox(parent) : QDoubleSpinBox(parent)
, m_valueProperty(d) , m_valueProperty(d)
, easyScrollable(easyScrollable) , m_easyScrollable(easyScrollable)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
GUI::View::NumberUtil::configSpinbox(this, d.decimals(), d.limits()); GUI::View::NumberUtil::configSpinbox(this, d.decimals(), d.limits());
...@@ -90,7 +90,7 @@ void DoubleSpinBox::setBaseValue(double baseValue) ...@@ -90,7 +90,7 @@ void DoubleSpinBox::setBaseValue(double baseValue)
void DoubleSpinBox::wheelEvent(QWheelEvent* event) void DoubleSpinBox::wheelEvent(QWheelEvent* event)
{ {
if (hasFocus() || easyScrollable) if (hasFocus() || m_easyScrollable)
QDoubleSpinBox::wheelEvent(event); QDoubleSpinBox::wheelEvent(event);
else else
event->ignore(); event->ignore();
......
...@@ -75,7 +75,7 @@ private: ...@@ -75,7 +75,7 @@ private:
Unit m_displayUnit = Unit::unitless; Unit m_displayUnit = Unit::unitless;
DoubleProperty& m_valueProperty; DoubleProperty& m_valueProperty;
bool easyScrollable; bool m_easyScrollable;
//! it was decided to not show the unit as a suffix. However, this may be user //! it was decided to not show the unit as a suffix. However, this may be user
//! selectable once, therefore the code is kept and controlled by this flag //! selectable once, therefore the code is kept and controlled by this flag
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "GUI/View/Numeric/ScientificSpinBox.h" #include "GUI/View/Numeric/ScientificSpinBox.h"
#include <QLineEdit> #include <QLineEdit>
#include <QRegularExpression> #include <QRegularExpression>
#include <QWheelEvent>
#include <cmath> #include <cmath>
namespace { namespace {
...@@ -28,13 +29,14 @@ bool useExponentialNotation(double val); ...@@ -28,13 +29,14 @@ bool useExponentialNotation(double val);
} // namespace } // namespace
ScientificSpinBox::ScientificSpinBox(QWidget* parent) ScientificSpinBox::ScientificSpinBox(QWidget* parent, bool easyScrollable)
: QAbstractSpinBox(parent) : QAbstractSpinBox(parent)
, m_value(0.0) , m_value(0.0)
, m_min(-max_val) , m_min(-max_val)
, m_max(max_val) , m_max(max_val)
, m_step(1.0) , m_step(1.0)
, m_decimals(3) , m_decimals(3)
, m_easyScrollable(easyScrollable)
{ {
QLocale locale; QLocale locale;
locale.setNumberOptions(QLocale::RejectGroupSeparator); locale.setNumberOptions(QLocale::RejectGroupSeparator);
...@@ -147,6 +149,14 @@ double ScientificSpinBox::round(double val, int decimals) ...@@ -147,6 +149,14 @@ double ScientificSpinBox::round(double val, int decimals)
return QString::number(val, 'e', decimals).toDouble(); return QString::number(val, 'e', decimals).toDouble();
} }
void ScientificSpinBox::wheelEvent(QWheelEvent* event)
{
if (hasFocus() || m_easyScrollable)
QAbstractSpinBox::wheelEvent(event);
else
event->ignore();
}
QAbstractSpinBox::StepEnabled ScientificSpinBox::stepEnabled() const QAbstractSpinBox::StepEnabled ScientificSpinBox::stepEnabled() const
{ {
return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled; return isReadOnly() ? StepNone : StepUpEnabled | StepDownEnabled;
......
...@@ -21,7 +21,7 @@ class ScientificSpinBox : public QAbstractSpinBox { ...@@ -21,7 +21,7 @@ class ScientificSpinBox : public QAbstractSpinBox {
Q_OBJECT Q_OBJECT
Q_PROPERTY(double value MEMBER m_value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(double value MEMBER m_value READ value WRITE setValue NOTIFY valueChanged USER true)
public: public:
ScientificSpinBox(QWidget* parent = nullptr); ScientificSpinBox(QWidget* parent = nullptr, bool easyScrollable = false);
~ScientificSpinBox() override; ~ScientificSpinBox() override;
double value() const; double value() const;
...@@ -48,6 +48,9 @@ public: ...@@ -48,6 +48,9 @@ public:
double default_value); double default_value);
static double round(double val, int decimals); static double round(double val, int decimals);
protected:
void wheelEvent(QWheelEvent* event) override;
signals: signals:
void valueChanged(double value); void valueChanged(double value);
...@@ -61,6 +64,7 @@ private: ...@@ -61,6 +64,7 @@ private:
double m_value, m_min, m_max; double m_value, m_min, m_max;
double m_step; double m_step;
int m_decimals; int m_decimals;
bool m_easyScrollable;
QDoubleValidator m_validator; QDoubleValidator m_validator;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment