#ifndef QTMVVM_COREAPP_H #define QTMVVM_COREAPP_H #include #include #include class QCommandLineParser; #include "QtMvvmCore/qtmvvmcore_global.h" #include "QtMvvmCore/viewmodel.h" #include "QtMvvmCore/ipresenter.h" namespace QtMvvm { class CoreAppPrivate; class Q_MVVMCORE_EXPORT CoreApp : public QObject { Q_OBJECT public: explicit CoreApp(QObject *parent = nullptr); ~CoreApp(); static CoreApp *instance(); static void setMainPresenter(IPresenter *presenter); static void disableAutoBoot(); void registerApp(); public Q_SLOTS: void bootApp(); protected: virtual void performRegistrations(); virtual int startApp(const QStringList &arguments) = 0; virtual void closeApp(); bool autoParse(QCommandLineParser &parser, const QStringList &arguments); template inline void show(const QVariantHash ¶ms = {}) const; private: friend class QtMvvm::CoreAppPrivate; QScopedPointer d; }; template inline void CoreApp::show(const QVariantHash ¶ms) const { ViewModel::show(params); } } #define QTMVVM_REGISTER_CORE_APP(T) \ static void _setup_ ## T ## _hook() { \ auto app = new T(nullptr); \ app->registerApp(); \ } \ Q_COREAPP_STARTUP_FUNCTION(_setup_ ## T ## _hook) #define coreApp CoreApp::instance() #endif // QTMVVM_COREAPP_H