MinimalApplication.hpp
1 #pragma once
2 
3 #include <core/application/ApplicationInterface.hpp>
4 #include <core/application/ApplicationSettings.hpp>
5 #include <core/presenter/Presenter.hpp>
6 #include <core/settings/Settings.hpp>
7 #include <core/view/Window.hpp>
8 
9 #include <QApplication>
10 
11 #include <clocale>
12 
13 #if defined(SCORE_STATIC_PLUGINS)
14 #include <score_static_plugins.hpp>
15 #endif
16 
17 namespace score
18 {
19 class MinimalApplication final
20  : public QObject
22 {
23 public:
24  int default_argc = 1;
25  const char* default_argv[2] = {"score", nullptr};
26 
28  : MinimalApplication{default_argc, (char**)default_argv}
29  {
30  }
31 
32  MinimalApplication(int& argc, char** argv)
33  : QObject{nullptr}
34  , m_app{new QApplication{argc, argv}}
35  {
36 #if defined(SCORE_STATIC_PLUGINS)
37  score_init_static_plugins();
38 #endif
39 
40  m_instance = this;
41  this->setParent(m_app);
42 
43  m_presenter
44  = new score::Presenter{m_applicationSettings, m_settings, m_pset, nullptr, this};
45 
46  GUIApplicationInterface::loadPluginData(m_settings, *m_presenter);
47  }
48 
49  ~MinimalApplication() override
50  {
51  this->setParent(nullptr);
52  delete m_presenter;
53 
54  QApplication::processEvents();
55  delete m_app;
56  }
57 
58  const score::GUIApplicationContext& context() const override
59  {
60  return m_presenter->applicationContext();
61  }
62 
63  const score::ApplicationComponents& components() const override
64  {
65  return context().components;
66  }
67 
68  score::ApplicationComponentsData& componentsData()
69  {
70  return m_presenter->components();
71  }
72 
73  int exec() { return m_app->exec(); }
74 
75  QApplication* m_app;
76  score::Settings m_settings;
78  score::Presenter* m_presenter{};
79  score::ApplicationSettings m_applicationSettings;
80 };
81 
83  : public QObject
85 {
86 public:
87  MinimalGUIApplication(int& argc, char** argv)
88  : QObject{nullptr}
89  , m_app{new QApplication{argc, argv}}
90  {
91 #if defined(SCORE_STATIC_PLUGINS)
92  score_init_static_plugins();
93 #endif
94 
95  m_instance = this;
96  this->setParent(m_app);
97 
98  m_view = new score::View{nullptr};
99  m_presenter
100  = new score::Presenter{m_applicationSettings, m_settings, m_pset, m_view, this};
101 
102  GUIApplicationInterface::loadPluginData(m_settings, *m_presenter);
103 
104  m_view->show();
105  }
106 
107  ~MinimalGUIApplication() override
108  {
109  this->setParent(nullptr);
110  delete m_presenter;
111 
112  QApplication::processEvents();
113  delete m_app;
114  }
115 
116  const score::GUIApplicationContext& context() const override
117  {
118  return m_presenter->applicationContext();
119  }
120 
121  const score::ApplicationComponents& components() const override
122  {
123  return context().components;
124  }
125 
126  score::ApplicationComponentsData& componentsData()
127  {
128  return m_presenter->components();
129  }
130 
131  score::View& view() const { return *m_view; }
132 
133  int exec() { return m_app->exec(); }
134 
135  QApplication* m_app{};
136  score::Settings m_settings;
137  score::ProjectSettings m_pset;
138  score::View* m_view{};
139  score::Presenter* m_presenter{};
140  score::ApplicationSettings m_applicationSettings;
141 };
142 }
Definition: ApplicationComponents.hpp:68
Definition: ApplicationInterface.hpp:39
void loadPluginData(score::Settings &settings, score::Presenter &presenter)
loadPluginData Utility method to load the minimal required data for plug-ins.
Definition: ApplicationInterface.cpp:77
Definition: MinimalApplication.hpp:22
Definition: MinimalApplication.hpp:85
The Presenter class.
Definition: lib/core/presenter/Presenter.hpp:36
Definition: lib/core/settings/Settings.hpp:70
Application-wide user settings registering and handling.
Definition: lib/core/settings/Settings.hpp:42
The main display of the application.
Definition: lib/core/view/Window.hpp:41
Base toolkit upon which the software is built.
Definition: Application.cpp:90
Definition: ApplicationComponents.hpp:46
Load-time settings.
Definition: ApplicationSettings.hpp:17
Specializes ApplicationContext with the QMainWindow.
Definition: GUIApplicationContext.hpp:15