/
Main.qml
77 lines (70 loc) · 1.91 KB
/
Main.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
ApplicationWindow {
width: 400
height: 550
visible: true
title: qsTr("QAbstractListModel Example")
PrintService {
id: printService
}
// Footer with input fields and buttons
footer: ToolBar {
RowLayout {
anchors.fill: parent
TextField {
id: nameField
placeholderText: "Name"
clip: true
Layout.fillWidth: true
}
TextField {
id: typeField
placeholderText: "Type"
clip: true
Layout.fillWidth: true
}
ToolButton {
text: "Add"
enabled: nameField.text.length > 0 && typeField.text.length > 0
onClicked: {
animalModel.push(nameField.text, typeField.text)
nameField.text = ""
typeField.text = ""
}
}
ToolButton {
text: "Print"
onClicked: {
console.log("-------------------------------------------")
animalModel.print()
printService.print(animalModel.getAnimalsForQML())
}
}
}
}
// List of animals and their types
ListView {
model: animalModel
anchors.fill: parent
delegate: RowLayout {
width: parent?.width
Text {
text: name + " (" + type + ")"
font.pixelSize: 24
color: "white"
}
Item {
Layout.fillWidth: true
}
ToolButton {
text: "x"
onClicked: {
animalModel.remove(index)
}
}
}
}
}