forked from Sorong/Smarrium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
230 lines (210 loc) · 8.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
import QtQuick.Layouts 1.3
import SensorBaseType 1.0
Window {
id: window
property alias sensorListPane: sensorListPane
width: 1920
height: 1080
visible: true
title: qsTr("Smarrium")
ColumnLayout {
id: layout
anchors.fill: parent
spacing: 10
Rectangle {
id: header
color: 'azure'
anchors.top: parent.top
anchors.left: layout.left
anchors.right: layout.right
Layout.fillWidth: true
Layout.preferredHeight: 80
Text {
anchors.centerIn: parent
text: "Smarriumkonfigurator"
lineHeight: 1
}
}
Rectangle {
id: actorCreatorPane
anchors.top: header.bottom
anchors.left: header.left
anchors.right: header.right
Layout.fillWidth: true
Layout.preferredHeight: 100
border.width: 1
//color: "blue"
Row {
id: switches
Component.onCompleted: function() {
var names = ["1", "2", "3", "4", "5", "A", "B","C", "D", "E"]
for(var i = 0; i < names.length; i++) {
var component = Qt.createComponent("uicomponents/_actuatorcreator.qml")
if (component.status === Component.Ready)
var sw = component.createObject(switches);
sw.text = qsTr(names[i])
}
}
}
RoundButton {
id: addActor
anchors.topMargin: 20
anchors.verticalCenter: parent.verticalCenter
anchors.left: switches.right
anchors.leftMargin: 10
spacing: 7
icon { source:"/icons/svg/ic_add_48px.svg"}
onClicked: function() {
var list = []
for(var i = 0; i < switches.children.length; i++) {
list.push(switches.children[i].checked)
}
actuatorFactory.addActuator(list)
actorConfiguratorPane.reload()
}
}
}
Rectangle {
id: sensorCreatorPane
anchors.top: actorCreatorPane.bottom
anchors.left: actorCreatorPane.left
anchors.right: actorCreatorPane.right
Layout.fillWidth: true
Layout.preferredHeight: 100
border.width: 1
//color: "blue"
Component.onCompleted: function() {
var component = Qt.createComponent("uicomponents/_sensorcreator.qml")
if (component.status === Component.Ready)
component.createObject(sensorCreatorPane);
}
}
Rectangle {
id: actorConfiguratorPane
anchors.top: sensorCreatorPane.bottom
anchors.left: sensorCreatorPane.left
anchors.right: sensorCreatorPane.right
Layout.fillWidth: true
Layout.preferredHeight: 100
property var reload : function() {
if(actorSelect.model.rowCount() > 0) {
actorSelect.currentIndex = 0;
}
if(sensorAdd.model.rowCount() > 0) {
sensorAdd.currentIndex = 0;
}
}
Column {
ComboBox {
id: actorSelect
width: actorConfiguratorPane.width
textRole: "code"
model: actuators
onCurrentIndexChanged: function() {
if(currentIndex >= 0) {
model.selectActuator(currentIndex);
console.log("sensorList.model")
sensorList.model = selectedSensors
}
}
Component.onCompleted: onCurrentIndexChanged()
}
Row {
ComboBox {
id: sensorAdd
width: actorConfiguratorPane.width - addSensor.width
textRole: "name"
model: sensors
delegate: ItemDelegate {
text: name
width: parent.width
onClicked: function() {
addSensor.uuid = uuid;
addSensor.config = configFactory.getConfig(type);
}
Component.onCompleted: this.onClicked()
}
}
RoundButton {
id: addSensor
property string uuid: ""
property string config: ""
anchors.bottom: parent.bottom
icon { source:"/icons/svg/ic_add_48px.svg"}
onClicked: function() {
if(this.uuid === "" || this.config === "") {
return;
}
sensors.selectSensor(sensorAdd.currentIndex);
actuatorFactory.createActuatorConfig(this.uuid, this.config);
if(selectedSensors !== undefined) {
sensorList.model = selectedSensors
}
}
}
}
}
}
Rectangle {
id: sensorListPane
anchors.top: actorConfiguratorPane.bottom
//anchors.fill: parent
//anchors.bottom: window.bottom
anchors.topMargin: 20
anchors.left: actorConfiguratorPane.left
anchors.right: actorConfiguratorPane.right
Layout.fillHeight: true
ListView {
id: sensorList
anchors.fill: parent
ScrollBar.vertical: ScrollBar {
id: sensorListScrollBar
policy: ScrollBar.AlwaysOn
}
delegate: Rectangle {
height: sensorListPane.height * 0.5
Component.onCompleted: function() {
var component = undefined;
switch (type) {
case SensorBaseType.UV:
component = Qt.createComponent("uicomponents/sensorviews/uv.qml")
break;
case SensorBaseType.LUX:
component =Qt.createComponent("uicomponents/sensorviews/lux.qml")
break;
case SensorBaseType.REL_HUMIDITY:
component = Qt.createComponent("uicomponents/sensorviews/relhumidity.qml")
break;
case SensorBaseType.SUBSTRAT_HUMIDITY:
component = Qt.createComponent("uicomponents/sensorviews/substrathumidity.qml")
break;
case SensorBaseType.TEMPERATURE:
component = Qt.createComponent("uicomponents/sensorviews/temperature.qml")
break;
case SensorBaseType.CLOCK:
component = Qt.createComponent("uicomponents/sensorviews/clock.qml")
break;
case SensorBaseType.CAMERA:
component = Qt.createComponent("uicomponents/sensorviews/camera.qml")
break;
default:
break;
}
if (component && component.status === Component.Ready) {
console.log("vor createObject")
component.createObject(this);
console.log("createObject")
}
}
// }
// }
// }
}
}
}
}
}