Browse Source

Added input view factory with basic views

pull/2/head
Skycoder42 7 years ago
parent
commit
cf9abd2bc6
  1. 24
      src/imports/mvvmquick/plugins.qmltypes
  2. 7
      src/imports/mvvmquick/qqmlquickpresenter.cpp
  3. 7
      src/imports/mvvmquick/qqmlquickpresenter.h
  4. 3
      src/imports/mvvmquick/qtmvvmquick_plugin.cpp
  5. 7
      src/mvvmquick/CheckBox.qml
  6. 38
      src/mvvmquick/DoubleSpinBox.qml
  7. 10
      src/mvvmquick/FontEdit.qml
  8. 19
      src/mvvmquick/ListEdit.qml
  9. 8
      src/mvvmquick/SpinBox.qml
  10. 30
      src/mvvmquick/TextField.qml
  11. 77
      src/mvvmquick/inputviewfactory.cpp
  12. 41
      src/mvvmquick/inputviewfactory.h
  13. 4
      src/mvvmquick/inputviewfactory_p.h
  14. 10
      src/mvvmquick/mvvmquick.pro
  15. 10
      src/mvvmquick/qtmvvmquick_module.qrc
  16. 15
      src/mvvmquick/quickpresenter.cpp
  17. 11
      src/mvvmquick/quickpresenter.h
  18. 1
      src/mvvmquick/quickpresenter_p.h
  19. 16
      src/mvvmwidgets/inputwidgetfactory.cpp
  20. 18
      src/mvvmwidgets/inputwidgetfactory.h
  21. 19
      src/mvvmwidgets/inputwidgetfactory_p.h
  22. 12
      src/mvvmwidgets/mvvmwidgets.pro
  23. 2
      src/mvvmwidgets/selectcombobox_p.h
  24. 9
      src/mvvmwidgets/widgetspresenter.cpp
  25. 11
      src/mvvmwidgets/widgetspresenter.h
  26. 2
      src/mvvmwidgets/widgetspresenter_p.h

24
src/imports/mvvmquick/plugins.qmltypes

@ -8,6 +8,25 @@ import QtQuick.tooling 1.2
Module {
dependencies: ["QtQuick 2.8"]
Component {
name: "QtMvvm::InputViewFactory"
prototype: "QObject"
exports: ["de.skycoder42.QtMvvm.Quick/InputViewFactory 1.0"]
isCreatable: false
exportMetaObjectRevisions: [0]
Method {
name: "getInputUrl"
type: "QUrl"
Parameter { name: "type"; type: "QByteArray" }
Parameter { name: "viewProperties"; type: "QVariantMap" }
}
Method {
name: "addSimpleView"
type: "bool"
Parameter { name: "type"; type: "QByteArray" }
Parameter { name: "qmlFileUrl"; type: "QUrl" }
}
}
Component {
name: "QtMvvm::QQmlQuickPresenter"
prototype: "QObject"
@ -16,6 +35,7 @@ Module {
isSingleton: true
exportMetaObjectRevisions: [0]
Property { name: "currentStyle"; type: "string"; isReadonly: true }
Property { name: "inputViewFactory"; type: "InputViewFactory"; isReadonly: true; isPointer: true }
Property { name: "qmlPresenter"; type: "QObject"; isPointer: true }
Property { name: "viewLoading"; type: "bool"; isReadonly: true }
Property { name: "loadingProgress"; type: "double"; isReadonly: true }
@ -31,5 +51,9 @@ Module {
name: "loadingProgressChanged"
Parameter { name: "loadingProgress"; type: "double" }
}
Signal {
name: "inputViewFactoryChanged"
Parameter { name: "inputViewFactory"; type: "InputViewFactory"; isPointer: true }
}
}
}

7
src/imports/mvvmquick/qqmlquickpresenter.cpp

@ -18,6 +18,8 @@ QQmlQuickPresenter::QQmlQuickPresenter(QQmlEngine *engine) :
_loadCache()
{
QuickPresenterPrivate::setQmlPresenter(this);
connect(QuickPresenterPrivate::currentPresenter(), &QuickPresenter::inputViewFactoryChanged,
this, &QQmlQuickPresenter::inputViewFactoryChanged);
}
QString QQmlQuickPresenter::currentStyle() const
@ -25,6 +27,11 @@ QString QQmlQuickPresenter::currentStyle() const
return QQuickStyle::name();
}
InputViewFactory *QQmlQuickPresenter::inputViewFactory() const
{
return QuickPresenterPrivate::currentPresenter()->inputViewFactory();
}
bool QQmlQuickPresenter::isViewLoading() const
{
return _latestComponent;

7
src/imports/mvvmquick/qqmlquickpresenter.h

@ -14,6 +14,8 @@
#include <QtMvvmCore/ViewModel>
#include <QtMvvmCore/Messages>
#include <QtMvvmQuick/InputViewFactory>
namespace QtMvvm {
class QQmlQuickPresenter : public QObject
@ -21,6 +23,7 @@ class QQmlQuickPresenter : public QObject
Q_OBJECT
Q_PROPERTY(QString currentStyle READ currentStyle CONSTANT)
Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory NOTIFY inputViewFactoryChanged)
Q_PROPERTY(QObject* qmlPresenter MEMBER _qmlPresenter NOTIFY qmlPresenterChanged)
Q_PROPERTY(bool viewLoading READ isViewLoading NOTIFY viewLoadingChanged)
@ -30,15 +33,19 @@ public:
explicit QQmlQuickPresenter(QQmlEngine *engine);
QString currentStyle() const;
InputViewFactory* inputViewFactory() const;
bool isViewLoading() const;
qreal loadingProgress() const;
Q_SIGNALS:
void qmlPresenterChanged(QObject* qmlPresenter);
void viewLoadingChanged(bool viewLoading);
void loadingProgressChanged(qreal loadingProgress);
void inputViewFactoryChanged(InputViewFactory* inputViewFactory);
private Q_SLOTS:
void present(QtMvvm::ViewModel *viewModel, const QVariantHash &params, const QUrl &viewUrl, QPointer<QtMvvm::ViewModel> parent);
void showDialog(const QtMvvm::MessageConfig &config, QtMvvm::MessageResult *result);

3
src/imports/mvvmquick/qtmvvmquick_plugin.cpp

@ -2,6 +2,8 @@
#include <QtQml>
#include <QtMvvmQuick/InputViewFactory>
#include "qqmlquickpresenter.h"
#include "svgimageprovider.h"
@ -31,6 +33,7 @@ void QtMvvmQuickDeclarativeModule::registerTypes(const char *uri)
Q_ASSERT(qstrcmp(uri, "de.skycoder42.QtMvvm.Quick") == 0);
//Version 1.0
qmlRegisterUncreatableType<QtMvvm::InputViewFactory>(uri, 1, 0, "InputViewFactory", QStringLiteral("InputViewFactories can only be created from C++ via the QuickPresenter"));
qmlRegisterSingletonType<QtMvvm::QQmlQuickPresenter>(uri, 1, 0, "QuickPresenter", createQuickPresenterQmlSingleton);
// Check to make shure no module update is forgotten

7
src/mvvmquick/CheckBox.qml

@ -0,0 +1,7 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
CheckBox {
id: _edit
property alias inputValue: _edit.checked
}

38
src/mvvmquick/DoubleSpinBox.qml

@ -0,0 +1,38 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
SpinBox {
id: _edit
property alias inputValue: _edit.dValue
editable: true
//double spinbox code
property int decimals: 2
property double dFrom: 0.0
property double dTo: 100.0
property double dValue: 0.0
property double dStepSize: 0.1
readonly property int factor: Math.pow(10, _edit.decimals)
stepSize: _edit.dStepSize * _edit.factor
from: _edit.dFrom * _edit.factor
to: _edit.dTo * _edit.factor
value: _edit.dValue * _edit.factor
validator: DoubleValidator {
bottom: _edit.dFrom
top: _edit.dTo
}
textFromValue: function(value, locale) {
return Number(value / _edit.factor).toLocaleString(locale, 'f', _edit.decimals);
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * _edit.factor;
}
onDValueChanged: _edit.value = _edit.dValue * _edit.factor
onValueChanged: _edit.dValue = _edit.value / _edit.factor
}

10
src/mvvmquick/FontEdit.qml

@ -0,0 +1,10 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
ComboBox {
id: _edit
property alias inputValue: _edit.currentText
model: Qt.fontFamilies()
editable: false
}

19
src/mvvmquick/ListEdit.qml

@ -0,0 +1,19 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
ComboBox {
id: _edit
property alias inputValue: _edit.currentValue
property var currentValue: getCurrentValue()
property alias listElements: _edit.model
textRole: "name"
function getCurrentValue() {
var value = _edit.model[_edit.currentIndex].value;
if(typeof value !== "undefined")
return value;
else
return _edit.displayText;
}
}

8
src/mvvmquick/SpinBox.qml

@ -0,0 +1,8 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
SpinBox {
id: _edit
property alias inputValue: _edit.value
editable: true
}

30
src/mvvmquick/TextField.qml

@ -0,0 +1,30 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
TextField {
id: _edit
property alias inputValue: _edit.text
property string regexp: ""
property string patternOptions
selectByMouse: true
validator: regexp != "" ? _validator.createObject(_edit) : null
Component {
id: _validator
RegExpValidator {
regExp: new RegExp(_edit.regexp, optionsAsString(_edit.patternOptions))
function optionsAsString(options) {
var resStr;
if((options & 0x0001) != 0) //QRegularExpression::CaseInsensitiveOption
resStr += "i";
if((options & 0x0004) != 0) //QRegularExpression::MultilineOption
resStr += "m";
if((options & 0x0040) != 0) //QRegularExpression::UseUnicodePropertiesOption
resStr += "u";
return resStr;
}
}
}
}

77
src/mvvmquick/inputviewfactory.cpp

@ -0,0 +1,77 @@
#include "inputviewfactory.h"
#include "inputviewfactory_p.h"
#include <QtCore/QMetaType>
#include <QtMvvmCore/private/qtmvvm_logging_p.h>
using namespace QtMvvm;
static void initResources()
{
#ifdef QT_STATIC
Q_INIT_RESOURCE(qtmvvmquick_module);
#endif
}
InputViewFactory::InputViewFactory() :
QObject(nullptr),
d(new InputViewFactoryPrivate())
{
initResources();
}
InputViewFactory::~InputViewFactory() {}
//int InputViewFactory::metaTypeId(const QByteArray &type, const QVariantMap &properties)
//{
// if(type == "string")
// return QMetaType::QString;
// else if(type == "list")
// return metaTypeId(properties.value(QStringLiteral("_list_data"), QByteArray("string")).toByteArray(), properties);
// else
// return QMetaType::type(type);
//}
QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &viewProperties)
{
Q_UNUSED(viewProperties)
if(d->simpleViews.contains(type))
return d->simpleViews.value(type);
else if(type == QMetaType::typeName(QMetaType::Bool))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/CheckBox.qml");
else if(type == QMetaType::typeName(QMetaType::QString) || type == "string")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/TextField.qml");
else if(type == QMetaType::typeName(QMetaType::Int))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/SpinBox.qml");
else if(type == QMetaType::typeName(QMetaType::Double))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/DoubleSpinBox.qml");
// else if(type == QMetaType::typeName(QMetaType::QDate))
// return QUrl();
// else if(type == QMetaType::typeName(QMetaType::QTime))
// return QUrl();
// else if(type == QMetaType::typeName(QMetaType::QDateTime) || type == "date")
// return QUrl();
else if(type == QMetaType::typeName(QMetaType::QFont))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/FontEdit.qml");
// else if(type == QMetaType::typeName(QMetaType::QUrl) || type == "url")
// return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/UrlField.qml");
else if(type == "selection" || type == "list")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/ListEdit.qml");
else {
logCritical() << "Failed to find any input view for input type:" << type;
return QUrl();
}
}
bool InputViewFactory::addSimpleView(const QByteArray &type, const QUrl &qmlFileUrl)
{
d->simpleViews.insert(type, qmlFileUrl);
return true;
}
// ------------- Private Implementation -------------
InputViewFactoryPrivate::InputViewFactoryPrivate() :
simpleViews()
{}

41
src/mvvmquick/inputviewfactory.h

@ -0,0 +1,41 @@
#ifndef QTMVVM_INPUTVIEWFACTORY_H
#define QTMVVM_INPUTVIEWFACTORY_H
#include <QtCore/qurl.h>
#include <QtCore/qvariant.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qobject.h>
#include "QtMvvmQuick/qtmvvmquick_global.h"
namespace QtMvvm {
class InputViewFactoryPrivate;
class Q_MVVMQUICK_EXPORT InputViewFactory : public QObject
{
Q_OBJECT
public:
InputViewFactory();
virtual ~InputViewFactory();
//virtual int metaTypeId(const QByteArray &type, const QVariantMap &properties);
Q_INVOKABLE virtual QUrl getInputUrl(const QByteArray &type, const QVariantMap &viewProperties);
Q_INVOKABLE virtual bool addSimpleView(const QByteArray &type, const QUrl &qmlFileUrl);
template <typename T>
bool addSimpleView(const QUrl &qmlFileUrl);
private:
QScopedPointer<InputViewFactoryPrivate> d;
};
template<typename T>
bool InputViewFactory::addSimpleView(const QUrl &qmlFileUrl)
{
return addSimpleView(QMetaType::typeName(qMetaTypeId<T>()), qmlFileUrl);
}
}
#endif // QTMVVM_INPUTVIEWFACTORY_H

4
src/mvvmwidgets/inputviewfactory_p.h → src/mvvmquick/inputviewfactory_p.h

@ -1,7 +1,7 @@
#ifndef QTMVVM_INPUTVIEWFACTORY_P_H
#define QTMVVM_INPUTVIEWFACTORY_P_H
#include "qtmvvmwidgets_global.h"
#include "qtmvvmquick_global.h"
#include "inputviewfactory.h"
namespace QtMvvm {
@ -11,7 +11,7 @@ class InputViewFactoryPrivate
public:
InputViewFactoryPrivate();
QHash<QByteArray, std::function<QWidget*(QWidget*)>> simpleWidgets;
QHash<QByteArray, QUrl> simpleViews;
};
}

10
src/mvvmquick/mvvmquick.pro

@ -5,10 +5,13 @@ QT = core gui widgets mvvmcore mvvmcore-private
HEADERS += \
qtmvvmquick_global.h \
quickpresenter.h \
quickpresenter_p.h
quickpresenter_p.h \
inputviewfactory.h \
inputviewfactory_p.h
SOURCES += \
quickpresenter.cpp
quickpresenter.cpp \
inputviewfactory.cpp
TRANSLATIONS += \
translations/qtmvvmquick_de.ts \
@ -35,3 +38,6 @@ else: include($$OUT_PWD/qpmx_generated.pri)
qpmx_ts_target.files -= $$OUT_PWD/$$QPMX_WORKINGDIR/qtmvvmquick_template.qm
qpmx_ts_target.files += translations/qtmvvmquick_template.ts
RESOURCES += \
qtmvvmquick_module.qrc

10
src/mvvmquick/qtmvvmquick_module.qrc

@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/de/skycoder42/qtmvvm/quick/inputs">
<file>ListEdit.qml</file>
<file>TextField.qml</file>
<file>SpinBox.qml</file>
<file>CheckBox.qml</file>
<file>DoubleSpinBox.qml</file>
<file>FontEdit.qml</file>
</qresource>
</RCC>

15
src/mvvmquick/quickpresenter.cpp

@ -67,6 +67,17 @@ bool QuickPresenter::presentToQml(QObject *qmlPresenter, QObject *viewObject)
return presented.toBool();
}
InputViewFactory *QuickPresenter::inputViewFactory() const
{
return d->inputViewFactory.data();
}
void QuickPresenter::setInputViewFactory(InputViewFactory *inputViewFactory)
{
d->inputViewFactory.reset(inputViewFactory);
emit inputViewFactoryChanged(inputViewFactory);
}
QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType)
{
auto currentMeta = viewModelType;
@ -141,7 +152,9 @@ bool QuickPresenter::nameOrClassContains(const QObject *obj, const QString &cont
QuickPresenterPrivate::QuickPresenterPrivate() :
explicitMappings(),
searchDirs({QStringLiteral(":/qtmvvm/views")})
searchDirs({QStringLiteral(":/qtmvvm/views")}),
qmlPresenter(nullptr),
inputViewFactory(new InputViewFactory())
{}
QuickPresenter *QuickPresenterPrivate::currentPresenter()

11
src/mvvmquick/quickpresenter.h

@ -10,6 +10,7 @@
#include <QtMvvmCore/coreapp.h>
#include "QtMvvmQuick/qtmvvmquick_global.h"
#include "QtMvvmQuick/inputviewfactory.h"
namespace QtMvvm {
@ -19,6 +20,8 @@ class Q_MVVMQUICK_EXPORT QuickPresenter : public QObject, public IPresenter
Q_OBJECT
Q_INTERFACES(QtMvvm::IPresenter)
Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory WRITE setInputViewFactory NOTIFY inputViewFactoryChanged)
public:
explicit QuickPresenter(QObject *parent = nullptr);
~QuickPresenter();
@ -36,6 +39,14 @@ public:
virtual bool presentToQml(QObject *qmlPresenter, QObject *viewObject);
InputViewFactory* inputViewFactory() const;
public Q_SLOTS:
void setInputViewFactory(InputViewFactory* inputViewFactory);
Q_SIGNALS:
void inputViewFactoryChanged(InputViewFactory* inputViewFactory);
protected:
virtual QUrl findViewUrl(const QMetaObject *viewModelType);
virtual int presentMethodIndex(const QMetaObject *presenterMetaObject, QObject *viewObject);

1
src/mvvmquick/quickpresenter_p.h

@ -24,6 +24,7 @@ private:
QStringList searchDirs;
QPointer<QObject> qmlPresenter;
QScopedPointer<InputViewFactory> inputViewFactory;
};
}

16
src/mvvmwidgets/inputviewfactory.cpp → src/mvvmwidgets/inputwidgetfactory.cpp

@ -1,5 +1,5 @@
#include "inputviewfactory.h"
#include "inputviewfactory_p.h"
#include "inputwidgetfactory.h"
#include "inputwidgetfactory_p.h"
#include <QtMvvmCore/private/qtmvvm_logging_p.h>
#include <QtWidgets/QCheckBox>
@ -15,13 +15,13 @@
using namespace QtMvvm;
InputViewFactory::InputViewFactory() :
d(new InputViewFactoryPrivate())
InputWidgetFactory::InputWidgetFactory() :
d(new InputWidgetFactoryPrivate())
{}
InputViewFactory::~InputViewFactory() {}
InputWidgetFactory::~InputWidgetFactory() {}
QWidget *InputViewFactory::createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties)
QWidget *InputWidgetFactory::createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties)
{
QWidget *widget = nullptr;
if(d->simpleWidgets.contains(type))
@ -72,7 +72,7 @@ QWidget *InputViewFactory::createInput(const QByteArray &type, QWidget *parent,
return widget;
}
void InputViewFactory::addSimpleWidget(const QByteArray &type, const std::function<QWidget *(QWidget *)> &creator)
void InputWidgetFactory::addSimpleWidget(const QByteArray &type, const std::function<QWidget *(QWidget *)> &creator)
{
Q_ASSERT_X(creator, Q_FUNC_INFO, "The passed creation function must be valid");
d->simpleWidgets.insert(type, creator);
@ -80,6 +80,6 @@ void InputViewFactory::addSimpleWidget(const QByteArray &type, const std::functi
// ------------- Private Implementation -------------
InputViewFactoryPrivate::InputViewFactoryPrivate() :
InputWidgetFactoryPrivate::InputWidgetFactoryPrivate() :
simpleWidgets()
{}

18
src/mvvmwidgets/inputviewfactory.h → src/mvvmwidgets/inputwidgetfactory.h

@ -1,5 +1,5 @@
#ifndef QTMVVM_INPUTVIEWFACTORY_H
#define QTMVVM_INPUTVIEWFACTORY_H
#ifndef QTMVVM_INPUTWIDGETFACTORY_H
#define QTMVVM_INPUTWIDGETFACTORY_H
#include <functional>
@ -11,12 +11,12 @@
namespace QtMvvm {
class InputViewFactoryPrivate;
class InputViewFactory
class InputWidgetFactoryPrivate;
class InputWidgetFactory
{
public:
InputViewFactory();
virtual ~InputViewFactory();
InputWidgetFactory();
virtual ~InputWidgetFactory();
virtual QWidget *createInput(const QByteArray &type, QWidget *parent, const QVariantMap &viewProperties);
@ -25,11 +25,11 @@ public:
void addSimpleWidget();
private:
QScopedPointer<InputViewFactoryPrivate> d;
QScopedPointer<InputWidgetFactoryPrivate> d;
};
template<typename TType, typename TWidget>
void InputViewFactory::addSimpleWidget()
void InputWidgetFactory::addSimpleWidget()
{
addSimpleWidget(QMetaType::typeName(qMetaTypeId<TType>()), [](QWidget *parent){
return new TWidget(parent);
@ -38,4 +38,4 @@ void InputViewFactory::addSimpleWidget()
}
#endif // QTMVVM_INPUTVIEWFACTORY_H
#endif // QTMVVM_INPUTWIDGETFACTORY_H

19
src/mvvmwidgets/inputwidgetfactory_p.h

@ -0,0 +1,19 @@
#ifndef QTMVVM_INPUTWIDGETFACTORY_P_H
#define QTMVVM_INPUTWIDGETFACTORY_P_H
#include "qtmvvmwidgets_global.h"
#include "inputwidgetfactory.h"
namespace QtMvvm {
class InputWidgetFactoryPrivate
{
public:
InputWidgetFactoryPrivate();
QHash<QByteArray, std::function<QWidget*(QWidget*)>> simpleWidgets;
};
}
#endif // QTMVVM_INPUTWIDGETFACTORY_P_H

12
src/mvvmwidgets/mvvmwidgets.pro

@ -7,16 +7,16 @@ HEADERS += \
widgetspresenter.h \
ipresentingview.h \
widgetspresenter_p.h \
inputviewfactory.h \
inputviewfactory_p.h \
fontcombobox_p.h \
selectcombobox_p.h
selectcombobox_p.h \
inputwidgetfactory.h \
inputwidgetfactory_p.h
SOURCES += \
widgetspresenter.cpp \
inputviewfactory.cpp \
fontcombobox.cpp \
selectcombobox.cpp
selectcombobox.cpp \
inputwidgetfactory.cpp
TRANSLATIONS += \
translations/qtmvvmwidgets_de.ts \
@ -43,3 +43,5 @@ else: include($$OUT_PWD/qpmx_generated.pri)
qpmx_ts_target.files -= $$OUT_PWD/$$QPMX_WORKINGDIR/qtmvvmwidgets_template.qm
qpmx_ts_target.files += translations/qtmvvmwidgets_template.ts
mingw: LIBS_PRIVATE += -lQt5Widgets -lQt5Gui -lQt5Core

2
src/mvvmwidgets/selectcombobox_p.h

@ -16,8 +16,6 @@ class SelectComboBox : public QComboBox
Q_PROPERTY(QVariant currentValue READ currentValue WRITE setCurrentValue NOTIFY currentValueChanged USER true)
Q_PROPERTY(QVariantList listElements READ listElements WRITE setListElements NOTIFY listElementsChanged)
QVariantMap m_listElements;
public:
explicit SelectComboBox(QWidget *parent = nullptr);

9
src/mvvmwidgets/widgetspresenter.cpp

@ -99,14 +99,15 @@ void WidgetsPresenter::showDialog(const MessageConfig &config, MessageResult *re
presentOtherDialog(config, result);
}
InputViewFactory *WidgetsPresenter::inputViewFactory() const
InputWidgetFactory *WidgetsPresenter::inputWidgetFactory() const
{
return d->inputViewFactory.data();
}
void WidgetsPresenter::setInputViewFactory(InputViewFactory *inputViewFactory)
void WidgetsPresenter::setInputWidgetFactory(InputWidgetFactory *inputWidgetFactory)
{
d->inputViewFactory.reset(inputViewFactory);
d->inputViewFactory.reset(inputWidgetFactory);
emit inputWidgetFactoryChanged(inputWidgetFactory);
}
const QMetaObject *WidgetsPresenter::findWidgetMetaObject(const QMetaObject *viewModelMetaObject)
@ -395,7 +396,7 @@ void WidgetsPresenter::presentOtherDialog(const MessageConfig &config, QPointer<
// ------------- Private Implementation -------------
WidgetsPresenterPrivate::WidgetsPresenterPrivate() :
inputViewFactory(new InputViewFactory()),
inputViewFactory(new InputWidgetFactory()),
implicitMappings(),
explicitMappings()
{}

11
src/mvvmwidgets/widgetspresenter.h

@ -10,7 +10,7 @@
#include <QtWidgets/qwidget.h>
#include "QtMvvmWidgets/qtmvvmwidgets_global.h"
#include "QtMvvmWidgets/inputviewfactory.h"
#include "QtMvvmWidgets/inputwidgetfactory.h"
namespace QtMvvm {
@ -20,7 +20,7 @@ class Q_MVVMWIDGETS_EXPORT WidgetsPresenter : public QObject, public IPresenter
Q_OBJECT
Q_INTERFACES(QtMvvm::IPresenter)
Q_PROPERTY(InputViewFactory* inputViewFactory READ inputViewFactory WRITE setInputViewFactory)
Q_PROPERTY(InputWidgetFactory* inputWidgetFactory READ inputWidgetFactory WRITE setInputWidgetFactory NOTIFY inputWidgetFactoryChanged)
public:
explicit WidgetsPresenter(QObject *parent = nullptr);
@ -40,10 +40,13 @@ public:
void present(ViewModel *viewModel, const QVariantHash &params, QPointer<ViewModel> parent) override;
void showDialog(const MessageConfig &config, MessageResult *result) override;
InputViewFactory* inputViewFactory() const;
InputWidgetFactory* inputWidgetFactory() const;
public Q_SLOTS:
void setInputViewFactory(InputViewFactory* inputViewFactory);
void setInputWidgetFactory(InputWidgetFactory* inputWidgetFactory);
Q_SIGNALS:
void inputWidgetFactoryChanged(InputWidgetFactory* inputWidgetFactory);
protected:
virtual const QMetaObject *findWidgetMetaObject(const QMetaObject *viewModelMetaObject);

2
src/mvvmwidgets/widgetspresenter_p.h

@ -16,7 +16,7 @@ public:
static WidgetsPresenter *currentPresenter();
QScopedPointer<InputViewFactory> inputViewFactory;
QScopedPointer<InputWidgetFactory> inputViewFactory;
QSet<const QMetaObject*> implicitMappings;
QHash<const QMetaObject*, const QMetaObject*> explicitMappings;
};

Loading…
Cancel
Save