Choice model settings was added
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import Components 1.0
|
||||
import ru.ded.beerlog 1.0
|
||||
|
||||
Page {
|
||||
id: root
|
||||
|
||||
title: qsTr("Settings")
|
||||
|
||||
ListModel {
|
||||
property var controls: {
|
||||
"text": textComponent,
|
||||
"choice": choiceComponent
|
||||
}
|
||||
|
||||
SettingsViewModel {
|
||||
id: settingsModel
|
||||
|
||||
ListElement {
|
||||
title: qsTr("BeerLog service address")
|
||||
name: "serverAddress"
|
||||
}
|
||||
|
||||
ListElement {
|
||||
title: qsTr("Selected user id")
|
||||
name: "selectedUserId"
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
@@ -35,6 +31,8 @@ Page {
|
||||
onClicked: {
|
||||
inputDialog.title = model.title
|
||||
inputDialog.name = model.name
|
||||
inputDialog.control = controls[model.control]
|
||||
inputDialog.choiceModel = model.choiceModel
|
||||
inputDialog.open()
|
||||
}
|
||||
}
|
||||
@@ -44,6 +42,8 @@ Page {
|
||||
id: inputDialog
|
||||
|
||||
property string name: ""
|
||||
property var choiceModel: undefined
|
||||
property alias control: editor.sourceComponent
|
||||
|
||||
width: root.width * 0.8
|
||||
|
||||
@@ -53,22 +53,54 @@ Page {
|
||||
modal: true
|
||||
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
Loader {
|
||||
id: editor
|
||||
|
||||
property var value: item && item.value
|
||||
|
||||
anchors.fill: parent
|
||||
|
||||
TextField {
|
||||
id: textField
|
||||
|
||||
width: parent.width
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase
|
||||
placeholderText: inputDialog.title
|
||||
text: settingsService[inputDialog.name] || ""
|
||||
}
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
settingsService[inputDialog.name] = textField.text
|
||||
settingsService[inputDialog.name] = editor.value
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: textComponent
|
||||
|
||||
TextField {
|
||||
id: textField
|
||||
|
||||
property alias value: textField.text
|
||||
|
||||
inputMethodHints: Qt.ImhNoAutoUppercase
|
||||
text: settingsService[inputDialog.name] || ""
|
||||
}
|
||||
}
|
||||
|
||||
ButtonGroup {
|
||||
id: group
|
||||
}
|
||||
|
||||
Component {
|
||||
id: choiceComponent
|
||||
|
||||
Column {
|
||||
|
||||
property var value: group.checkedButton && group.checkedButton.valueId
|
||||
|
||||
Repeater {
|
||||
model: inputDialog.choiceModel
|
||||
|
||||
delegate: RadioDelegate {
|
||||
property var valueId: modelData.id
|
||||
text: modelData.name
|
||||
width: parent.width
|
||||
checked: settingsService[inputDialog.name] === valueId
|
||||
ButtonGroup.group: group
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user