Browse Source

WIP quick ui

pull/2/head
Skycoder42 7 years ago
parent
commit
4b976ac809
  1. 31
      src/imports/mvvmquick/ActionButton.qml
  2. 31
      src/imports/mvvmquick/ListSection.qml
  3. 74
      src/imports/mvvmquick/OverviewListView.qml
  4. 21
      src/imports/mvvmquick/SectionListView.qml
  5. 219
      src/imports/mvvmquick/SettingsView.qml
  6. 4
      src/imports/mvvmquick/icons/ic_arrow_back_white_24px.svg
  7. 4
      src/imports/mvvmquick/icons/ic_close_white_24px.svg
  8. 4
      src/imports/mvvmquick/icons/ic_search_white_24px.svg
  9. 4
      src/imports/mvvmquick/icons/ic_settings_backup_restore_white_24px.svg
  10. 4
      src/imports/mvvmquick/icons/ic_settings_white_24px.svg
  11. 7
      src/imports/mvvmquick/mvvmquick.pro
  12. 20
      src/imports/mvvmquick/plugins.qmltypes
  13. 6
      src/imports/mvvmquick/qmldir
  14. 1
      src/imports/mvvmquick/qtmvvmquick_plugin.cpp
  15. 10
      src/imports/mvvmquick/qtmvvmquick_plugin.qrc
  16. 2
      src/mvvmcore/serviceregistry.cpp
  17. 1
      src/mvvmcore/serviceregistry.h
  18. 2
      src/mvvmcore/settingssetuploader.cpp
  19. 46
      src/mvvmquick/BoolDelegate.qml
  20. 29
      src/mvvmquick/MsgDelegate.qml
  21. 46
      src/mvvmquick/SwitchDelegate.qml
  22. 66
      src/mvvmquick/inputviewfactory.cpp
  23. 37
      src/mvvmquick/inputviewfactory.h
  24. 6
      src/mvvmquick/inputviewfactory_p.h
  25. 7
      src/mvvmquick/qtmvvmquick_module.qrc
  26. 6
      src/mvvmquick/quickpresenter.cpp
  27. 2
      src/mvvmwidgets/qtmvvmwidgets_module.qrc
  28. 2
      src/mvvmwidgets/settingsdialog.cpp

31
src/imports/mvvmquick/ActionButton.qml

@ -0,0 +1,31 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
ToolButton {
id: _toolButton
property alias source: _tintIcon.source
property alias toolTip: _backToolTip.text
implicitHeight: 56.0
implicitWidth: 56.0
contentItem: TintIcon {
id: _tintIcon
implicitHeight: _toolButton.implicitHeight
implicitWidth: _toolButton.implicitWidth
}
ToolTip {
id: _backToolTip
Material.foreground: "#FFFFFF"
}
onPressAndHold: {
//TODO QuickExtras.hapticLongPress();
_backToolTip.visible = true;
}
onCanceled: _backToolTip.visible = false
onReleased: _backToolTip.visible = false
}

31
src/imports/mvvmquick/ListSection.qml

@ -0,0 +1,31 @@
import QtQuick 2.8
import QtQuick.Controls 2.1
import de.skycoder42.quickextras 2.0
Label {
property string title
CommonStyle {
id: style
}
width: parent.width
font.bold: true
font.capitalization: Font.SmallCaps
padding: 14
bottomPadding: 4
text: title + qsTr(":")
background: Rectangle {
anchors.fill: parent
color: style.sBackground
Rectangle {
anchors.left: parent.left
anchors.bottom: parent.bottom
anchors.right: parent.right
height: 2
color: style.accent
}
}
}

74
src/imports/mvvmquick/OverviewListView.qml

@ -0,0 +1,74 @@
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import de.skycoder42.quickextras 2.0
ListView {
id: listView
property bool showSections: true
section.property: showSections ? "category" : ""
section.labelPositioning: ViewSection.InlineLabels
section.delegate: ListSection {
title: section
}
delegate: ItemDelegate {
id: delegate
width: parent.width
onClicked: builder.loadSection(settingsSection)
Timer {
id: enforcer
interval: 50
repeat: false
running: true
onTriggered: {
delegate.implicitHeight = Qt.binding(function(){return grid.implicitHeight + 32});
}
}
contentItem: GridLayout {
id: grid
rows: 2
columns: 2
columnSpacing: 14
TintIcon {
id: tintIcon
source: icon
visible: icon != ""
Layout.row: 0
Layout.column: 0
Layout.rowSpan: 2
Layout.fillHeight: true
Layout.preferredWidth: iconSize.width
Layout.preferredHeight: iconSize.height
Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
}
Label {
id: titleLabel
text: title
Layout.row: 0
Layout.column: 1
font.bold: true
elide: Label.ElideRight
Layout.fillWidth: true
}
Label {
id: textLabel
visible: tooltip
Layout.row: 1
Layout.column: 1
text: tooltip
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
}
}

21
src/imports/mvvmquick/SectionListView.qml

@ -0,0 +1,21 @@
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
ListView {
id: listView
section.property: "group"
section.labelPositioning: ViewSection.InlineLabels
section.delegate: ListSection {
title: section
}
delegate: Loader {
id: loaderDelegate
width: parent.width
height: item ? item.implicitHeight : 0
Component.onCompleted: loaderDelegate.setSource(delegateUrl, editProperties);
}
}

219
src/imports/mvvmquick/SettingsView.qml

@ -0,0 +1,219 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
import QtQuick.Layouts 1.3
import de.skycoder42.QtMvvm.Core 1.0
import de.skycoder42.QtMvvm.Quick 1.0
Page {
id: _settingsView
property SettingsViewModel viewModel: null
function closeAction() {
return _settingsStack.closeAction();
}
header: ToolBar {
id: _toolBar
RowLayout {
id: _toolLayout
anchors.fill: parent
spacing: 0
ActionButton {
id: _backButton
source: "image://svg/de/skycoder42/qtmvvm/quick/icons/ic_arrow_back"
toolTip: qsTr("Go back")
onClicked: {
//TODO close settings view
}
}
Item {
id: _labelContainer
Layout.fillWidth: true
Layout.minimumHeight: 56
Label {
id: _titleLabel
font.pointSize: 16
font.bold: true
elide: Label.ElideRight
leftPadding: 10
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
anchors.fill: parent
text: qsTr("Settings")
visible: !_searchField.visible
}
TextField {
id: _searchField
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
height: Math.min(implicitHeight, parent.height)
width: parent.width
}
}
ActionButton {
id: _searchButton
visible: true
toolTip: qsTr("Search in settings")
onClicked: toggleSearchState()
}
ActionButton {
id: _restoreButton
visible: true
source: "image://svg/de/skycoder42/qtmvvm/quick/icons/ic_settings_backup_restore"
toolTip: qsTr("Restore settings")
onClicked: builder.restoreDefaults()
}
}
}
states: [
State {
name: "title"
PropertyChanges {
target: _searchButton
source: "image://svg/de/skycoder42/qtmvvm/quick/icons/ic_search"
}
PropertyChanges {
target: _titleLabel
visible: true
}
PropertyChanges {
target: _searchField
visible: false
width: 0
}
StateChangeScript {
name: "focusScript"
script: _searchField.clear();
}
},
State {
name: "search"
PropertyChanges {
target: _searchButton
source: "image://svg/de/skycoder42/qtmvvm/quick/icons/ic_close"
}
PropertyChanges {
target: _titleLabel
visible: false
}
PropertyChanges {
target: _searchField
visible: true
width: _labelContainer.width
}
StateChangeScript {
name: "focusScript"
script: _searchField.forceActiveFocus();
}
}
]
transitions: [
Transition {
from: "title"
to: "search"
SequentialAnimation {
PropertyAnimation {
target: _searchField
property: "visible"
duration: 0
}
PropertyAnimation {
target: _searchField
property: "width"
duration: 250
easing.type: Easing.InOutCubic
}
PropertyAnimation {
target: _titleLabel
property: "visible"
duration: 0
}
}
},
Transition {
from: "search"
to: "title"
SequentialAnimation {
PropertyAnimation {
target: _titleLabel
property: "visible"
duration: 0
}
PropertyAnimation {
target: _searchField
property: "width"
duration: 250
easing.type: Easing.InOutCubic
}
PropertyAnimation {
target: _searchField
property: "visible"
duration: 0
}
}
}
]
state: "title"
function toggleSearchState() {
if(state == "title")
state = "search";
else
state = "title";
}
PresenterProgress {}
StackView {
id: _settingsStack
anchors.fill: parent
function closeAction() {
if(_settingsStack.depth <= 1)
return false;
else {
_settingsStack.pop();
return true;
}
}
}
// SettingsUiBuilder {
// id: builder
// buildView: _settingsView
// control: _settingsView.control
// filterText: _searchField.text
// onInitActions: {
// searchButton.visible = allowSearch;
// restoreButton.visible = allowSearch;
// }
// onCreateView: {
// if(isOverview) {
// _settingsStack.push("qrc:/de/skycoder42/qtmvvm/settings/quick/OverviewListView.qml", {
// "model": model,
// "showSections": showSections
// });
// } else {
// _settingsStack.push("qrc:/de/skycoder42/qtmvvm/settings/quick/SectionListView.qml", {
// "model": model
// });
// }
// }
// }
}

4
src/imports/mvvmquick/icons/ic_arrow_back_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/>
</svg>

After

Width:  |  Height:  |  Size: 224 B

4
src/imports/mvvmquick/icons/ic_close_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 265 B

4
src/imports/mvvmquick/icons/ic_search_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 398 B

4
src/imports/mvvmquick/icons/ic_settings_backup_restore_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M14 12c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm-2-9c-4.97 0-9 4.03-9 9H0l4 4 4-4H5c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.51 0-2.91-.49-4.06-1.3l-1.42 1.44C8.04 20.3 9.94 21 12 21c4.97 0 9-4.03 9-9s-4.03-9-9-9z"/>
</svg>

After

Width:  |  Height:  |  Size: 382 B

4
src/imports/mvvmquick/icons/ic_settings_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M19.43 12.98c.04-.32.07-.64.07-.98s-.03-.66-.07-.98l2.11-1.65c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.3-.61-.22l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.46 2.18 14.25 2 14 2h-4c-.25 0-.46.18-.49.42l-.38 2.65c-.61.25-1.17.59-1.69.98l-2.49-1c-.23-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64l2.11 1.65c-.04.32-.07.65-.07.98s.03.66.07.98l-2.11 1.65c-.19.15-.24.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.03.24.24.42.49.42h4c.25 0 .46-.18.49-.42l.38-2.65c.61-.25 1.17-.59 1.69-.98l2.49 1c.23.09.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.65zM12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z"/>
</svg>

After

Width:  |  Height:  |  Size: 836 B

7
src/imports/mvvmquick/mvvmquick.pro

@ -23,10 +23,15 @@ QML_FILES += \
PopupPresenter.qml \
DialogPresenter.qml \
TintIcon.qml \
ActionButton.qml \
MsgBoxBase.qml \
MsgBox.qml \
InputDialog.qml \
PresentingDrawer.qml
PresentingDrawer.qml \
ListSection.qml \
SectionListView.qml \
OverviewListView.qml
RESOURCES += \
qtmvvmquick_plugin.qrc

20
src/imports/mvvmquick/plugins.qmltypes

@ -32,12 +32,28 @@ Module {
Parameter { name: "viewProperties"; type: "QVariantMap" }
}
Method {
name: "addSimpleView"
name: "getDelegate"
type: "QUrl"
Parameter { name: "type"; type: "QByteArray" }
Parameter { name: "viewProperties"; type: "QVariantMap" }
}
Method {
name: "addSimpleInput"
Parameter { name: "type"; type: "QByteArray" }
Parameter { name: "qmlFileUrl"; type: "QUrl" }
}
Method {
name: "addAlias"
name: "addSimpleDelegate"
Parameter { name: "type"; type: "QByteArray" }
Parameter { name: "qmlFileUrl"; type: "QUrl" }
}
Method {
name: "addInputAlias"
Parameter { name: "alias"; type: "QByteArray" }
Parameter { name: "targetType"; type: "QByteArray" }
}
Method {
name: "addDelegateAlias"
Parameter { name: "alias"; type: "QByteArray" }
Parameter { name: "targetType"; type: "QByteArray" }
}

6
src/imports/mvvmquick/qmldir

@ -8,6 +8,12 @@ internal MsgBoxBase MsgBoxBase.qml
internal MsgBox MsgBox.qml
internal InputDialog InputDialog.qml
internal ListSection ListSection.qml
internal SectionListView SectionListView.qml
internal OverviewListView OverviewListView.qml
ActionButton 1.0 ActionButton.qml
PresenterProgress 1.0 PresenterProgress.qml
PresentingStackView 1.0 PresentingStackView.qml
PopupPresenter 1.0 PopupPresenter.qml

1
src/imports/mvvmquick/qtmvvmquick_plugin.cpp

@ -41,6 +41,7 @@ void QtMvvmQuickDeclarativeModule::registerTypes(const char *uri)
qmlRegisterType(QUrl(QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/qml/FileDialog.qml")), uri, 1, 0, "FileDialog");
qmlRegisterType(QUrl(QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/qml/FolderDialog.qml")), uri, 1, 0, "FolderDialog");
qmlRegisterType(QUrl(QStringLiteral("qrc:/qtmvvm/views/SettingsView.qml")), uri, 1, 0, "SettingsView");
#ifdef Q_OS_ANDROID
qmlRegisterType<QtMvvm::AndroidFileChooser>(uri, 1, 0, "FileChooser");

10
src/imports/mvvmquick/qtmvvmquick_plugin.qrc

@ -4,6 +4,10 @@
<file alias="ic_help.svg">icons/ic_help_white_24px.svg</file>
<file alias="ic_info.svg">icons/ic_info_white_24px.svg</file>
<file alias="ic_warning.svg">icons/ic_warning_white_24px.svg</file>
<file alias="ic_arrow_back.svg">icons/ic_arrow_back_white_24px.svg</file>
<file alias="ic_close.svg">icons/ic_close_white_24px.svg</file>
<file alias="ic_search.svg">icons/ic_search_white_24px.svg</file>
<file alias="ic_settings_backup_restore.svg">icons/ic_settings_backup_restore_white_24px.svg</file>
</qresource>
<qresource prefix="/de/skycoder42/qtmvvm/quick/qml">
<file>FileDialog.qml</file>
@ -11,4 +15,10 @@
<file alias="+android/FileDialog.qml">AndroidFileDialog.qml</file>
<file alias="+android/FolderDialog.qml">AndroidFolderDialog.qml</file>
</qresource>
<qresource prefix="/qtmvvm/views">
<file>SettingsView.qml</file>
</qresource>
<qresource prefix="/de/skycoder42/qtmvvm/icons">
<file alias="settings.svg">icons/ic_settings_white_24px.svg</file>
</qresource>
</RCC>

2
src/mvvmcore/serviceregistry.cpp

@ -15,6 +15,8 @@ ServiceRegistry::ServiceRegistry(ServiceRegistryPrivate *d_ptr) :
d(d_ptr)
{}
ServiceRegistry::~ServiceRegistry() {}
ServiceRegistry *ServiceRegistry::instance()
{
return _instance;

1
src/mvvmcore/serviceregistry.h

@ -16,6 +16,7 @@ class Q_MVVMCORE_EXPORT ServiceRegistry
{
public:
ServiceRegistry(ServiceRegistryPrivate *d_ptr);
~ServiceRegistry();
static ServiceRegistry* instance();

2
src/mvvmcore/settingssetuploader.cpp

@ -21,7 +21,7 @@ using namespace QtMvvm::SettingsElements;
SettingsSetupLoader::SettingsSetupLoader(QObject *parent) :
QObject(parent),
_defaultIcon(QStringLiteral("qrc:/qtmvvm/icons/settings.svg")),
_defaultIcon(QStringLiteral("qrc:/de/skycoder42/qtmvvm/icons/settings.svg")),
_cache()
{}

46
src/mvvmquick/BoolDelegate.qml

@ -0,0 +1,46 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
CheckDelegate {
id: _boolDelegate
text: title
Component.onCompleted: checked = settingsValue;
onCheckedChanged: settingsValue = checked;
contentItem: GridLayout {
columns: 2
rows: 2
Label {
id: _titleLabel
text: _boolDelegate.text
Layout.row: 0
Layout.column: 0
font.bold: true
elide: Label.ElideRight
Layout.fillWidth: true
}
Label {
id: _textLabel
visible: tooltip
Layout.row: 1
Layout.column: 0
text: tooltip
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
Item {
Layout.row: 0
Layout.column: 1
Layout.rowSpan: 2
Layout.minimumWidth: implicitWidth
Layout.maximumWidth: implicitWidth
implicitWidth: _boolDelegate.indicator.width + 14
}
}
}

29
src/mvvmquick/MsgDelegate.qml

@ -0,0 +1,29 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
ItemDelegate {
id: _msgDelegate
text: title
contentItem: ColumnLayout {
Label {
id: _titleLabel
text: _msgDelegate.text
font.bold: true
elide: Label.ElideRight
Layout.fillWidth: true
}
Label {
id: _textLabel
visible: tooltip
text: tooltip
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
}
onClicked: showInputDialog = true
}

46
src/mvvmquick/SwitchDelegate.qml

@ -0,0 +1,46 @@
import QtQuick 2.10
import QtQuick.Controls 2.3 as Controls
import QtQuick.Layouts 1.3
Controls.SwitchDelegate {
id: _boolDelegate
text: title
Component.onCompleted: checked = settingsValue;
onCheckedChanged: settingsValue = checked;
contentItem: GridLayout {
columns: 2
rows: 2
Controls.Label {
id: _titleLabel
text: _boolDelegate.text
Layout.row: 0
Layout.column: 0
font.bold: true
elide: Label.ElideRight
Layout.fillWidth: true
}
Controls.Label {
id: _textLabel
visible: tooltip
Layout.row: 1
Layout.column: 0
text: tooltip
wrapMode: Text.WordWrap
Layout.fillWidth: true
}
Item {
Layout.row: 0
Layout.column: 1
Layout.rowSpan: 2
Layout.minimumWidth: implicitWidth
Layout.maximumWidth: implicitWidth
implicitWidth: _boolDelegate.indicator.width + 14
}
}
}

66
src/mvvmquick/inputviewfactory.cpp

@ -41,20 +41,20 @@ InputViewFactory::~InputViewFactory() {}
QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &viewProperties)
{
Q_UNUSED(viewProperties)
if(d->aliases.contains(type))
return getInputUrl(d->aliases.value(type), viewProperties);
if(d->simpleViews.contains(type))
return d->simpleViews.value(type);
if(d->inputAliases.contains(type))
return getInputUrl(d->inputAliases.value(type), viewProperties);
if(d->simpleInputs.contains(type))
return d->simpleInputs.value(type);
else if(type == QMetaType::typeName(QMetaType::Bool))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/CheckBox.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/CheckBox.qml");
else if(type == "switch")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/Switch.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/Switch.qml");
else if(type == QMetaType::typeName(QMetaType::QString) || type == "string")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/TextField.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/TextField.qml");
else if(type == QMetaType::typeName(QMetaType::Int))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/SpinBox.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/SpinBox.qml");
else if(type == QMetaType::typeName(QMetaType::Double))
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/DoubleSpinBox.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml");
// else if(type == QMetaType::typeName(QMetaType::QDate))
// return QUrl();
// else if(type == QMetaType::typeName(QMetaType::QTime))
@ -62,31 +62,61 @@ QUrl InputViewFactory::getInputUrl(const QByteArray &type, const QVariantMap &vi
// 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");
return QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml");
else if(type == QMetaType::typeName(QMetaType::QUrl) || type == "url")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/UrlField.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml");
else if(type == "selection" || type == "list")
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/quick/inputs/ListEdit.qml");
return QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml");
else {
logCritical() << "Failed to find any input view for input type:" << type;
return QUrl();
}
}
void InputViewFactory::addSimpleView(const QByteArray &type, const QUrl &qmlFileUrl)
QUrl InputViewFactory::getDelegate(const QByteArray &type, const QVariantMap &viewProperties)
{
d->simpleViews.insert(type, qmlFileUrl);
Q_UNUSED(viewProperties)
if(d->delegateAliases.contains(type))
return getDelegate(d->delegateAliases.value(type), viewProperties);
if(d->simpleDelegates.contains(type))
return d->simpleDelegates.value(type);
else if(type == QMetaType::typeName(QMetaType::Bool))
return QStringLiteral("qrc:/qtmvvm/delegates/BoolDelegate.qml");
else if(type == "switch")
return QStringLiteral("qrc:/qtmvvm/inputs/SwitchDelegate.qml");
//TODO add
// else if(type == "selection" || type == "list")
// return QStringLiteral("qrc:/qtmvvm/inputs/ListDelegate.qml");
else
return QStringLiteral("qrc:/qtmvvm/delegates/MsgDelegate.qml");
}
void InputViewFactory::addSimpleInput(const QByteArray &type, const QUrl &qmlFileUrl)
{
d->simpleInputs.insert(type, qmlFileUrl);
}
void InputViewFactory::addSimpleDelegate(const QByteArray &type, const QUrl &qmlFileUrl)
{
d->simpleDelegates.insert(type, qmlFileUrl);
}
void InputViewFactory::addInputAlias(const QByteArray &alias, const QByteArray &targetType)
{
d->inputAliases.insert(alias, targetType);
}
void InputViewFactory::addAlias(const QByteArray &alias, const QByteArray &targetType)
void InputViewFactory::addDelegateAlias(const QByteArray &alias, const QByteArray &targetType)
{
d->aliases.insert(alias, targetType);
d->delegateAliases.insert(alias, targetType);
}
// ------------- Private Implementation -------------
InputViewFactoryPrivate::InputViewFactoryPrivate() :
simpleViews(),
aliases()
simpleInputs(),
simpleDelegates(),
inputAliases(),
delegateAliases()
{}

37
src/mvvmquick/inputviewfactory.h

@ -20,29 +20,50 @@ public:
virtual ~InputViewFactory();
Q_INVOKABLE virtual QUrl getInputUrl(const QByteArray &type, const QVariantMap &viewProperties);
Q_INVOKABLE virtual QUrl getDelegate(const QByteArray &type, const QVariantMap &viewProperties);
Q_INVOKABLE virtual void addSimpleView(const QByteArray &type, const QUrl &qmlFileUrl);
Q_INVOKABLE virtual void addSimpleInput(const QByteArray &type, const QUrl &qmlFileUrl);
template <typename TType>
inline void addSimpleView(const QUrl &qmlFileUrl);
inline void addSimpleInput(const QUrl &qmlFileUrl);
Q_INVOKABLE virtual void addAlias(const QByteArray &alias, const QByteArray &targetType);
Q_INVOKABLE virtual void addSimpleDelegate(const QByteArray &type, const QUrl &qmlFileUrl);
template <typename TType>
inline void addSimpleDelegate(const QUrl &qmlFileUrl);
Q_INVOKABLE virtual void addInputAlias(const QByteArray &alias, const QByteArray &targetType);
template <typename TAliasType, typename TTargetType>
inline void addInputAlias();
Q_INVOKABLE virtual void addDelegateAlias(const QByteArray &alias, const QByteArray &targetType);
template <typename TAliasType, typename TTargetType>
inline void addAlias();
inline void addDelegateAlias();
private:
QScopedPointer<InputViewFactoryPrivate> d;
};
template<typename TType>
inline void InputViewFactory::addSimpleView(const QUrl &qmlFileUrl)
inline void InputViewFactory::addSimpleInput(const QUrl &qmlFileUrl)
{
addSimpleInput(QMetaType::typeName(qMetaTypeId<TType>()), qmlFileUrl);
}
template<typename TType>
void InputViewFactory::addSimpleDelegate(const QUrl &qmlFileUrl)
{
addSimpleDelegate(QMetaType::typeName(qMetaTypeId<TType>()), qmlFileUrl);
}
template<typename TAliasType, typename TTargetType>
inline void InputViewFactory::addInputAlias()
{
addSimpleView(QMetaType::typeName(qMetaTypeId<TType>()), qmlFileUrl);
addInputAlias(QMetaType::typeName(qMetaTypeId<TAliasType>()), QMetaType::typeName(qMetaTypeId<TTargetType>()));
}
template<typename TAliasType, typename TTargetType>
inline void InputViewFactory::addAlias()
void InputViewFactory::addDelegateAlias()
{
addAlias(QMetaType::typeName(qMetaTypeId<TAliasType>()), QMetaType::typeName(qMetaTypeId<TTargetType>()));
addDelegateAlias(QMetaType::typeName(qMetaTypeId<TAliasType>()), QMetaType::typeName(qMetaTypeId<TTargetType>()));
}
}

6
src/mvvmquick/inputviewfactory_p.h

@ -11,8 +11,10 @@ class InputViewFactoryPrivate
public:
InputViewFactoryPrivate();
QHash<QByteArray, QUrl> simpleViews;
QHash<QByteArray, QByteArray> aliases;
QHash<QByteArray, QUrl> simpleInputs;
QHash<QByteArray, QUrl> simpleDelegates;
QHash<QByteArray, QByteArray> inputAliases;
QHash<QByteArray, QByteArray> delegateAliases;
};
}

7
src/mvvmquick/qtmvvmquick_module.qrc

@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/de/skycoder42/qtmvvm/quick/inputs">
<qresource prefix="/qtmvvm/inputs">
<file>ListEdit.qml</file>
<file>TextField.qml</file>
<file>SpinBox.qml</file>
@ -9,4 +9,9 @@
<file>UrlField.qml</file>
<file>Switch.qml</file>
</qresource>
<qresource prefix="/qtmvvm/delegates">
<file>BoolDelegate.qml</file>
<file>MsgDelegate.qml</file>
<file>SwitchDelegate.qml</file>
</qresource>
</RCC>

6
src/mvvmquick/quickpresenter.cpp

@ -88,13 +88,19 @@ QUrl QuickPresenter::findViewUrl(const QMetaObject *viewModelType)
return d->explicitMappings.value(currentMeta);
else {
QByteArray cName = currentMeta->className();
//strip viewmodel
auto lIndex = cName.lastIndexOf("ViewModel");
if(lIndex > 0)
cName.truncate(lIndex);
//strip namespaces
lIndex = cName.lastIndexOf("::");
if(lIndex > 0)
cName = cName.mid(lIndex + 2);
QUrl resUrl;
auto shortest = std::numeric_limits<int>::max();
for(auto dir : qAsConst(d->searchDirs)) {
logDebug() << QDir(dir).entryList();
QDir searchDir(dir,
QStringLiteral("%1*.qml").arg(QString::fromLatin1(cName)),
QDir::NoSort,

2
src/mvvmwidgets/qtmvvmwidgets_module.qrc

@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/qtmvvm/icons">
<qresource prefix="/de/skycoder42/qtmvvm/icons">
<file alias="settings.ico">setting_tools.ico</file>
</qresource>
</RCC>

2
src/mvvmwidgets/settingsdialog.cpp

@ -84,7 +84,7 @@ QString SettingsDialog::labelFilterStyleSheet() const
QUrl SettingsDialog::iconOverwrite() const
{
return QStringLiteral("qrc:/qtmvvm/icons/settings.ico");
return QStringLiteral("qrc:/de/skycoder42/qtmvvm/icons/settings.ico");
}
// ------------- Private Implementation -------------

Loading…
Cancel
Save