TG-PlatformPlus/qml/debug/hsvp/SettingSystem.qml

174 lines
5.6 KiB
QML
Raw Normal View History

2026-03-02 14:29:58 +08:00
import QtQuick
import QtQuick.Controls
import "./common"
Item{
property var deviceInfos: []
property var devModel: ListModel{}
property var interfaceModel: ListModel{}
Component.onCompleted: {
refreshDevices()
}
onVisibleChanged: if (visible) refreshDevices()
function refreshDevices()
{
deviceInfos = getDeviceInfo()
devModel.clear()
for (var i = 0; i < deviceInfos.length; i++)
{
console.info(typeof(deviceInfos[i].interface))
devModel.append({
"id": deviceInfos[i].id,
"name": deviceInfos[i].name,
"dev_model_id": deviceInfos[i].dev_model_id,
"interface": JSON.stringify(deviceInfos[i].interface),
})
}
initJsonModel(funcModel, "funcModel.json")
}
function getDeviceInfo()
{
return deviceManager.getInfo("all")
}
function getInterFaceName(id)
{
var interFaceInfos = interfaceManager.getInfo(id)
if(interFaceInfos.length > 0)
return interFaceInfos[0].name
return ""
}
function getInstructionInfo(dev_model_id)
{
return instructionManager.getDevmodelInstructions(dev_model_id)
}
Item{
anchors.fill: parent
clip: true
ListView{
id: funLstView
model: funcModel
header: table_func_header
boundsBehavior: Flickable.StopAtBounds
anchors.fill: parent
delegate: table_func_delegate
}
}
Component {
id: table_func_header
Rectangle {
width: funLstView.width
height: 40
color: "#F7F7F7"
z:2
Row {
width: parent.width
height: parent.height
property var childcount: 4
QxHLabel {
text: "功能"
width: parent.width/4
}
QxHLabel {
text: "设备"
width: parent.width/4
}
QxHLabel {
text: "接口"
width: parent.width/4
}
QxHLabel {
text: "指令"
width: parent.width/4
}
}
}
}
Component {
id: table_func_delegate
Rectangle {
width: funLstView.width
height: 58
color: index % 2 == 0 ? "#F8FAFF" : "#FFFFFF"
z:2
Row {
width: parent.width
height: parent.height
property var childcount: 4
QxLabel {
text: name
width: parent.width/4
}
SetComboBox {
id: cvDev
text: deviceName
cbmodel: devModel
width: parent.width/4
onCurrentIndexChanged: {
if(currentIndex != -1)
{
var devName = devModel.get(currentIndex).name
var dev_model_id = devModel.get(currentIndex).dev_model_id
deviceName = text
deviceId = devModel.get(currentIndex).id.toString()
var interfaces = JSON.parse(devModel.get(currentIndex).interface)
cbInterface.cbmodel.clear()
for(var i =0; i<interfaces.length; i++)
{
cbInterface.cbmodel.append({
"id": interfaces[i],
"name": getInterFaceName(interfaces[i])
})
}
cbInterface.selectItem(interfaceName)
cbCmd.cbmodel.clear()
var instructionInfo = getInstructionInfo(dev_model_id)
for(var i = 0; i < instructionInfo.length; i++)
{
cbCmd.cbmodel.append(instructionInfo[i])
}
cbCmd.selectItem(instructionName)
updateJsonFile(funcModel, "funcModel.json")
}
}
}
SetComboBox {
id: cbInterface
text: interfaceName
width: parent.width/4
onCurrentIndexChanged: {
if(currentIndex != -1)
{
interfaceName = text
interfaceId = cbmodel.get(currentIndex).id
interfaceIndex = currentIndex.toString()
updateJsonFile(funcModel, "funcModel.json")
}
}
}
SetComboBox {
id: cbCmd
text: instructionName
width: parent.width/4
onCurrentIndexChanged: {
if(currentIndex != -1)
{
instructionName = text
instructionId = cbCmd.cbmodel.get(currentIndex).id.toString()
updateJsonFile(funcModel, "funcModel.json")
}
}
}
}
}
}
}