Skycoder42
7 years ago
26 changed files with 375 additions and 40 deletions
@ -0,0 +1,7 @@ |
|||
import QtQuick 2.10 |
|||
import QtQuick.Controls 2.3 |
|||
|
|||
CheckBox { |
|||
id: _edit |
|||
property alias inputValue: _edit.checked |
|||
} |
@ -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 |
|||
} |
@ -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 |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -0,0 +1,8 @@ |
|||
import QtQuick 2.10 |
|||
import QtQuick.Controls 2.3 |
|||
|
|||
SpinBox { |
|||
id: _edit |
|||
property alias inputValue: _edit.value |
|||
editable: true |
|||
} |
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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() |
|||
{} |
|||
|
@ -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
|
@ -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> |
@ -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
|
Loading…
Reference in new issue