20 #include <QFormLayout>
25 std::function<
void(uint)> slot)
27 auto* spinBox =
new QSpinBox(parent);
28 spinBox->setFocusPolicy(Qt::StrongFocus);
30 spinBox->setMaximum(std::numeric_limits<int>::max());
31 spinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
33 if (d.
limits.hasLowerLimit())
34 spinBox->setMinimum(
static_cast<int>(d.
limits.lowerLimit()));
35 if (d.
limits.hasUpperLimit())
36 spinBox->setMaximum(
static_cast<int>(d.
limits.upperLimit()));
38 spinBox->setValue(d.
get());
41 QObject::connect(spinBox, qOverload<int>(&QSpinBox::valueChanged),
42 [=](
int v) { slot(
static_cast<uint
>(v)); });
48 std::function<
void(
double)> slot)
50 auto* sb =
new DoubleSpinBox(parentLayout->parentWidget(), d);
68 const QString s = std::holds_alternative<QString>(unit) ? std::get<QString>(unit)
72 return label +
" [" + s +
"]";
84 std::function<
void(
double)> slot)
87 spinBox->setFocusPolicy(Qt::StrongFocus);
90 spinBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
91 spinBox->setValue(d.
get());
Defines class DoubleSpinBox.
Defines class GUIHelpers functions.
Defines class ScientificSpinBox.
Defines class UIntDescriptor.
QString unitAsString(const Unit &unit)
Returns the string for the given unit.
Unit
Defines units, mainly to be able to convert between units.
Describes properties of a double value which are necessary to allow GUI representation,...
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString label
A label text (short, no trailing colon)
RealLimits limits
Limits of the value.
function< double()> get
function to get the current value
QString tooltip
Tooltip text.
int decimals
numbers of decimals to be shown in an edit control
SpinBox for DoubleDescriptors, supporting units.
void baseValueChanged(double newBaseValue)
Emitted whenever the value changes.
void valueChanged(double value)
Describes properties of a uint value which are necessary to allow GUI representation,...
QString label
A label text (short, no trailing colon)
variant< QString, Unit > unit
Unit of the value (internal unit only!)
QString tooltip
Tooltip text.
RealLimits limits
Limits of the value.
function< uint()> get
function to get the current value
ScientificSpinBox * createScientificSpinBox(QFormLayout *parentLayout, const DoubleDescriptor &d, std::function< void(double)> slot=nullptr)
Create a label and a scientific spin box with the information found in a DoubleDescriptor and place t...
QSpinBox * createSpinBox(QWidget *parent, const UIntDescriptor &d, std::function< void(uint)> slot=nullptr)
Create a spin box with the information found in a UIntDescriptor.
QString labelWithUnit(const QString &label, std::variant< QString, Unit > unit)
Create a label with an optional unit in brackets.
void configSpinbox(QDoubleSpinBox *spinBox, int decimals, const RealLimits &limits)