SettingsDelegatePresenter.hpp
1 #pragma once
2 #include <score/command/Dispatchers/SettingsCommandDispatcher.hpp>
3 #include <score/tools/Bind.hpp>
4 
5 #include <QObject>
6 
7 #include <score_lib_base_export.h>
8 
9 namespace score
10 {
11 template <class Model>
12 class SettingsDelegateView;
13 class SettingsDelegateModel;
14 
15 template <class Model>
16 class SettingsDelegatePresenter : public QObject
17 {
18 public:
20  SettingsDelegatePresenter(Model& model, SView& view, QObject* parent)
21  : QObject{parent}
22  , m_model{model}
23  , m_view{view}
24  {
25  }
26 
27  virtual ~SettingsDelegatePresenter() = default;
28  virtual void on_accept() { m_disp.commit(); }
29 
30  virtual void on_reject() { m_disp.rollback(); }
31 
32  virtual QString settingsName() = 0;
33  virtual QIcon settingsIcon() = 0;
34 
35  template <typename T>
36  auto& model(T* self)
37  {
38  return static_cast<typename T::model_type&>(self->m_model);
39  }
40 
41  template <typename T>
42  auto& view(T* self)
43  {
44  return static_cast<typename T::view_type&>(self->m_view);
45  }
46 
47 protected:
48  Model& m_model;
49  SView& m_view;
50 
52 };
53 
56 }
57 
58 #define DEFERRED_SETTINGS_PRESENTER(Control) \
59  do \
60  { \
61  con(v, &View::Control##Changed, this, [&](auto val) { \
62  if(val != m.get##Control()) \
63  { \
64  m_disp.submitDeferredCommand<SetModel##Control>(this->model(this), val); \
65  } \
66  }); \
67  \
68  con(m, &Model::Control##Changed, &v, &View::set##Control); \
69  v.set##Control(m.get##Control()); \
70  } while(0)
71 
72 #define SETTINGS_PRESENTER(Control) \
73  do \
74  { \
75  con(v, &View::Control##Changed, this, [&](auto val) { \
76  if(val != m.get##Control()) \
77  { \
78  m_disp.submit<SetModel##Control>(this->model(this), val); \
79  } \
80  }); \
81  \
82  con(m, &Model::Control##Changed, &v, &View::set##Control); \
83  v.set##Control(m.get##Control()); \
84  } while(0)
Definition: SettingsCommandDispatcher.hpp:10
Definition: SettingsDelegatePresenter.hpp:17
Definition: SettingsDelegateView.hpp:18
Base toolkit upon which the software is built.
Definition: Application.cpp:90