This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
powersync-app/nymea-app/ui/magic/SelectEventDescriptorParamsPage.qml
2025-12-05 13:40:20 +01:00

112 lines
4.9 KiB
QML

// SPDX-License-Identifier: GPL-3.0-or-later
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (C) 2013 - 2024, nymea GmbH
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
*
* This file is part of nymea-app.
*
* nymea-app is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* nymea-app is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with nymea-app. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Nymea
import "../components"
import "../delegates"
Page {
id: root
// Needs to be set and filled in with thingId and eventTypeId
property var eventDescriptor: null
readonly property Thing thing: eventDescriptor && eventDescriptor.thingId ? engine.thingManager.things.getThing(eventDescriptor.thingId) : null
readonly property var iface: eventDescriptor && eventDescriptor.interfaceName ? Interfaces.findByName(eventDescriptor.interfaceName) : null
readonly property EventType eventType: thing ? thing.thingClass.eventTypes.getEventType(eventDescriptor.eventTypeId)
: iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null
readonly property StateType stateType: thing ? thing.thingClass.stateTypes.getStateType(eventDescriptor.eventTypeId)
: iface ? iface.eventTypes.findByName(eventDescriptor.interfaceEvent) : null
signal backPressed();
signal completed();
header: NymeaHeader {
text: "Options"
onBackPressed: root.backPressed();
}
ColumnLayout {
anchors.fill: parent
Repeater {
id: delegateRepeater
model: root.eventType ? root.eventType.paramTypes : 1
delegate: ColumnLayout {
Layout.fillWidth: true
property alias paramType: paramDescriptorDelegate.paramType
property alias stateType: paramDescriptorDelegate.stateType
property alias value: paramDescriptorDelegate.value
property alias considerParam: paramCheckBox.checked
property alias operatorType: paramDescriptorDelegate.operatorType
CheckBox {
id: paramCheckBox
text: root.eventType ? qsTr("Only consider event if") : qsTr("Only consider state change if")
Layout.fillWidth: true
Layout.leftMargin: app.margins
Layout.rightMargin: app.margins
}
ParamDescriptorDelegate {
id: paramDescriptorDelegate
enabled: paramCheckBox.checked
Layout.fillWidth: true
paramType: root.eventType ? root.eventType.paramTypes.get(index) : null
stateType: root.stateType
value: paramType ? paramType.defaultValue : stateType.defaultValue
}
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
}
Button {
text: "OK"
Layout.fillWidth: true
Layout.margins: app.margins
onClicked: {
root.eventDescriptor.paramDescriptors.clear();
for (var i = 0; i < delegateRepeater.count; i++) {
var paramDelegate = delegateRepeater.itemAt(i);
if (paramDelegate.considerParam) {
if (root.thing) {
var paramTypeId = paramDelegate.paramType ? paramDelegate.paramType.id : paramDelegate.stateType.id
print("setting param descriptor by id:", paramTypeId, paramDelegate.value)
root.eventDescriptor.paramDescriptors.setParamDescriptor(paramTypeId, paramDelegate.value, paramDelegate.operatorType)
} else if (root.iface) {
var name = root.eventType ? root.eventType.paramTypes.get(i).name : root.stateType.name
print("setting param descriptors by name", name, paramDelegate.value)
root.eventDescriptor.paramDescriptors.setParamDescriptorByName(name, paramDelegate.value, paramDelegate.operatorType)
}
}
}
root.completed()
}
}
}
}