diff --git a/src/imports/mvvmcore/mvvmcore.pro b/src/imports/mvvmcore/mvvmcore.pro index ce2109a..36e2f4a 100644 --- a/src/imports/mvvmcore/mvvmcore.pro +++ b/src/imports/mvvmcore/mvvmcore.pro @@ -10,13 +10,15 @@ HEADERS += \ qtmvvmcore_plugin.h \ qqmlmvvmbinding.h \ qqmlmvvmmessage.h \ - qqmlserviceregistry.h + qqmlserviceregistry.h \ + qqmlcoreapp.h SOURCES += \ qtmvvmcore_plugin.cpp \ qqmlmvvmbinding.cpp \ qqmlmvvmmessage.cpp \ - qqmlserviceregistry.cpp + qqmlserviceregistry.cpp \ + qqmlcoreapp.cpp OTHER_FILES += qmldir diff --git a/src/imports/mvvmcore/plugins.qmltypes b/src/imports/mvvmcore/plugins.qmltypes index c24845a..24e6eca 100644 --- a/src/imports/mvvmcore/plugins.qmltypes +++ b/src/imports/mvvmcore/plugins.qmltypes @@ -91,6 +91,35 @@ Module { Parameter { name: "result"; type: "QVariant" } } } + Component { + name: "QtMvvm::QQmlCoreApp" + prototype: "QObject" + exports: ["de.skycoder42.QtMvvm.Core/CoreApp 1.1"] + isCreatable: false + isSingleton: true + exportMetaObjectRevisions: [0] + Signal { name: "appStarted" } + Method { + name: "show" + Parameter { name: "viewModelName"; type: "string" } + Parameter { name: "params"; type: "QVariantHash" } + Parameter { name: "parentViewModel"; type: "QtMvvm::ViewModel"; isPointer: true } + } + Method { + name: "show" + Parameter { name: "viewModelName"; type: "string" } + Parameter { name: "params"; type: "QVariantHash" } + } + Method { + name: "show" + Parameter { name: "viewModelName"; type: "string" } + } + Method { + name: "showDialog" + type: "QtMvvm::MessageResult*" + Parameter { name: "config"; type: "QtMvvm::MessageConfig" } + } + } Component { name: "QtMvvm::QQmlMvvmBinding" prototype: "QObject" diff --git a/src/imports/mvvmcore/qqmlcoreapp.cpp b/src/imports/mvvmcore/qqmlcoreapp.cpp new file mode 100644 index 0000000..9f6acc8 --- /dev/null +++ b/src/imports/mvvmcore/qqmlcoreapp.cpp @@ -0,0 +1,19 @@ +#include "qqmlcoreapp.h" +using namespace QtMvvm; + +QQmlCoreApp::QQmlCoreApp(QObject *parent) : + QObject(parent) +{ + connect(coreApp, &CoreApp::appStarted, + this, &QQmlCoreApp::appStarted); +} + +MessageResult *QQmlCoreApp::showDialog(const MessageConfig &config) +{ + return CoreApp::showDialog(config); +} + +void QQmlCoreApp::show(const QString &viewModelName, const QVariantHash ¶ms, ViewModel *parentViewModel) +{ + CoreApp::show(qUtf8Printable(viewModelName), params, parentViewModel); +} diff --git a/src/imports/mvvmcore/qqmlcoreapp.h b/src/imports/mvvmcore/qqmlcoreapp.h new file mode 100644 index 0000000..966efa0 --- /dev/null +++ b/src/imports/mvvmcore/qqmlcoreapp.h @@ -0,0 +1,28 @@ +#ifndef QTMVVM_QQMLCOREAPP_H +#define QTMVVM_QQMLCOREAPP_H + +#include + +#include + +namespace QtMvvm { + +class QQmlCoreApp : public QObject +{ + Q_OBJECT + +public: + explicit QQmlCoreApp(QObject *parent = nullptr); + + Q_INVOKABLE QtMvvm::MessageResult *showDialog(const QtMvvm::MessageConfig &config); + +public Q_SLOTS: + void show(const QString &viewModelName, const QVariantHash ¶ms = {}, QtMvvm::ViewModel *parentViewModel = nullptr); + +Q_SIGNALS: + void appStarted(); +}; + +} + +#endif // QTMVVM_QQMLCOREAPP_H diff --git a/src/imports/mvvmcore/qtmvvmcore_plugin.cpp b/src/imports/mvvmcore/qtmvvmcore_plugin.cpp index 6043f01..2953667 100644 --- a/src/imports/mvvmcore/qtmvvmcore_plugin.cpp +++ b/src/imports/mvvmcore/qtmvvmcore_plugin.cpp @@ -9,18 +9,29 @@ #include "qqmlmvvmbinding.h" #include "qqmlmvvmmessage.h" #include "qqmlserviceregistry.h" +#include "qqmlcoreapp.h" -static QObject *createMessageSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) +namespace { + +QObject *createMessageSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { return new QtMvvm::QQmlMvvmMessage{jsEngine, qmlEngine}; } -static QObject *createRegistrySingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) +QObject *createRegistrySingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) { Q_UNUSED(jsEngine) return new QtMvvm::QQmlServiceRegistry{qmlEngine}; } +QObject *createCoreAppSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) +{ + Q_UNUSED(jsEngine) + return new QtMvvm::QQmlCoreApp{qmlEngine}; +} + +} + QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) : QQmlExtensionPlugin(parent) {} @@ -41,6 +52,7 @@ void QtMvvmCoreDeclarativeModule::registerTypes(const char *uri) //Version 1.1 qmlRegisterSingletonType(uri, 1, 1, "ServiceRegistry", createRegistrySingleton); + qmlRegisterSingletonType(uri, 1, 1, "CoreApp", createCoreAppSingleton); // Check to make shure no module update is forgotten static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");