From 01f3811390b5e5b3adbb281572b02518ec4734f0 Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Fri, 18 Feb 2022 12:19:29 +0100 Subject: [PATCH] docu; add convenience parameter --- GUI/View/Tool/WidgetUtils.cpp | 7 ++++++- GUI/View/Tool/WidgetUtils.h | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/GUI/View/Tool/WidgetUtils.cpp b/GUI/View/Tool/WidgetUtils.cpp index d52fcb7c603..77c3e2b4cd7 100644 --- a/GUI/View/Tool/WidgetUtils.cpp +++ b/GUI/View/Tool/WidgetUtils.cpp @@ -42,10 +42,15 @@ QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d, return spinBox; } -DoubleSpinBox* GUI::Util::createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d) +DoubleSpinBox* GUI::Util::createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d, + std::function<void(double)> slot) { auto* sb = new DoubleSpinBox(parentLayout->parentWidget(), d); parentLayout->addRow(labelWithUnit(d.label, d.unit) + ":", sb); + + if (slot) + QObject::connect(sb, &DoubleSpinBox::baseValueChanged, [=](int v) { slot(v); }); + return sb; } diff --git a/GUI/View/Tool/WidgetUtils.h b/GUI/View/Tool/WidgetUtils.h index 08e4c0b25cc..8526a374429 100644 --- a/GUI/View/Tool/WidgetUtils.h +++ b/GUI/View/Tool/WidgetUtils.h @@ -91,8 +91,10 @@ QSpinBox* createSpinBox(QFormLayout* parentLayout, const UIntDescriptor& d); //! //! No connections to update the descriptor will be established! Therefore changes in the spin box //! will *not* be notified to the descriptor. The additional (and optional) slot can be used to be -//! notified about a value change. -DoubleSpinBox* createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d); +//! notified about a value change (the notified new value is in the base unit of the +//! DoubleDescriptor). +DoubleSpinBox* createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d, + std::function<void(double)> slot = nullptr); //! Create a label with an optional unit in brackets. //! -- GitLab