Skip to content
Snippets Groups Projects
Commit 4f40fb28 authored by Matthias Puchner's avatar Matthias Puchner Committed by Wuttke, Joachim
Browse files

simplify, add documentation

parent 8199a116
No related branches found
No related tags found
1 merge request!706replace SessionItem signaling by Qt signaling in RealDataPropertiesWidget;...
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
class DoubleSpinBox : public QDoubleSpinBox { class DoubleSpinBox : public QDoubleSpinBox {
Q_OBJECT Q_OBJECT
public: public:
//! Create a DoubleSpinBox with the information found in a DoubleDescriptor.
//!
//! The spin box will be fully initialized (tooltip, limits, unit, current value, size policy).
//! 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
//! changes would take place when just scrolling through the form.
DoubleSpinBox(QWidget* parent, const DoubleDescriptor& d); DoubleSpinBox(QWidget* parent, const DoubleDescriptor& d);
//! Set a display unit. //! Set a display unit.
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
#include <QFormLayout> #include <QFormLayout>
#include <QSpinBox> #include <QSpinBox>
QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d) QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d,
std::function<void(uint)> slot)
{ {
auto* spinBox = new QSpinBox(parent); auto* spinBox = new QSpinBox(parent);
spinBox->setFocusPolicy(Qt::StrongFocus); spinBox->setFocusPolicy(Qt::StrongFocus);
...@@ -34,18 +35,11 @@ QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d) ...@@ -34,18 +35,11 @@ QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d)
spinBox->setValue(d.get()); spinBox->setValue(d.get());
return spinBox;
}
QSpinBox* GUI::Util::createSpinBox(QWidget* parent, const UIntDescriptor& d,
std::function<void(uint)> slot)
{
auto* sb = createSpinBox(parent, d);
if (slot) if (slot)
QObject::connect(sb, qOverload<int>(&QSpinBox::valueChanged), QObject::connect(spinBox, qOverload<int>(&QSpinBox::valueChanged),
[=](int v) { slot(static_cast<uint>(v)); }); [=](int v) { slot(static_cast<uint>(v)); });
return sb; return spinBox;
} }
DoubleSpinBox* GUI::Util::createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d) DoubleSpinBox* GUI::Util::createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d)
......
...@@ -29,9 +29,17 @@ class QFormLayout; ...@@ -29,9 +29,17 @@ class QFormLayout;
namespace GUI::Util { namespace GUI::Util {
// #bamigration docu //! Create a combo box with the information found in a selection descriptor.
//! Changes in the combobox will be notified to the SelectionDescriptor already. The addition slot //!
//! exists to be notified about an already executed change. //! The combo will be filled with the available options and will get the found tooltip.
//! The current index will be set according to the current index in the selection.
//! Furthermore, the combo box will prohibit accidental changes by the mouse wheel. Otherwise it
//! would be dangerous if the combo is on a scrollable form - unintended and unnoticed changes would
//! take place when just scrolling through the form.
//!
//! Changes in the combobox will be notified to the SelectionDescriptor already. The additional (and
//! optional) slot can be used to be notified about an already executed change.
//!
template <typename T> template <typename T>
QComboBox* createSelectionCombo(QWidget* parent, const SelectionDescriptor<T> d, QComboBox* createSelectionCombo(QWidget* parent, const SelectionDescriptor<T> d,
std::function<void(int)> slot = nullptr) std::function<void(int)> slot = nullptr)
...@@ -53,15 +61,42 @@ QComboBox* createSelectionCombo(QWidget* parent, const SelectionDescriptor<T> d, ...@@ -53,15 +61,42 @@ QComboBox* createSelectionCombo(QWidget* parent, const SelectionDescriptor<T> d,
return combo; return combo;
} }
// #bamigration docu //! Create a spin box with the information found in a UIntDescriptor.
QSpinBox* createSpinBox(QWidget* parent, const UIntDescriptor& d); //!
QSpinBox* createSpinBox(QWidget* parent, const UIntDescriptor& d, std::function<void(uint)> slot); //! The spin box will be fully initialized (tooltip, limits, current value, size policy).
//! 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 changes
//! would take place when just scrolling through the form.
//!
//! 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.
QSpinBox* createSpinBox(QWidget* parent, const UIntDescriptor& d,
std::function<void(uint)> slot = nullptr);
//! Create a label and a spin box with the information found in a UIntDescriptor and place them in a
//! row in a form layout.
//!
//! The label will also contain the unit, if present.
//! Regarding the spin box creation see the method above.
QSpinBox* createSpinBox(QFormLayout* parentLayout, const UIntDescriptor& d); QSpinBox* createSpinBox(QFormLayout* parentLayout, const UIntDescriptor& d);
//! Create a label and a spin box with the information found in a DoubleDescriptor and place them in
//! a row in a form layout.
//!
//! The spin box will be fully initialized (tooltip, limits, current value, unit, size policy).
//! 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 changes
//! would take place when just scrolling through the form.
//!
//! 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); DoubleSpinBox* createSpinBox(QFormLayout* parentLayout, const DoubleDescriptor& d);
//! No trailing ':' //! Create a label with an optional unit in brackets.
//!
//! No trailing ':' will be appended
QString labelWithUnit(const QString& label, std::variant<QString, Unit> unit); QString labelWithUnit(const QString& label, std::variant<QString, Unit> unit);
} // namespace GUI::Util } // namespace GUI::Util
......
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