DeviceView.qml 6.72 KB
Newer Older
Leander Schulten's avatar
Leander Schulten committed
1
2
3
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
4
import QtQuick.Dialogs 1.2
Leander Schulten's avatar
Leander Schulten committed
5
import custom.licht 1.0
Leander Schulten's avatar
Leander Schulten committed
6
import "components"
Leander Schulten's avatar
Leander Schulten committed
7

8
ModelView{
9
    id: deviceModelView
10
    model: deviceModel
11
    nameFunction: function(modelData){return modelData.name + ", Channel: " + modelData.startDMXChannel + (modelData.prototype.numberOfChannels > 1 ? " - " + (modelData.startDMXChannel + modelData.prototype.numberOfChannels - 1) : "");}
12
    rows: 7
13
14
    onAddClicked: dialog.visible = true
    onRemoveClicked: ModelManager.removeDmxDevice(remove);
Leander Schulten's avatar
Leander Schulten committed
15
16
17
18
19
20
    addButtonEnabled: UserManagment.currentUser.havePermission(Permission.ADD_DEVICE)
    removeButtonEnabled: UserManagment.currentUser.havePermission(Permission.REMOVE_DEVICE)
    nameInputEnabled: UserManagment.currentUser.havePermission(Permission.CHANGE_NAME)
    descriptionInputEnabled: UserManagment.currentUser.havePermission(Permission.CHANGE_NAME)
    addButton.text: "Add Device"
    removeButton.text: "Remove Device"
21
    property var placeOnMapCallback
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    sortModel: ListModel{
        ListElement{
            name: "Creation Date"
            sortPropertyName: ""
        }
        ListElement{
            name: "DMX Channel"
            sortPropertyName: "startDMXChannel"
        }
        ListElement{
            name: "Name"
            sortPropertyName: "name"
        }
        ListElement{
            name: "Prototype Name"
            sortPropertyName: "prototype.name"
        }
    }
Leander Schulten's avatar
Leander Schulten committed
40

41
42
43
44
45
46
47
48
49
50
    Text{
        Layout.row: 2
        Layout.column: 2
        text:"startDMXChannel:"
        Layout.rightMargin: 20
        font.pixelSize: 15
    }
    TextInputField{
        Layout.row: 2
        Layout.column: 3
Leander Schulten's avatar
Leander Schulten committed
51
        enabled: UserManagment.currentUser.havePermission(Permission.CHANGE_DEVICE_DMX_CHANNEL);
52
        text: parent.currentModelData ? parent.currentModelData.startDMXChannel : ""
53
54
55
        validator: IntValidator{
            bottom: 0
            top:512
Leander Schulten's avatar
Leander Schulten committed
56
        }
57
        onTextChanged: if(parent.currentModelData) parent.currentModelData.startDMXChannel = text.length?text:0
Leander Schulten's avatar
Leander Schulten committed
58
    }
59
60
61
62
63
64
65
66
67
68
    Text{
        Layout.row: 3
        Layout.column: 2
        text:"DevicePrototype:"
        Layout.rightMargin: 20
        font.pixelSize: 15
    }
    Text{
        Layout.row: 3
        Layout.column: 3
69
        text: parent.currentModelData ? parent.currentModelData.prototype.name : ""
70
        font.pixelSize: 15
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
        TextUnderline{
            extendetWidth:1
            color:"lightgrey"
        }
    }
    Text{
        Layout.row: 4
        Layout.column: 2
        text:"Position:"
        Layout.rightMargin: 20
        font.pixelSize: 15
    }
    RowLayout{
        Layout.row: 4
        Layout.column: 3
        Text{
            text:"x:"
            font.pixelSize: 15
        }
        TextInputField{
Leander Schulten's avatar
Leander Schulten committed
91
            enabled: UserManagment.currentUser.havePermission(Permission.CHANGE_POSITION);
92
            Layout.minimumWidth: 40
93
            text:deviceModelView.currentModelData ? deviceModelView.currentModelData.position.x : ""
94
            validator: IntValidator{}
95
            onTextChanged: if(deviceModelView.currentModelData) deviceModelView.currentModelData.position.x = text.length?text:0
96
97
98
99
100
101
102
        }
        Text{
            Layout.leftMargin: 10
            text:"y:"
            font.pixelSize: 15
        }
        TextInputField{
Leander Schulten's avatar
Leander Schulten committed
103
            enabled: UserManagment.currentUser.havePermission(Permission.CHANGE_POSITION);
104
            Layout.minimumWidth: 40
105
            text: deviceModelView.currentModelData ? deviceModelView.currentModelData.position.y : ""
106
            validator: IntValidator{}
107
            onTextChanged: if(deviceModelView.currentModelData) deviceModelView.currentModelData.position.y = text.length?text:0
108
        }
109
        Button{
110
            enabled: UserManagment.currentUser.havePermission(Permission.CHANGE_POSITION);
111
            visible: deviceModelView.currentModelData ? deviceModelView.placeOnMapCallback && deviceModelView.currentModelData.position.x === -1 || deviceModelView.currentModelData.position.x === -1 : false
112
            text: "Place on map"
113
            onClicked: deviceModelView.placeOnMapCallback(deviceModelView.currentModelData)
114
115
            height: implicitHeight - 15
        }
116
    }
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

    Dialog{
        modality: Qt.WindowModal
        id:dialog
        title: "Hallo"
        width:300
        contentItem: RowLayout {
            Pane{
                Layout.fillWidth: true
                ColumnLayout{
                    anchors.left: parent.left
                    anchors.right: parent.right
                    spacing: 10
                    ComboBox{
                        Layout.fillWidth: true
                        id:prototype
                        model: devicePrototypeModel
                        textRole: "display"
                    }
                    RowLayout{
                        Label{
                            id:nameLabel
                            text:"Name :"
                        }
                        TextInputField{
                            Layout.fillWidth: true
                            id:name
                        }
                    }
                    RowLayout{
                        Label{
                            text:"Description :"
                        }
                        TextInputField{
                            Layout.fillWidth: true
                            id:description
                        }
                    }
                    RowLayout{
                        Label{
                            text:"Start DMX Channel :"
                        }
                        TextInputField{
                            Layout.fillWidth: true
                            id:dmx
                            validator: IntValidator{
                            bottom: 0
                            top:1024
                            }
                        }
                    }
                    RowLayout{
                        Button{
                            Layout.fillWidth: true
                            text:"Abbrechen"
                            onClicked: dialog.visible = false
                        }
                        Button{
                            Layout.fillWidth: true
                            text:"Erzeugen"
                            onClicked: {
                                if(name.text===""){
                                    name.underlineColor = "red";
                                }else{
                                    dialog.visible = false;
                                    ModelManager.addDevice(prototype.currentIndex,dmx.text,name.text,description.text);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

192
}