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

DoubleSpinbox: decimals and step fix

parent a36dc8f4
No related branches found
No related tags found
1 merge request!1179GUI: DoubleSpinbox format fix
...@@ -54,7 +54,7 @@ void XYZRotationItem::serialize(Streamer& s) ...@@ -54,7 +54,7 @@ void XYZRotationItem::serialize(Streamer& s)
XRotationItem::XRotationItem() XRotationItem::XRotationItem()
{ {
m_angle.init("Angle", "Rotation angle around x-axis", 0.0, Unit::degree, "angle"); m_angle.init("Angle", "Rotation angle around x-axis", 0.0, Unit::degree, 2 /*decimals*/, 1.0 /*step*/, RealLimits::limitless(), "angle");
} }
unique_ptr<IRotation> XRotationItem::createRotation() const unique_ptr<IRotation> XRotationItem::createRotation() const
......
...@@ -16,12 +16,10 @@ ...@@ -16,12 +16,10 @@
#include "GUI/View/Tool/EditUtil.h" #include "GUI/View/Tool/EditUtil.h"
#include <QWheelEvent> #include <QWheelEvent>
DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, int precision, double stepSize, DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, QWidget* parent)
QWidget* parent)
: QDoubleSpinBox(parent) : QDoubleSpinBox(parent)
, m_valueProperty(d) , m_valueProperty(d)
, easyScrollable(easyScrollable) , easyScrollable(easyScrollable)
, m_precision(precision)
{ {
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
GUI::View::EditUtil::configSpinbox(this, d.decimals(), d.limits()); GUI::View::EditUtil::configSpinbox(this, d.decimals(), d.limits());
...@@ -35,7 +33,7 @@ DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, int precisi ...@@ -35,7 +33,7 @@ DoubleSpinBox::DoubleSpinBox(DoubleProperty& d, bool easyScrollable, int precisi
QObject::connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, QObject::connect(this, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this,
&DoubleSpinBox::onDisplayValueChanged); &DoubleSpinBox::onDisplayValueChanged);
setSingleStep(stepSize); setSingleStep(m_valueProperty.step());
} }
void DoubleSpinBox::setDisplayUnit(Unit displayUnit) void DoubleSpinBox::setDisplayUnit(Unit displayUnit)
{ {
...@@ -116,8 +114,3 @@ void DoubleSpinBox::updateValue() ...@@ -116,8 +114,3 @@ void DoubleSpinBox::updateValue()
QSignalBlocker b(this); QSignalBlocker b(this);
setBaseValue(m_valueProperty.value()); setBaseValue(m_valueProperty.value());
} }
QString DoubleSpinBox::textFromValue(double val) const
{
return QString::number(val, 'f', m_precision);
}
...@@ -27,8 +27,7 @@ public: ...@@ -27,8 +27,7 @@ public:
//! Furthermore, the spin box will prohibit accidental changes by the mouse wheel. Otherwise it //! Furthermore, the spin box will prohibit accidental changes by the mouse wheel. Otherwise it
//! would be dangerous if the spin box is on a scrollable form - unintended and unnoticed //! would be dangerous if the spin box is on a scrollable form - unintended and unnoticed
//! changes would take place when just scrolling through the form. //! changes would take place when just scrolling through the form.
DoubleSpinBox(DoubleProperty& d, bool easyScrollable = false, int precision = 2, DoubleSpinBox(DoubleProperty& d, bool easyScrollable = false, QWidget* parent = nullptr);
double singleStepSize = 0.1, QWidget* parent = nullptr);
//! Set a display unit. //! Set a display unit.
//! //!
//! The caller has to make sure that the new display unit has a conversion to/from the contained //! The caller has to make sure that the new display unit has a conversion to/from the contained
...@@ -81,14 +80,6 @@ private: ...@@ -81,14 +80,6 @@ private:
//! 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
bool m_showUnitAsSuffix = false; bool m_showUnitAsSuffix = false;
//! stores the decimal places used for displaying the value. A user can still
//! type more decimal places, these places will get rounded up to the places allowed.
const int m_precision;
// QDoubleSpinBox interface
public:
QString textFromValue(double val) const override;
}; };
......
...@@ -84,12 +84,7 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir ...@@ -84,12 +84,7 @@ void LayerEditorUtils::addMultiPropertyToGrid(QGridLayout* m_gridLayout, int fir
{ {
int col = firstCol; int col = firstCol;
for (auto* d : valueProperties) { for (auto* d : valueProperties) {
DoubleSpinBox* editor; DoubleSpinBox* editor = new DoubleSpinBox(*d);
if (d->label() == "Angle")
editor = new DoubleSpinBox(*d, false, 1, 1.0);
else
editor = new DoubleSpinBox(*d);
QObject::connect(editor, &DoubleSpinBox::baseValueChanged, QObject::connect(editor, &DoubleSpinBox::baseValueChanged,
[setNewValue, d](double newValue) { setNewValue(newValue, *d); }); [setNewValue, d](double newValue) { setNewValue(newValue, *d); });
......
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