SettingsDelegateView.hpp
1 #pragma once
2 #include <QWidget>
3 
4 #include <score_lib_base_export.h>
5 
6 class QComboBox;
7 class QCheckBox;
8 class QSpinBox;
9 class QDoubleSpinBox;
10 namespace score
11 {
12 class SettingsDelegateModel;
13 template <class Model>
14 class SettingsDelegatePresenter;
15 
16 template <class Model>
17 class SettingsDelegateView : public QObject
18 {
19 public:
21  using QObject::QObject;
22  ~SettingsDelegateView() = default;
23  virtual void setPresenter(Presenter* presenter) { m_presenter = presenter; }
24 
25  Presenter* getPresenter() { return m_presenter; }
26 
27  virtual QWidget* getWidget()
28  = 0; // QML? ownership transfer ? ? ? what about "this" case ?
29 
30 protected:
31  Presenter* m_presenter{};
32 };
34 }
35 
36 #define SETTINGS_UI_COMBOBOX_HPP(Control) \
37 public: \
38  void set##Control(QString); \
39  \
40 public: \
41  void Control##Changed(QString arg) W_SIGNAL(Control##Changed, arg); \
42  \
43 private: \
44  QComboBox* m_##Control{};
45 
46 #define SETTINGS_UI_NUM_COMBOBOX_HPP(Control) \
47 public: \
48  void set##Control(int); \
49  void Control##Changed(int arg) W_SIGNAL(Control##Changed, arg); \
50  \
51 private: \
52  QComboBox* m_##Control{};
53 
54 #define SETTINGS_UI_TOGGLE_HPP(Control) \
55 public: \
56  void set##Control(bool); \
57  void Control##Changed(bool arg) W_SIGNAL(Control##Changed, arg); \
58  \
59 private: \
60  QCheckBox* m_##Control{};
61 
62 #define SETTINGS_UI_SPINBOX_HPP(Control) \
63 public: \
64  void set##Control(int); \
65  void Control##Changed(int arg) W_SIGNAL(Control##Changed, arg); \
66  \
67 private: \
68  QSpinBox* m_##Control{};
69 
70 #define SETTINGS_UI_DOUBLE_SPINBOX_HPP(Control) \
71 public: \
72  void set##Control(double); \
73  void Control##Changed(double arg) W_SIGNAL(Control##Changed, arg); \
74  \
75 private: \
76  QDoubleSpinBox* m_##Control{};
77 
78 #define SETTINGS_UI_COMBOBOX_SETUP(Text, Control, Values) \
79  m_##Control = new QComboBox{m_widg}; \
80  m_##Control->addItems(Values); \
81  lay->addRow(tr(Text), m_##Control); \
82  connect( \
83  m_##Control, SignalUtils::QComboBox_currentIndexChanged_int(), this, \
84  [this](int i) { Control##Changed(m_##Control->itemText(i)); });
85 
86 #define SETTINGS_UI_NUM_COMBOBOX_SETUP(Text, Control, Values) \
87  m_##Control = new QComboBox{m_widg}; \
88  for(auto v : Values) \
89  m_##Control->addItem(QString::number(v)); \
90  lay->addRow(tr(Text), m_##Control); \
91  connect( \
92  m_##Control, SignalUtils::QComboBox_currentIndexChanged_int(), this, \
93  [this](int i) { Control##Changed(m_##Control->itemText(i).toInt()); });
94 
95 #define SETTINGS_UI_SPINBOX_SETUP(Text, Control) \
96  m_##Control = new QSpinBox{m_widg}; \
97  lay->addRow(tr(Text), m_##Control); \
98  connect( \
99  m_##Control, SignalUtils::QSpinBox_valueChanged_int(), this, \
100  &View::Control##Changed);
101 
102 #define SETTINGS_UI_DOUBLE_SPINBOX_SETUP(Text, Control) \
103  m_##Control = new QDoubleSpinBox{m_widg}; \
104  lay->addRow(tr(Text), m_##Control); \
105  connect( \
106  m_##Control, SignalUtils::QDoubleSpinBox_valueChanged_double(), this, \
107  &View::Control##Changed);
108 
109 #define SETTINGS_UI_TOGGLE_SETUP(Text, Control) \
110  m_##Control = new QCheckBox{tr(Text), m_widg}; \
111  lay->addRow(m_##Control); \
112  connect(m_##Control, &QCheckBox::toggled, this, &View::Control##Changed);
113 
114 #define SETTINGS_UI_COMBOBOX_IMPL(Control) \
115  void View::set##Control(QString val) \
116  { \
117  int idx = m_##Control->findData(QVariant::fromValue(val)); \
118  if(idx != -1 && idx != m_##Control->currentIndex()) \
119  m_##Control->setCurrentIndex(idx); \
120  else \
121  { \
122  idx = m_##Control->findText(val); \
123  if(idx != -1 && idx != m_##Control->currentIndex()) \
124  m_##Control->setCurrentIndex(idx); \
125  } \
126  }
127 
128 #define SETTINGS_UI_NUM_COMBOBOX_IMPL(Control) \
129  void View::set##Control(int val) \
130  { \
131  int idx = m_##Control->findData(QVariant::fromValue(val)); \
132  if(idx != -1 && idx != m_##Control->currentIndex()) \
133  m_##Control->setCurrentIndex(idx); \
134  else \
135  { \
136  idx = m_##Control->findText(QString::number(val)); \
137  if(idx != -1 && idx != m_##Control->currentIndex()) \
138  m_##Control->setCurrentIndex(idx); \
139  } \
140  }
141 
142 #define SETTINGS_UI_SPINBOX_IMPL(Control) \
143  void View::set##Control(int val) \
144  { \
145  int cur = m_##Control->value(); \
146  if(cur != val) \
147  m_##Control->setValue(val); \
148  }
149 
150 #define SETTINGS_UI_DOUBLE_SPINBOX_IMPL(Control) \
151  void View::set##Control(double val) \
152  { \
153  int cur = m_##Control->value(); \
154  if(cur != val) \
155  m_##Control->setValue(val); \
156  }
157 
158 #define SETTINGS_UI_TOGGLE_IMPL(Control) \
159  void View::set##Control(bool val) \
160  { \
161  bool cur = m_##Control->isChecked(); \
162  if(cur != val) \
163  m_##Control->setChecked(val); \
164  }
Definition: SettingsDelegatePresenter.hpp:17
Definition: SettingsDelegateView.hpp:18
Base toolkit upon which the software is built.
Definition: Application.cpp:90