SettingsPresenter.hpp
1 #pragma once
2 #include <score/plugins/settingsdelegate/SettingsDelegatePresenter.hpp>
3 
4 #include <core/settings/SettingsView.hpp>
5 
6 #include <QObject>
7 
8 #include <vector>
9 
10 namespace score
11 {
12 class SettingsDelegateModel;
13 template <class Model>
14 class SettingsDelegatePresenter;
15 using GlobalSettingsPresenter = SettingsDelegatePresenter<SettingsDelegateModel>;
16 } // namespace score
17 
18 namespace score
19 {
20 class Settings;
21 
22 template <class Model>
23 class SettingsPresenter final : public QObject
24 {
25 public:
26  using Sv = SettingsView<Model>;
27  SettingsPresenter(Sv* view, QObject* parent)
28  : QObject{parent}
29  , m_view{view}
30  {
31  connect(m_view, &Sv::accepted, this, &SettingsPresenter::on_accept);
32  connect(m_view, &Sv::rejected, this, &SettingsPresenter::on_reject);
33  }
34 
35  void addSettingsPresenter(SettingsDelegatePresenter<Model>* presenter)
36  {
37  SCORE_ASSERT(ossia::find(m_pluginPresenters, presenter) == m_pluginPresenters.end());
38 
39  m_pluginPresenters.push_back(presenter);
40  }
41 
42 private:
43  void on_accept()
44  {
45  for(auto presenter : m_pluginPresenters)
46  {
47  presenter->on_accept();
48  }
49  }
50  void on_reject()
51  {
52  for(auto presenter : m_pluginPresenters)
53  {
54  presenter->on_reject();
55  }
56  }
57  Sv* m_view;
58 
59  std::vector<SettingsDelegatePresenter<Model>*> m_pluginPresenters;
60 };
61 }
Definition: SettingsDelegatePresenter.hpp:17
Definition: SettingsPresenter.hpp:24
Definition: SettingsView.hpp:21
Base toolkit upon which the software is built.
Definition: Application.cpp:90