ModelView.qml 2.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

GridLayout{
    anchors.leftMargin: 5
    columnSpacing: 5
    rowSpacing: 5
    columns: 4
    rows: 4
11
    signal addClicked()
12
13
    property alias model : listView.model
    property alias currentItem : listView.currentItem
Leander Schulten's avatar
Leander Schulten committed
14
15
16
17
18
19
    property alias addButton: buttonAdd
    property alias removeButton: buttonRemove
    property alias addButtonEnabled: buttonAdd.enabled
    property alias removeButtonEnabled: buttonRemove.enabled
    property alias nameInputEnabled: textName.enabled
    property alias descriptionInputEnabled: textDescription.enabled
20
21
    property alias listView : listView

Leander Schulten's avatar
Leander Schulten committed
22

23
24
    ListView{
        Layout.fillHeight: true
Leander Schulten's avatar
Leander Schulten committed
25
        Layout.preferredWidth: Math.max(350,implicitWidth)
26
27
28
29
        Layout.columnSpan: 2
        Layout.rowSpan: parent.rows-1
        id:listView
        delegate: ItemDelegate{
30
            property var data: itemData
31
            width: parent.width
32
            text: itemData.name +"("+itemData.description+")"
33
34
35
36
37
38
39
            onClicked: listView.currentIndex = index

        }
        highlight: Rectangle{
            color: "blue"
            opacity: 0.7
        }
Leander Schulten's avatar
Leander Schulten committed
40

41
42
43
44
45
    }

    Button{
        Layout.row: parent.rows-1
        Layout.column: 0
46
        Layout.preferredWidth: listView.width/2
47
        id: buttonAdd
Leander Schulten's avatar
Leander Schulten committed
48
        text:"Add"
49
        font.pixelSize: 15
Leander Schulten's avatar
Leander Schulten committed
50
        onClicked: addClicked()
51
52
53
54
    }
    Button{
        Layout.row: parent.rows-1
        Layout.column: 1
55
        Layout.preferredWidth: listView.width/2
56
        id: buttonRemove
Leander Schulten's avatar
Leander Schulten committed
57
        text:"Remove"
58
        font.pixelSize: 15
59
        onClicked: ModelManager.remove(listView.currentItem.data)
60
61
62
    }


Leander Schulten's avatar
Leander Schulten committed
63
    Label{
64
65
66
67
68
69
70
71
72
73
        Layout.row: 0
        Layout.column: 2
        id:labelName
        text:"Name:"
    }
    TextInputField{
        Layout.row: 0
        Layout.column: 3
        Layout.fillWidth: true
        id:textName
Leander Schulten's avatar
Leander Schulten committed
74
        text: listView.currentItem?listView.currentItem.data.name:""
75
76
        onTextChanged: listView.currentItem.data.name = text
    }
Leander Schulten's avatar
Leander Schulten committed
77
    Label{
78
79
80
81
82
83
84
85
86
87
88
        Layout.row: 1
        Layout.column: 2
        id:labelDescription
        text:"Description:"

    }
    TextInputField{
        Layout.row: 1
        Layout.column: 3
        Layout.fillWidth: true
        id:textDescription
Leander Schulten's avatar
Leander Schulten committed
89
        text: listView.currentItem?listView.currentItem.data.description:""
90
91
92
93
94
95
        onTextChanged: listView.currentItem.data.description = text
    }



}