Browse Source

added CoreApp qml singleton

pull/2/head
Skycoder42 7 years ago
parent
commit
0e85e6f770
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 6
      src/imports/mvvmcore/mvvmcore.pro
  2. 29
      src/imports/mvvmcore/plugins.qmltypes
  3. 19
      src/imports/mvvmcore/qqmlcoreapp.cpp
  4. 28
      src/imports/mvvmcore/qqmlcoreapp.h
  5. 16
      src/imports/mvvmcore/qtmvvmcore_plugin.cpp

6
src/imports/mvvmcore/mvvmcore.pro

@ -10,13 +10,15 @@ HEADERS += \
qtmvvmcore_plugin.h \ qtmvvmcore_plugin.h \
qqmlmvvmbinding.h \ qqmlmvvmbinding.h \
qqmlmvvmmessage.h \ qqmlmvvmmessage.h \
qqmlserviceregistry.h qqmlserviceregistry.h \
qqmlcoreapp.h
SOURCES += \ SOURCES += \
qtmvvmcore_plugin.cpp \ qtmvvmcore_plugin.cpp \
qqmlmvvmbinding.cpp \ qqmlmvvmbinding.cpp \
qqmlmvvmmessage.cpp \ qqmlmvvmmessage.cpp \
qqmlserviceregistry.cpp qqmlserviceregistry.cpp \
qqmlcoreapp.cpp
OTHER_FILES += qmldir OTHER_FILES += qmldir

29
src/imports/mvvmcore/plugins.qmltypes

@ -91,6 +91,35 @@ Module {
Parameter { name: "result"; type: "QVariant" } 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 { Component {
name: "QtMvvm::QQmlMvvmBinding" name: "QtMvvm::QQmlMvvmBinding"
prototype: "QObject" prototype: "QObject"

19
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 &params, ViewModel *parentViewModel)
{
CoreApp::show(qUtf8Printable(viewModelName), params, parentViewModel);
}

28
src/imports/mvvmcore/qqmlcoreapp.h

@ -0,0 +1,28 @@
#ifndef QTMVVM_QQMLCOREAPP_H
#define QTMVVM_QQMLCOREAPP_H
#include <QtCore/QObject>
#include <QtMvvmCore/CoreApp>
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 &params = {}, QtMvvm::ViewModel *parentViewModel = nullptr);
Q_SIGNALS:
void appStarted();
};
}
#endif // QTMVVM_QQMLCOREAPP_H

16
src/imports/mvvmcore/qtmvvmcore_plugin.cpp

@ -9,18 +9,29 @@
#include "qqmlmvvmbinding.h" #include "qqmlmvvmbinding.h"
#include "qqmlmvvmmessage.h" #include "qqmlmvvmmessage.h"
#include "qqmlserviceregistry.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}; return new QtMvvm::QQmlMvvmMessage{jsEngine, qmlEngine};
} }
static QObject *createRegistrySingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) QObject *createRegistrySingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{ {
Q_UNUSED(jsEngine) Q_UNUSED(jsEngine)
return new QtMvvm::QQmlServiceRegistry{qmlEngine}; return new QtMvvm::QQmlServiceRegistry{qmlEngine};
} }
QObject *createCoreAppSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
Q_UNUSED(jsEngine)
return new QtMvvm::QQmlCoreApp{qmlEngine};
}
}
QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) : QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) :
QQmlExtensionPlugin(parent) QQmlExtensionPlugin(parent)
{} {}
@ -41,6 +52,7 @@ void QtMvvmCoreDeclarativeModule::registerTypes(const char *uri)
//Version 1.1 //Version 1.1
qmlRegisterSingletonType<QtMvvm::QQmlServiceRegistry>(uri, 1, 1, "ServiceRegistry", createRegistrySingleton); qmlRegisterSingletonType<QtMvvm::QQmlServiceRegistry>(uri, 1, 1, "ServiceRegistry", createRegistrySingleton);
qmlRegisterSingletonType<QtMvvm::QQmlCoreApp>(uri, 1, 1, "CoreApp", createCoreAppSingleton);
// Check to make shure no module update is forgotten // Check to make shure no module update is forgotten
static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated"); static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");

Loading…
Cancel
Save