Browse Source

implemented core message qml bindings

pull/2/head
Skycoder42 7 years ago
parent
commit
081ce57f8d
  1. 6
      examples/mvvmquick/SampleQuick/main.qml
  2. 6
      src/imports/mvvmcore/mvvmcore.pro
  3. 282
      src/imports/mvvmcore/plugins.qmltypes
  4. 107
      src/imports/mvvmcore/qqmlmvvmmessage.cpp
  5. 81
      src/imports/mvvmcore/qqmlmvvmmessage.h
  6. 7
      src/imports/mvvmcore/qtmvvmcore_plugin.cpp
  7. 2
      src/imports/mvvmcore/qtmvvmcore_plugin.h
  8. 2
      src/imports/mvvmquick/qtmvvmquick_plugin.h
  9. 4
      src/mvvmquick/quickpresenter.cpp

6
examples/mvvmquick/SampleQuick/main.qml

@ -3,9 +3,5 @@ import de.skycoder42.qtmvvm.core 1.0
import de.skycoder42.qtmvvm.quick 1.0 import de.skycoder42.qtmvvm.quick 1.0
App { App {
title: qsTr("Hello World") title: qsTr("QtMvvm Quick Sample")
QtMvvmBinding {
id: binding
}
} }

6
src/imports/mvvmcore/mvvmcore.pro

@ -6,11 +6,13 @@ IMPORT_VERSION = 1.0
HEADERS += \ HEADERS += \
qtmvvmcore_plugin.h \ qtmvvmcore_plugin.h \
qqmlmvvmbinding.h qqmlmvvmbinding.h \
qqmlmvvmmessage.h
SOURCES += \ SOURCES += \
qtmvvmcore_plugin.cpp \ qtmvvmcore_plugin.cpp \
qqmlmvvmbinding.cpp qqmlmvvmbinding.cpp \
qqmlmvvmmessage.cpp
OTHER_FILES += qmldir OTHER_FILES += qmldir

282
src/imports/mvvmcore/plugins.qmltypes

@ -54,4 +54,286 @@ Module {
Method { name: "unbind" } Method { name: "unbind" }
Method { name: "isValid"; type: "bool" } Method { name: "isValid"; type: "bool" }
} }
Component {
name: "QtMvvm::QQmlMvvmMessage"
prototype: "QObject"
exports: ["de.skycoder42.qtmvvm.core/QtMvvmMessage 1.0"]
isCreatable: false
isSingleton: true
exportMetaObjectRevisions: [0]
Method {
name: "information"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "okText"; type: "string" }
}
Method {
name: "information"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "information"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
}
Method {
name: "question"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "yesText"; type: "string" }
Parameter { name: "noText"; type: "string" }
}
Method {
name: "question"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "yesText"; type: "string" }
}
Method {
name: "question"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "question"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
}
Method {
name: "warning"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "okText"; type: "string" }
}
Method {
name: "warning"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "warning"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
}
Method {
name: "critical"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "okText"; type: "string" }
}
Method {
name: "critical"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "critical"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
Parameter { name: "licenseUrl"; type: "QUrl" }
Parameter { name: "companyName"; type: "string" }
Parameter { name: "addQtVersion"; type: "bool" }
Parameter { name: "extraTopInfos"; type: "QStringList" }
Parameter { name: "extraBottomInfos"; type: "string" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
Parameter { name: "licenseUrl"; type: "QUrl" }
Parameter { name: "companyName"; type: "string" }
Parameter { name: "addQtVersion"; type: "bool" }
Parameter { name: "extraTopInfos"; type: "QStringList" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
Parameter { name: "licenseUrl"; type: "QUrl" }
Parameter { name: "companyName"; type: "string" }
Parameter { name: "addQtVersion"; type: "bool" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
Parameter { name: "licenseUrl"; type: "QUrl" }
Parameter { name: "companyName"; type: "string" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
Parameter { name: "licenseUrl"; type: "QUrl" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
Parameter { name: "licenseName"; type: "string" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
Parameter { name: "websiteUrl"; type: "QUrl" }
}
Method {
name: "about"
Parameter { name: "description"; type: "string" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "defaultValue"; type: "QVariant" }
Parameter { name: "viewProperties"; type: "QVariantMap" }
Parameter { name: "okText"; type: "string" }
Parameter { name: "cancelText"; type: "string" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "defaultValue"; type: "QVariant" }
Parameter { name: "viewProperties"; type: "QVariantMap" }
Parameter { name: "okText"; type: "string" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "defaultValue"; type: "QVariant" }
Parameter { name: "viewProperties"; type: "QVariantMap" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "defaultValue"; type: "QVariant" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "getInput"
Parameter { name: "title"; type: "string" }
Parameter { name: "text"; type: "string" }
Parameter { name: "inputType"; type: "const char"; isPointer: true }
}
Method {
name: "getExistingDirectory"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "dir"; type: "QUrl" }
}
Method {
name: "getExistingDirectory"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
}
Method {
name: "getExistingDirectory"
Parameter { name: "onResult"; type: "QJSValue" }
}
Method { name: "getExistingDirectory" }
Method {
name: "getOpenFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
Parameter { name: "dir"; type: "QUrl" }
}
Method {
name: "getOpenFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
}
Method {
name: "getOpenFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
}
Method {
name: "getOpenFile"
Parameter { name: "onResult"; type: "QJSValue" }
}
Method { name: "getOpenFile" }
Method {
name: "getOpenFiles"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
Parameter { name: "dir"; type: "QUrl" }
}
Method {
name: "getOpenFiles"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
}
Method {
name: "getOpenFiles"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
}
Method {
name: "getOpenFiles"
Parameter { name: "onResult"; type: "QJSValue" }
}
Method {
name: "getSaveFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
Parameter { name: "dir"; type: "QUrl" }
}
Method {
name: "getSaveFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
Parameter { name: "supportedMimeTypes"; type: "QStringList" }
}
Method {
name: "getSaveFile"
Parameter { name: "onResult"; type: "QJSValue" }
Parameter { name: "title"; type: "string" }
}
Method {
name: "getSaveFile"
Parameter { name: "onResult"; type: "QJSValue" }
}
}
} }

107
src/imports/mvvmcore/qqmlmvvmmessage.cpp

@ -0,0 +1,107 @@
#include "qqmlmvvmmessage.h"
using namespace QtMvvm;
QQmlMvvmMessage::QQmlMvvmMessage(QJSEngine *engine, QObject *parent) :
QObject(parent),
_engine(engine)
{}
void QQmlMvvmMessage::information(const QString &title, const QString &text, const QJSValue &onResult, const QString &okText)
{
if(onResult.isCallable()) {
QtMvvm::information(title, text, this, [onResult](){
QJSValue(onResult).call();
}, okText);
} else
QtMvvm::information(title, text, okText);
}
void QQmlMvvmMessage::question(const QString &title, const QString &text, const QJSValue &onResult, const QString &yesText, const QString &noText)
{
if(onResult.isCallable()) {
QtMvvm::question(title, text, this, [onResult](bool res){
QJSValue(onResult).call({res});
}, yesText, noText);
} else
QtMvvm::question(title, text, yesText, noText);
}
void QQmlMvvmMessage::warning(const QString &title, const QString &text, const QJSValue &onResult, const QString &okText)
{
if(onResult.isCallable()) {
QtMvvm::warning(title, text, this, [onResult](){
QJSValue(onResult).call();
}, okText);
} else
QtMvvm::warning(title, text, okText);
}
void QQmlMvvmMessage::critical(const QString &title, const QString &text, const QJSValue &onResult, const QString &okText)
{
if(onResult.isCallable()) {
QtMvvm::critical(title, text, this, [onResult](){
QJSValue(onResult).call();
}, okText);
} else
QtMvvm::critical(title, text, okText);
}
void QQmlMvvmMessage::about(const QString &description, const QUrl &websiteUrl, const QString &licenseName, const QUrl &licenseUrl, const QString &companyName, bool addQtVersion, const QStringList &extraTopInfos, const QString &extraBottomInfos)
{
QtMvvm::about(description, websiteUrl, licenseName, licenseUrl, companyName, addQtVersion, extraTopInfos, extraBottomInfos);
}
void QQmlMvvmMessage::getInput(const QString &title, const QString &text, const char *inputType, const QJSValue &onResult, const QVariant &defaultValue, const QVariantMap &viewProperties, const QString &okText, const QString &cancelText)
{
if(onResult.isCallable()) {
auto engine = _engine;
QtMvvm::getInput(title, text, inputType, this, [engine, onResult](QVariant result){
QJSValue(onResult).call({engine->toScriptValue(result)});
}, defaultValue, viewProperties, okText, cancelText);
} else
QtMvvm::getInput(title, text, inputType, defaultValue, viewProperties, okText, cancelText);
}
void QQmlMvvmMessage::getExistingDirectory(const QJSValue &onResult, const QString &title, const QUrl &dir)
{
if(onResult.isCallable()) {
auto engine = _engine;
QtMvvm::getExistingDirectory(this, [engine, onResult](QUrl url){
QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, dir);
} else
QtMvvm::getExistingDirectory(title, dir);
}
void QQmlMvvmMessage::getOpenFile(const QJSValue &onResult, const QString &title, const QStringList &supportedMimeTypes, const QUrl &dir)
{
if(onResult.isCallable()) {
auto engine = _engine;
QtMvvm::getOpenFile(this, [engine, onResult](QUrl url){
QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir);
} else
QtMvvm::getOpenFile(title, supportedMimeTypes, dir);
}
void QQmlMvvmMessage::getOpenFiles(const QJSValue &onResult, const QString &title, const QStringList &supportedMimeTypes, const QUrl &dir)
{
if(onResult.isCallable()) {
auto engine = _engine;
QtMvvm::getOpenFiles(this, [engine, onResult](QList<QUrl> url){
QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir);
} else
QtMvvm::getOpenFiles(title, supportedMimeTypes, dir);
}
void QQmlMvvmMessage::getSaveFile(const QJSValue &onResult, const QString &title, const QStringList &supportedMimeTypes, const QUrl &dir)
{
if(onResult.isCallable()) {
auto engine = _engine;
QtMvvm::getSaveFile(this, [engine, onResult](QUrl url){
QJSValue(onResult).call({engine->toScriptValue(url)});
}, title, supportedMimeTypes, dir);
} else
QtMvvm::getSaveFile(title, supportedMimeTypes, dir);
}

81
src/imports/mvvmcore/qqmlmvvmmessage.h

@ -0,0 +1,81 @@
#ifndef QTMVVM_QQMLMVVMMESSAGE_H
#define QTMVVM_QQMLMVVMMESSAGE_H
#include <QtCore/QObject>
#include <QtQml/QQmlParserStatus>
#include <QtQml/QJSValue>
#include <QtQml/QJSEngine>
#include <QtMvvmCore/Messages>
namespace QtMvvm {
class QQmlMvvmMessage : public QObject
{
Q_OBJECT
public:
explicit QQmlMvvmMessage(QJSEngine *engine, QObject *parent = nullptr);
public Q_SLOTS:
void information(const QString &title,
const QString &text,
const QJSValue &onResult = {},
const QString &okText = {});
void question(const QString &title,
const QString &text,
const QJSValue &onResult = {},
const QString &yesText = {},
const QString &noText = {});
void warning(const QString &title,
const QString &text,
const QJSValue &onResult = {},
const QString &okText = {});
void critical(const QString &title,
const QString &text,
const QJSValue &onResult = {},
const QString &okText = {});
void about(const QString &description,
const QUrl &websiteUrl = QUrl(),
const QString &licenseName = QString(),
const QUrl &licenseUrl = QUrl(),
const QString &companyName = QString(),
bool addQtVersion = true,
const QStringList &extraTopInfos = QStringList(),
const QString &extraBottomInfos = QString());
void getInput(const QString &title,
const QString &text,
const char *inputType,
const QJSValue &onResult = {},
const QVariant &defaultValue = {},
const QVariantMap &viewProperties = {},
const QString &okText = {},
const QString &cancelText = {});
void getExistingDirectory(const QJSValue &onResult = {},
const QString &title = {},
const QUrl &dir = {});
void getOpenFile(const QJSValue &onResult = {},
const QString &title = {},
const QStringList &supportedMimeTypes = {},
const QUrl &dir = {});
void getOpenFiles(const QJSValue &onResult,
const QString &title = {},
const QStringList &supportedMimeTypes = {},
const QUrl &dir = {});
void getSaveFile(const QJSValue &onResult,
const QString &title = {},
const QStringList &supportedMimeTypes = {},
const QUrl &dir = {});
private:
QJSEngine *_engine;
};
}
#endif // QTMVVM_QQMLMVVMMESSAGE_H

7
src/imports/mvvmcore/qtmvvmcore_plugin.cpp

@ -3,6 +3,12 @@
#include <QtQml> #include <QtQml>
#include "qqmlmvvmbinding.h" #include "qqmlmvvmbinding.h"
#include "qqmlmvvmmessage.h"
static QObject *createMessageSingleton(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
return new QtMvvm::QQmlMvvmMessage(jsEngine, qmlEngine);
}
QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) : QtMvvmCoreDeclarativeModule::QtMvvmCoreDeclarativeModule(QObject *parent) :
QQmlExtensionPlugin(parent) QQmlExtensionPlugin(parent)
@ -13,4 +19,5 @@ void QtMvvmCoreDeclarativeModule::registerTypes(const char *uri)
Q_ASSERT(qstrcmp(uri, "de.skycoder42.qtmvvm.core") == 0); Q_ASSERT(qstrcmp(uri, "de.skycoder42.qtmvvm.core") == 0);
qmlRegisterType<QtMvvm::QQmlMvvmBinding>(uri, 1, 0, "QtMvvmBinding"); qmlRegisterType<QtMvvm::QQmlMvvmBinding>(uri, 1, 0, "QtMvvmBinding");
qmlRegisterSingletonType<QtMvvm::QQmlMvvmMessage>(uri, 1, 0, "QtMvvmMessage", createMessageSingleton);
} }

2
src/imports/mvvmcore/qtmvvmcore_plugin.h

@ -1,7 +1,7 @@
#ifndef QTMVVMCORE_PLUGIN_H #ifndef QTMVVMCORE_PLUGIN_H
#define QTMVVMCORE_PLUGIN_H #define QTMVVMCORE_PLUGIN_H
#include <QQmlExtensionPlugin> #include <QtQml/QQmlExtensionPlugin>
class QtMvvmCoreDeclarativeModule : public QQmlExtensionPlugin class QtMvvmCoreDeclarativeModule : public QQmlExtensionPlugin
{ {

2
src/imports/mvvmquick/qtmvvmquick_plugin.h

@ -1,7 +1,7 @@
#ifndef QTMVVMQUICK_PLUGIN_H #ifndef QTMVVMQUICK_PLUGIN_H
#define QTMVVMQUICK_PLUGIN_H #define QTMVVMQUICK_PLUGIN_H
#include <QQmlExtensionPlugin> #include <QtQml/QQmlExtensionPlugin>
class QtMvvmQuickDeclarativeModule : public QQmlExtensionPlugin class QtMvvmQuickDeclarativeModule : public QQmlExtensionPlugin
{ {

4
src/mvvmquick/quickpresenter.cpp

@ -13,12 +13,12 @@ void QuickPresenter::registerViewExplicitly(const QMetaObject *viewModelType, co
void QuickPresenter::present(QtMvvm::ViewModel *viewModel, const QVariantHash &params, QPointer<QtMvvm::ViewModel> parent) void QuickPresenter::present(QtMvvm::ViewModel *viewModel, const QVariantHash &params, QPointer<QtMvvm::ViewModel> parent)
{ {
qDebug(Q_FUNC_INFO);
} }
void QuickPresenter::showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result) void QuickPresenter::showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result)
{ {
qDebug(Q_FUNC_INFO);
} }
QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType) QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType)

Loading…
Cancel
Save