Skip to content
Snippets Groups Projects
Commit b05c359b authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

[distribution_limits] GUI: Fix ScientificSpinBox limits (Closes #314)

Merging branch 'distribution_limits'  into 'main'.

See merge request !1047
parents 4dc5e717 439309c6
No related branches found
No related tags found
1 merge request!1047GUI: Fix ScientificSpinBox limits
Pipeline #75442 passed
...@@ -29,7 +29,7 @@ bool useExponentialNotation(double val); ...@@ -29,7 +29,7 @@ bool useExponentialNotation(double val);
} // namespace } // namespace
ScientificSpinBox::ScientificSpinBox(QWidget* parent) ScientificSpinBox::ScientificSpinBox(QWidget* parent)
: QDoubleSpinBox(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)
...@@ -46,21 +46,6 @@ ScientificSpinBox::ScientificSpinBox(QWidget* parent) ...@@ -46,21 +46,6 @@ ScientificSpinBox::ScientificSpinBox(QWidget* parent)
ScientificSpinBox::~ScientificSpinBox() = default; ScientificSpinBox::~ScientificSpinBox() = default;
QString ScientificSpinBox::textFromValue(double) const
{
return text();
}
QSize ScientificSpinBox::sizeHint() const
{
// The following is somehow a hack to get a reasonable sizeHint. Implementation could/should be
// re-thought
QDoubleSpinBox d;
d.setRange(m_min, m_max);
d.setDecimals(m_decimals);
return d.sizeHint();
}
double ScientificSpinBox::value() const double ScientificSpinBox::value() const
{ {
return m_value; return m_value;
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#ifndef BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H #ifndef BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H
#define BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H #define BORNAGAIN_GUI_VIEW_COMMON_SCIENTIFICSPINBOX_H
#include <QDoubleSpinBox> #include <QAbstractSpinBox>
class ScientificSpinBox : public QDoubleSpinBox { 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)
...@@ -25,9 +25,6 @@ public: ...@@ -25,9 +25,6 @@ public:
ScientificSpinBox(QWidget* parent = nullptr); ScientificSpinBox(QWidget* parent = nullptr);
~ScientificSpinBox() override; ~ScientificSpinBox() override;
QString textFromValue(double) const override;
QSize sizeHint() const override;
double value() const; double value() const;
void setValue(double val); void setValue(double val);
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "GUI/View/Tool/EditUtil.h" #include "GUI/View/Tool/EditUtil.h"
#include "Fit/Param/RealLimits.h" #include "Fit/Param/RealLimits.h"
#include "GUI/View/Common/ScientificSpinBox.h"
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QLineEdit> #include <QLineEdit>
#include <cmath> #include <cmath>
...@@ -58,3 +59,18 @@ void GUI::View::EditUtil::configSpinbox(QDoubleSpinBox* spinBox, int decimals, ...@@ -58,3 +59,18 @@ void GUI::View::EditUtil::configSpinbox(QDoubleSpinBox* spinBox, int decimals,
spinBox->setDecimals(decimals); spinBox->setDecimals(decimals);
spinBox->setSingleStep(singleStep(decimals)); spinBox->setSingleStep(singleStep(decimals));
} }
void GUI::View::EditUtil::configSpinbox(ScientificSpinBox* spinBox, int decimals,
const RealLimits& limits)
{
spinBox->setMaximum(std::numeric_limits<double>::max());
spinBox->setMinimum(std::numeric_limits<double>::lowest());
if (limits.hasLowerLimit())
spinBox->setMinimum(limits.lowerLimit());
if (limits.hasUpperLimit())
spinBox->setMaximum(limits.upperLimit());
spinBox->setDecimals(decimals);
spinBox->setSingleStep(singleStep(decimals));
}
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
class RealLimits; class RealLimits;
class QDoubleSpinBox; class QDoubleSpinBox;
class QLineEdit; class QLineEdit;
class ScientificSpinBox;
namespace GUI::View::EditUtil { namespace GUI::View::EditUtil {
void configScientificDoubleEdit(QLineEdit* edit, const RealLimits& limits); void configScientificDoubleEdit(QLineEdit* edit, const RealLimits& limits);
void configSpinbox(QDoubleSpinBox* spinBox, int decimals, const RealLimits& limits); void configSpinbox(QDoubleSpinBox* spinBox, int decimals, const RealLimits& limits);
void configSpinbox(ScientificSpinBox* spinBox, int decimals, const RealLimits& limits);
} // namespace GUI::View::EditUtil } // namespace GUI::View::EditUtil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment