Browse Source

bump version 1.1, add qml service registry class

pull/2/head
Skycoder42 7 years ago
parent
commit
de8ea82e95
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 4
      .qmake.conf
  2. 5
      src/imports/imports.pro
  3. 6
      src/imports/mvvmcore/mvvmcore.pro
  4. 38
      src/imports/mvvmcore/plugins.qmltypes
  5. 46
      src/imports/mvvmcore/qqmlserviceregistry.cpp
  6. 41
      src/imports/mvvmcore/qqmlserviceregistry.h
  7. 14
      src/imports/mvvmcore/qtmvvmcore_plugin.cpp
  8. 2
      src/imports/mvvmdatasynccore/plugins.qmltypes
  9. 5
      src/imports/mvvmdatasynccore/qtmvvmdatasynccore_plugin.cpp
  10. 2
      src/imports/mvvmdatasyncquick/plugins.qmltypes
  11. 6
      src/imports/mvvmdatasyncquick/qtmvvmdatasyncquick_plugin.cpp
  12. 2
      src/imports/mvvmquick/plugins.qmltypes
  13. 5
      src/imports/mvvmquick/qtmvvmquick_plugin.cpp
  14. 2
      src/mvvmcore/serviceregistry.h

4
.qmake.conf

@ -6,7 +6,7 @@ win32:cross_compile: CONFIG += winrt
DEFINES += QT_DEPRECATED_WARNINGS QT_ASCII_CAST_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS QT_ASCII_CAST_WARNINGS
MODULE_VERSION_MAJOR = 1 MODULE_VERSION_MAJOR = 1
MODULE_VERSION_MINOR = 0 MODULE_VERSION_MINOR = 1
MODULE_VERSION_PATCH = 2 MODULE_VERSION_PATCH = 0
MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR} MODULE_VERSION_IMPORT = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}
MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH} MODULE_VERSION = $${MODULE_VERSION_MAJOR}.$${MODULE_VERSION_MINOR}.$${MODULE_VERSION_PATCH}

5
src/imports/imports.pro

@ -4,7 +4,12 @@ SUBDIRS += \
mvvmcore \ mvvmcore \
mvvmquick mvvmquick
mvvmquick.depends += mvvmcore
qtHaveModule(datasync) { qtHaveModule(datasync) {
SUBDIRS += mvvmdatasynccore \ SUBDIRS += mvvmdatasynccore \
mvvmdatasyncquick mvvmdatasyncquick
mvvmdatasynccore.depends += mvvmcore
mvvmdatasyncquick.depends += mvvmdatasynccore mvvmquick
} }

6
src/imports/mvvmcore/mvvmcore.pro

@ -9,12 +9,14 @@ DEFINES += "VERSION_MINOR=$$MODULE_VERSION_MINOR"
HEADERS += \ HEADERS += \
qtmvvmcore_plugin.h \ qtmvvmcore_plugin.h \
qqmlmvvmbinding.h \ qqmlmvvmbinding.h \
qqmlmvvmmessage.h qqmlmvvmmessage.h \
qqmlserviceregistry.h
SOURCES += \ SOURCES += \
qtmvvmcore_plugin.cpp \ qtmvvmcore_plugin.cpp \
qqmlmvvmbinding.cpp \ qqmlmvvmbinding.cpp \
qqmlmvvmmessage.cpp qqmlmvvmmessage.cpp \
qqmlserviceregistry.cpp
OTHER_FILES += qmldir OTHER_FILES += qmldir

38
src/imports/mvvmcore/plugins.qmltypes

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only. // It is used for QML tooling purposes only.
// //
// This file was auto-generated by: // This file was auto-generated by:
// 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.Core 1.0' // 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.Core 1.1'
Module { Module {
dependencies: ["QtQml 2.2"] dependencies: ["QtQml 2.2"]
@ -429,6 +429,42 @@ Module {
Parameter { name: "onResult"; type: "QJSValue" } Parameter { name: "onResult"; type: "QJSValue" }
} }
} }
Component {
name: "QtMvvm::QQmlServiceRegistry"
prototype: "QObject"
exports: ["de.skycoder42.QtMvvm.Core/ServiceRegistry 1.1"]
isCreatable: false
isSingleton: true
exportMetaObjectRevisions: [0]
Enum {
name: "DestructionScope"
values: {
"DestroyOnAppQuit": 1,
"DestroyOnAppDestroy": 2,
"DestroyOnRegistryDestroy": 3,
"DestroyNever": 127
}
}
Method {
name: "isRegistered"
type: "bool"
Parameter { name: "iid"; type: "string" }
}
Method {
name: "registerObject"
Parameter { name: "componentUrl"; type: "QUrl" }
Parameter { name: "weak"; type: "bool" }
}
Method {
name: "registerObject"
Parameter { name: "componentUrl"; type: "QUrl" }
}
Method {
name: "service"
type: "QObject*"
Parameter { name: "iid"; type: "string" }
}
}
Component { Component {
name: "QtMvvm::SettingsViewModel" name: "QtMvvm::SettingsViewModel"
prototype: "QtMvvm::ViewModel" prototype: "QtMvvm::ViewModel"

46
src/imports/mvvmcore/qqmlserviceregistry.cpp

@ -0,0 +1,46 @@
#include "qqmlserviceregistry.h"
#include <QtQml/QQmlInfo>
using namespace QtMvvm;
QQmlServiceRegistry::QQmlServiceRegistry(QQmlEngine *parent) :
QObject{parent},
_engine{parent}
{}
bool QQmlServiceRegistry::isRegistered(const QString &iid) const
{
return ServiceRegistry::instance()->isRegistered(iid.toUtf8());
}
void QQmlServiceRegistry::registerObject(const QUrl &componentUrl, bool weak)
{
ServiceRegistry::instance()->registerService(componentUrl.toString().toUtf8(), [this, componentUrl](const QObjectList &) -> QObject* {
QQmlComponent component{_engine, componentUrl, QQmlComponent::PreferSynchronous};
switch(component.status()) {
case QQmlComponent::Ready:
{
auto object = component.create();
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
object->setParent(nullptr);
return object;
}
case QQmlComponent::Null:
throw ServiceConstructionException{"No component was loaded for URL: " +
component.url().toString().toUtf8()};
case QQmlComponent::Error:
throw ServiceConstructionException{"Failed to load componentfor URL \"" + component.url().toString().toUtf8() +
"\" with error: " + component.errorString().trimmed().toUtf8()};
case QQmlComponent::Loading:
throw ServiceConstructionException{"Unable to construct service from asynchronously loaded URL: " +
component.url().toString().toUtf8()};
default:
Q_UNREACHABLE();
return nullptr;
}
}, {}, weak, ServiceRegistry::DestroyOnAppQuit);
}
QObject *QQmlServiceRegistry::service(const QString &iid)
{
return ServiceRegistry::instance()->serviceObj(iid.toUtf8());
}

41
src/imports/mvvmcore/qqmlserviceregistry.h

@ -0,0 +1,41 @@
#ifndef QTMVVM_QQMLSERVICEREGISTRY_H
#define QTMVVM_QQMLSERVICEREGISTRY_H
#include <QtCore/QObject>
#include <QtMvvmCore/ServiceRegistry>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlComponent>
namespace QtMvvm {
class QQmlServiceRegistry : public QObject
{
Q_OBJECT
public:
enum DestructionScope {
DestroyOnAppQuit = ServiceRegistry::DestroyOnAppQuit,
DestroyOnAppDestroy = ServiceRegistry::DestroyOnAppDestroy,
DestroyOnRegistryDestroy = ServiceRegistry::DestroyOnRegistryDestroy,
DestroyNever = ServiceRegistry::DestroyNever
};
Q_ENUM(DestructionScope)
explicit QQmlServiceRegistry(QQmlEngine *parent = nullptr);
Q_INVOKABLE bool isRegistered(const QString &iid) const;
Q_INVOKABLE void registerObject(const QUrl &componentUrl, bool weak = false);
Q_INVOKABLE QObject *service(const QString &iid);
private:
QQmlEngine *_engine;
};
}
#endif // QTMVVM_QQMLSERVICEREGISTRY_H

14
src/imports/mvvmcore/qtmvvmcore_plugin.cpp

@ -8,10 +8,17 @@
#include "qqmlmvvmbinding.h" #include "qqmlmvvmbinding.h"
#include "qqmlmvvmmessage.h" #include "qqmlmvvmmessage.h"
#include "qqmlserviceregistry.h"
static QObject *createMessageSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine) static 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)
{
Q_UNUSED(jsEngine)
return new QtMvvm::QQmlServiceRegistry{qmlEngine};
} }
QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) : QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) :
@ -32,6 +39,9 @@ void QtMvvmCoreDeclarativeModule::registerTypes(const char *uri)
qmlRegisterSingletonType<QtMvvm::QQmlMvvmMessage>(uri, 1, 0, "Message", createMessageSingleton); qmlRegisterSingletonType<QtMvvm::QQmlMvvmMessage>(uri, 1, 0, "Message", createMessageSingleton);
//Version 1.1
qmlRegisterSingletonType<QtMvvm::QQmlServiceRegistry>(uri, 1, 1, "ServiceRegistry", createRegistrySingleton);
// 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 == 0, "QML module version needs to be updated"); static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");
} }

2
src/imports/mvvmdatasynccore/plugins.qmltypes

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only. // It is used for QML tooling purposes only.
// //
// This file was auto-generated by: // This file was auto-generated by:
// 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.DataSync.Core 1.0' // 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.DataSync.Core 1.1'
Module { Module {
dependencies: [ dependencies: [

5
src/imports/mvvmdatasynccore/qtmvvmdatasynccore_plugin.cpp

@ -31,6 +31,9 @@ void QtMvvmDataSyncCoreDeclarativeModule::registerTypes(const char *uri)
qmlRegisterUncreatableType<QtMvvm::ChangeRemoteViewModel>(uri, 1, 0, "PChangeRemoteViewModel", QStringLiteral("ViewModels cannot be created from QML")); qmlRegisterUncreatableType<QtMvvm::ChangeRemoteViewModel>(uri, 1, 0, "PChangeRemoteViewModel", QStringLiteral("ViewModels cannot be created from QML"));
qmlRegisterUncreatableType<QtMvvm::ExportSetupViewModel>(uri, 1, 0, "PExportSetupViewModel", QStringLiteral("ViewModels cannot be created from QML")); qmlRegisterUncreatableType<QtMvvm::ExportSetupViewModel>(uri, 1, 0, "PExportSetupViewModel", QStringLiteral("ViewModels cannot be created from QML"));
//Version 1.1
qmlRegisterModule(uri, 1, 1);
// 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 == 0, "QML module version needs to be updated"); static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");
} }

2
src/imports/mvvmdatasyncquick/plugins.qmltypes

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only. // It is used for QML tooling purposes only.
// //
// This file was auto-generated by: // This file was auto-generated by:
// 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.DataSync.Quick 1.0' // 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.DataSync.Quick 1.1'
Module { Module {
dependencies: [ dependencies: [

6
src/imports/mvvmdatasyncquick/qtmvvmdatasyncquick_plugin.cpp

@ -21,7 +21,11 @@ void QtMvvmDataSyncQuickDeclarativeModule::registerTypes(const char *uri)
//Version 1.0 //Version 1.0
//no c++ types. plugin is only needed for the resources //no c++ types. plugin is only needed for the resources
qmlRegisterModule(uri, 1, 0);
//Version 1.1
qmlRegisterModule(uri, 1, 1);
// 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 == 0, "QML module version needs to be updated"); static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");
} }

2
src/imports/mvvmquick/plugins.qmltypes

@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only. // It is used for QML tooling purposes only.
// //
// This file was auto-generated by: // This file was auto-generated by:
// 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.Quick 1.0' // 'qmlplugindump -nonrelocatable de.skycoder42.QtMvvm.Quick 1.1'
Module { Module {
dependencies: [ dependencies: [

5
src/imports/mvvmquick/qtmvvmquick_plugin.cpp

@ -48,6 +48,9 @@ void QtMvvmQuickDeclarativeModule::registerTypes(const char *uri)
qmlRegisterType(QUrl(QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/qml/FolderDialog.qml")), uri, 1, 0, "FolderDialog"); qmlRegisterType(QUrl(QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/qml/FolderDialog.qml")), uri, 1, 0, "FolderDialog");
#endif #endif
//Version 1.1
qmlRegisterModule(uri, 1, 1);
// 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 == 0, "QML module version needs to be updated"); static_assert(VERSION_MAJOR == 1 && VERSION_MINOR == 1, "QML module version needs to be updated");
} }

2
src/mvvmcore/serviceregistry.h

@ -14,7 +14,7 @@ namespace QtMvvm {
class ServiceRegistryPrivate; class ServiceRegistryPrivate;
//! A singleton to prepare services for dependency injection and to access them //! A singleton to prepare services for dependency injection and to access them
class Q_MVVMCORE_EXPORT ServiceRegistry class Q_MVVMCORE_EXPORT ServiceRegistry //MAJOR make a QObject for invokable methods and Q_ENUM
{ {
public: public:
enum DestructionScope { enum DestructionScope {

Loading…
Cancel
Save