Event: reset values on editing start

This commit is contained in:
Timotej Lazar 2021-09-11 17:16:57 +02:00
parent 1eee2fc2b5
commit 4ef0c49825
No known key found for this signature in database
GPG key ID: B6F38793D143456F
2 changed files with 13 additions and 16 deletions

View file

@ -8,6 +8,8 @@ import 'util.js' as Util
// This is the delegate for event list items.
ItemDelegate {
id: control
required property var model
required property int index
required property int time
@ -29,15 +31,6 @@ ItemDelegate {
radius: border.width
}
// Set inputs to current model values.
function reset() {
for (var i = 0; i < fields.length; i++) {
const child = inputs.itemAt(i)
if (child && child.item)
child.item.set(model.values[fields[i].name])
}
}
// Store current inputs in model.
function store() {
var values = {}
@ -46,7 +39,6 @@ ItemDelegate {
model.values = values
}
Component.onCompleted: reset()
onEditingChanged: {
if (editing)
forceActiveFocus()
@ -75,7 +67,7 @@ ItemDelegate {
var str = ''
for (var i = 0; i < inputs.count; i++) {
const field = inputs.model[i]
const value = inputs.itemAt(i).item.value
const value = model.values[field.name]
if (value && field.type !== 'TextArea')
str += (field.type === 'Bool' ? field.name : value) + ' '
}
@ -88,7 +80,7 @@ ItemDelegate {
}
}
// Eventspecific input fields.
// Inputs for eventspecific fields.
GridLayout {
flow: GridLayout.TopToBottom
rows: inputs.count
@ -110,8 +102,16 @@ ItemDelegate {
id: inputs
delegate: Loader {
source: 'qrc:/Fields/' + modelData.type + '.qml'
Layout.fillHeight: true
Layout.fillWidth: true
// Set input value to what is in the model each time the control is expanded.
onVisibleChanged: {
if (item && visible)
item.set(control.model.values[modelData.name])
}
Binding {
target: item; property: 'model'
value: modelData

View file

@ -183,10 +183,7 @@ Page {
}
break
case Qt.Key_Escape:
if (editing) {
currentItem.reset()
editing = false
}
editing = false
break
case Qt.Key_Delete:
editing = false