CommandSpinBox.hpp
1 #pragma once
2 #include <score/command/Dispatchers/SingleOngoingCommandDispatcher.hpp>
3 #include <score/widgets/SignalUtils.hpp>
4 
5 #include <QObject>
6 namespace score
7 {
12 template <typename Property, typename Command, typename SpinBox>
13 struct CommandSpinbox : public QObject
14 {
15  using model_type = typename Property::model_type;
17  const model_type& model, const score::CommandStackFacade& stck, QWidget* parent)
18  : m_sb{new SpinBox{parent}}
19  , m_slotDisp{stck}
20  {
21  m_sb->setMinimum(20);
22  m_sb->setMaximum(20000);
23 
24  connect(m_sb, SignalUtils::SpinBox_valueChanged<SpinBox>(), this, [&](int h) {
25  if(h != (model.*Property::get())())
26  {
27  m_slotDisp.submit(model, h);
28  }
29  });
30  connect(m_sb, &SpinBox::editingFinished, this, [=] { m_slotDisp.commit(); });
31 
32  con(model, Property::notify(), this, [=](auto val) {
33  if(val != m_sb->value())
34  {
35  m_sb->setValue(val);
36  }
37  });
38 
39  m_sb->setValue((model.*Property::get())());
40  }
41 
42  auto widget() const { return m_sb; }
43 
44 private:
45  SpinBox* m_sb{};
47 };
48 }
The SingleOngoingCommandDispatcher class.
Definition: SingleOngoingCommandDispatcher.hpp:17
A small abstraction layer over the score::CommandStack.
Definition: CommandStackFacade.hpp:20
The SpinBox class.
Definition: SpinBoxes.hpp:68
Base toolkit upon which the software is built.
Definition: Application.cpp:90
CommandSpinbox Will update a value of the model according to the spinbox.
Definition: CommandSpinBox.hpp:14