|
@ -8,6 +8,8 @@ |
|
|
|
|
|
|
|
|
#include <QtMvvmCore/private/qtmvvm_logging_p.h> |
|
|
#include <QtMvvmCore/private/qtmvvm_logging_p.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "formatters_p.h" |
|
|
|
|
|
|
|
|
using namespace QtMvvm; |
|
|
using namespace QtMvvm; |
|
|
|
|
|
|
|
|
InputViewFactory::InputViewFactory(QObject *parent) : |
|
|
InputViewFactory::InputViewFactory(QObject *parent) : |
|
@ -24,32 +26,8 @@ QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &vi |
|
|
Q_UNUSED(viewProperties) |
|
|
Q_UNUSED(viewProperties) |
|
|
if(d->inputAliases.contains(type)) |
|
|
if(d->inputAliases.contains(type)) |
|
|
url = getInputUrl(d->inputAliases.value(type), viewProperties); |
|
|
url = getInputUrl(d->inputAliases.value(type), viewProperties); |
|
|
if(d->simpleInputs.contains(type)) |
|
|
else if(d->simpleInputs.contains(type)) |
|
|
url = d->simpleInputs.value(type); |
|
|
url = d->simpleInputs.value(type); |
|
|
else if(type == QMetaType::typeName(QMetaType::Bool)) |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/CheckBox.qml"); |
|
|
|
|
|
else if(type == "switch") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/Switch.qml"); |
|
|
|
|
|
else if(type == QMetaType::typeName(QMetaType::QString) || type == "string") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml"); |
|
|
|
|
|
else if(type == QMetaType::typeName(QMetaType::Int)) |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/SpinBox.qml"); |
|
|
|
|
|
else if(type == QMetaType::typeName(QMetaType::Double)) |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml"); |
|
|
|
|
|
// else if(type == QMetaType::typeName(QMetaType::QDate))
|
|
|
|
|
|
// url = QUrl();
|
|
|
|
|
|
// else if(type == QMetaType::typeName(QMetaType::QTime))
|
|
|
|
|
|
// url = QUrl();
|
|
|
|
|
|
// else if(type == QMetaType::typeName(QMetaType::QDateTime) || type == "date")
|
|
|
|
|
|
// url = QUrl();
|
|
|
|
|
|
else if(type == QMetaType::typeName(QMetaType::QFont)) |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml"); |
|
|
|
|
|
else if(type == QMetaType::typeName(QMetaType::QUrl) || type == "url") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml"); |
|
|
|
|
|
else if(type == "selection" || type == "list") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml"); |
|
|
|
|
|
else if(type == "radiolist") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/inputs/RadioListEdit.qml"); |
|
|
|
|
|
else { |
|
|
else { |
|
|
logCritical() << "Failed to find any input view for input type:" << type; |
|
|
logCritical() << "Failed to find any input view for input type:" << type; |
|
|
return QUrl(); |
|
|
return QUrl(); |
|
@ -66,12 +44,8 @@ QUrl InputViewFactory::getDelegate(const QByteArray &type, const QVariantMap &vi |
|
|
Q_UNUSED(viewProperties) |
|
|
Q_UNUSED(viewProperties) |
|
|
if(d->delegateAliases.contains(type)) |
|
|
if(d->delegateAliases.contains(type)) |
|
|
url = getDelegate(d->delegateAliases.value(type), viewProperties); |
|
|
url = getDelegate(d->delegateAliases.value(type), viewProperties); |
|
|
if(d->simpleDelegates.contains(type)) |
|
|
else if(d->simpleDelegates.contains(type)) |
|
|
url = d->simpleDelegates.value(type); |
|
|
url = d->simpleDelegates.value(type); |
|
|
else if(type == QMetaType::typeName(QMetaType::Bool)) |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/delegates/BoolDelegate.qml"); |
|
|
|
|
|
else if(type == "switch") |
|
|
|
|
|
url = QStringLiteral("qrc:/qtmvvm/delegates/SwitchDelegate.qml"); |
|
|
|
|
|
else if((type == "selection" || type == "list") && |
|
|
else if((type == "selection" || type == "list") && |
|
|
!viewProperties.value(QStringLiteral("editable"), false).toBool()) |
|
|
!viewProperties.value(QStringLiteral("editable"), false).toBool()) |
|
|
url = QStringLiteral("qrc:/qtmvvm/delegates/ListDelegate.qml"); |
|
|
url = QStringLiteral("qrc:/qtmvvm/delegates/ListDelegate.qml"); |
|
@ -82,6 +56,16 @@ QUrl InputViewFactory::getDelegate(const QByteArray &type, const QVariantMap &vi |
|
|
return url; |
|
|
return url; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString QtMvvm::InputViewFactory::format(const QByteArray &type, const QString &formatString, const QVariant &value, const QVariantMap &viewProperties) |
|
|
|
|
|
{ |
|
|
|
|
|
if(d->formatterAliases.contains(type)) |
|
|
|
|
|
return format(d->formatterAliases.value(type), formatString, value, viewProperties); |
|
|
|
|
|
else if(d->formatters.contains(type)) |
|
|
|
|
|
return d->formatters.value(type)->format(formatString, value, viewProperties); |
|
|
|
|
|
else |
|
|
|
|
|
return formatString.arg(value.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void InputViewFactory::addSimpleInput(const QByteArray &type, const QUrl &qmlFileUrl) |
|
|
void InputViewFactory::addSimpleInput(const QByteArray &type, const QUrl &qmlFileUrl) |
|
|
{ |
|
|
{ |
|
|
d->simpleInputs.insert(type, qmlFileUrl); |
|
|
d->simpleInputs.insert(type, qmlFileUrl); |
|
@ -92,6 +76,11 @@ void InputViewFactory::addSimpleDelegate(const QByteArray &type, const QUrl &qml |
|
|
d->simpleDelegates.insert(type, qmlFileUrl); |
|
|
d->simpleDelegates.insert(type, qmlFileUrl); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void InputViewFactory::addFormatter(const QByteArray &type, Formatter *formatter) |
|
|
|
|
|
{ |
|
|
|
|
|
d->formatters.insert(type, QSharedPointer<Formatter>{formatter}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void InputViewFactory::addInputAlias(const QByteArray &alias, const QByteArray &targetType) |
|
|
void InputViewFactory::addInputAlias(const QByteArray &alias, const QByteArray &targetType) |
|
|
{ |
|
|
{ |
|
|
d->inputAliases.insert(alias, targetType); |
|
|
d->inputAliases.insert(alias, targetType); |
|
@ -101,3 +90,49 @@ void InputViewFactory::addDelegateAlias(const QByteArray &alias, const QByteArra |
|
|
{ |
|
|
{ |
|
|
d->delegateAliases.insert(alias, targetType); |
|
|
d->delegateAliases.insert(alias, targetType); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void QtMvvm::InputViewFactory::addFormatterAlias(const QByteArray &alias, const QByteArray &targetType) |
|
|
|
|
|
{ |
|
|
|
|
|
d->formatterAliases.insert(alias, targetType); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Formatter::Formatter() = default; |
|
|
|
|
|
|
|
|
|
|
|
Formatter::~Formatter() = default; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InputViewFactoryPrivate::InputViewFactoryPrivate() : |
|
|
|
|
|
simpleInputs{ |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Bool), QStringLiteral("qrc:/qtmvvm/inputs/CheckBox.qml")}, |
|
|
|
|
|
{"switch", QStringLiteral("qrc:/qtmvvm/inputs/Switch.qml")}, |
|
|
|
|
|
{QMetaType::typeName(QMetaType::QString), QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml")}, |
|
|
|
|
|
{"string", QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml")}, |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Int), QStringLiteral("qrc:/qtmvvm/inputs/SpinBox.qml")}, |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Double), QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")}, |
|
|
|
|
|
// {QMetaType::typeName(QMetaType::QDate), QStringLiteral("qrc:/qtmvvm/inputs/.qml")},
|
|
|
|
|
|
// {QMetaType::typeName(QMetaType::QTime), QStringLiteral("qrc:/qtmvvm/inputs/.qml")},
|
|
|
|
|
|
// {QMetaType::typeName(QMetaType::QDateTime), QStringLiteral("qrc:/qtmvvm/inputs/.qml")},
|
|
|
|
|
|
// {"date", QStringLiteral("qrc:/qtmvvm/inputs/.qml")},
|
|
|
|
|
|
{QMetaType::typeName(QMetaType::QFont), QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml")}, |
|
|
|
|
|
{QMetaType::typeName(QMetaType::QUrl), QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml")}, |
|
|
|
|
|
{"selection", QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml")}, |
|
|
|
|
|
{"list", QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml")}, |
|
|
|
|
|
{"radiolist", QStringLiteral("qrc:/qtmvvm/inputs/RadioListEdit.qml")} |
|
|
|
|
|
}, |
|
|
|
|
|
simpleDelegates{ |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Bool), QStringLiteral("qrc:/qtmvvm/delegates/BoolDelegate.qml")}, |
|
|
|
|
|
{"switch", QStringLiteral("qrc:/qtmvvm/inputs/SwitchDelegate.qml")} |
|
|
|
|
|
}, |
|
|
|
|
|
formatters{ |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Int), QSharedPointer<IntFormatter>::create()}, |
|
|
|
|
|
{QMetaType::typeName(QMetaType::Double), QSharedPointer<SimpleFormatter<double>>::create()}, |
|
|
|
|
|
} |
|
|
|
|
|
{ |
|
|
|
|
|
auto listFormatter = QSharedPointer<ListFormatter>::create(); |
|
|
|
|
|
formatters.insert("selection", listFormatter); |
|
|
|
|
|
formatters.insert("list", listFormatter); |
|
|
|
|
|
formatters.insert("radiolist", listFormatter); |
|
|
|
|
|
} |
|
|