QtMvvm  1.0.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
coreapp.h
Go to the documentation of this file.
1 #ifndef QTMVVM_COREAPP_H
2 #define QTMVVM_COREAPP_H
3 
4 #include <type_traits>
5 
6 #include <QtCore/qobject.h>
7 #include <QtCore/qscopedpointer.h>
8 #include <QtCore/qcoreapplication.h>
10 
11 #include "QtMvvmCore/qtmvvmcore_global.h"
12 #include "QtMvvmCore/viewmodel.h"
13 #include "QtMvvmCore/ipresenter.h"
14 #include "QtMvvmCore/message.h"
15 
16 namespace QtMvvm {
17 
18 class CoreAppPrivate;
20 class Q_MVVMCORE_EXPORT CoreApp : public QObject
21 {
22  Q_OBJECT
23 
24 public:
26  explicit CoreApp(QObject *parent = nullptr);
27  ~CoreApp();
28 
30  static CoreApp *instance();
32  static void disableAutoBoot();
33 
35  void registerApp();
36 
38  template <typename TViewModel>
39  static inline void show(const QVariantHash &params = {});
41  static void show(const char *viewModelName, const QVariantHash &params = {});
43  static void show(const QMetaObject *viewModelMetaObject, const QVariantHash &params = {});
44 
46  static MessageResult *showDialog(const MessageConfig &config);
47 
48 public Q_SLOTS:
50  void bootApp();
51 
52 Q_SIGNALS:
54  void appStarted(QPrivateSignal);
55 
56 protected:
58  virtual void performRegistrations();
60  virtual int startApp(const QStringList &arguments) = 0;
62  virtual void closeApp();
63 
65  bool autoParse(QCommandLineParser &parser, const QStringList &arguments);
66 
67 private:
68  friend class QtMvvm::CoreAppPrivate;
70 
71  static void showImp(const QMetaObject *metaObject, const QVariantHash &params);
72 };
73 
74 template<typename TViewModel>
75 inline void CoreApp::show(const QVariantHash &params)
76 {
77  static_assert(std::is_base_of<ViewModel, TViewModel>::value, "TViewModel must extend QtMvvm::ViewModel");
78  ViewModel::showImp(&TViewModel::staticMetaObject, params, nullptr);
79 }
80 
81 }
82 
84 #define QTMVVM_REGISTER_CORE_APP(T) \
85  static void _setup_ ## T ## _hook() { \
86  static_assert(std::is_base_of<QtMvvm::CoreApp, T>::value, "QTMVVM_REGISTER_CORE_APP must be used with a class that extends QtMvvm::CoreApp"); \
87  auto app = new T(nullptr); \
88  app->registerApp(); \
89  } \
90  Q_COREAPP_STARTUP_FUNCTION(_setup_ ## T ## _hook)
91 
93 #define coreApp QtMvvm::CoreApp::instance()
94 
96 #endif // QTMVVM_COREAPP_H
static void show(const QVariantHash &params={})
Show a new ViewModel by its type.
Definition: coreapp.h:75
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:18
A logicaly application object to drive the mvvm application from the core part.
Definition: coreapp.h:20
A result watcher to get the result once a dialog has finished.
Definition: message.h:172
The primary namespace of the QtMvvm library.
Definition: binding.h:10