Event: reset values on editing start
This commit is contained in:
parent
1eee2fc2b5
commit
4ef0c49825
2 changed files with 13 additions and 16 deletions
24
Event.qml
24
Event.qml
|
@ -8,6 +8,8 @@ import 'util.js' as Util
|
||||||
|
|
||||||
// This is the delegate for event list items.
|
// This is the delegate for event list items.
|
||||||
ItemDelegate {
|
ItemDelegate {
|
||||||
|
id: control
|
||||||
|
|
||||||
required property var model
|
required property var model
|
||||||
required property int index
|
required property int index
|
||||||
required property int time
|
required property int time
|
||||||
|
@ -29,15 +31,6 @@ ItemDelegate {
|
||||||
radius: border.width
|
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.
|
// Store current inputs in model.
|
||||||
function store() {
|
function store() {
|
||||||
var values = {}
|
var values = {}
|
||||||
|
@ -46,7 +39,6 @@ ItemDelegate {
|
||||||
model.values = values
|
model.values = values
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: reset()
|
|
||||||
onEditingChanged: {
|
onEditingChanged: {
|
||||||
if (editing)
|
if (editing)
|
||||||
forceActiveFocus()
|
forceActiveFocus()
|
||||||
|
@ -75,7 +67,7 @@ ItemDelegate {
|
||||||
var str = ''
|
var str = ''
|
||||||
for (var i = 0; i < inputs.count; i++) {
|
for (var i = 0; i < inputs.count; i++) {
|
||||||
const field = inputs.model[i]
|
const field = inputs.model[i]
|
||||||
const value = inputs.itemAt(i).item.value
|
const value = model.values[field.name]
|
||||||
if (value && field.type !== 'TextArea')
|
if (value && field.type !== 'TextArea')
|
||||||
str += (field.type === 'Bool' ? field.name : value) + ' '
|
str += (field.type === 'Bool' ? field.name : value) + ' '
|
||||||
}
|
}
|
||||||
|
@ -88,7 +80,7 @@ ItemDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event‐specific input fields.
|
// Inputs for event‐specific fields.
|
||||||
GridLayout {
|
GridLayout {
|
||||||
flow: GridLayout.TopToBottom
|
flow: GridLayout.TopToBottom
|
||||||
rows: inputs.count
|
rows: inputs.count
|
||||||
|
@ -110,8 +102,16 @@ ItemDelegate {
|
||||||
id: inputs
|
id: inputs
|
||||||
delegate: Loader {
|
delegate: Loader {
|
||||||
source: 'qrc:/Fields/' + modelData.type + '.qml'
|
source: 'qrc:/Fields/' + modelData.type + '.qml'
|
||||||
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: 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 {
|
Binding {
|
||||||
target: item; property: 'model'
|
target: item; property: 'model'
|
||||||
value: modelData
|
value: modelData
|
||||||
|
|
|
@ -183,10 +183,7 @@ Page {
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case Qt.Key_Escape:
|
case Qt.Key_Escape:
|
||||||
if (editing) {
|
editing = false
|
||||||
currentItem.reset()
|
|
||||||
editing = false
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
case Qt.Key_Delete:
|
case Qt.Key_Delete:
|
||||||
editing = false
|
editing = false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue