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

204 lines
6.3 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: {
deviceInfos = getDeviceInfo()
devModel.clear()
for (var i = 0; i < deviceInfos.length; i++)
{
devModel.append({
"id": deviceInfos[i].id,
"name": deviceInfos[i].name,
"dev_model_id": deviceInfos[i].dev_model_id,
"interface": deviceInfos[i].interface,
})
}
var data = get_json("function.json")
for(var i = 0; i < data.infos.length; i++)
{
funcModel.append(data.infos[i])
}
}
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)
}
function updateJson()
{
var data = []
for(var i = 0; i < funcModel.count; i++)
{
var item = funcModel.get(i)
data.push({
"name": item.name,
"deviceName": item.deviceName,
"deviceId": item.deviceId,
"interfaceName": item.interfaceName,
"interfaceId": item.interfaceId,
"interfaceIndex": item.interfaceIndex,
"instructionName": item.instructionName,
"instructionId": item.instructionId
})
}
save_json("function.json", {"infos":data})
}
GroupBox{
width: parent.width
height: 200
ListView{
model: funcModel
header: table_func_header
interactive: false
anchors.fill: parent
delegate: table_func_delegate
}
}
Component {
id: table_func_header
Rectangle {
width: parent ? parent.width : 0
height: 30
color: "#f0f0f0"
z:2
Row {
width: parent.width
height: parent.height
property var childcount: 4
QxLabel {
text: "功能"
width: parent.width/4
}
QxLabel {
text: "设备"
width: parent.width/4
}
QxLabel {
text: "接口"
width: parent.width/4
}
QxLabel {
text: "指令"
width: parent.width/4
}
}
Rectangle{
color:"#222"
width: 1
height: parent.height
z: 1
}
}
}
Component {
id: table_func_delegate
Rectangle {
width: parent ? parent.width : 0
height: 30
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)
updateJson()
}
}
}
SetComboBox {
id: cbInterface
text: interfaceName
width: parent.width/4
onCurrentIndexChanged: {
if(currentIndex > -1)
{
interfaceName = text
interfaceId = cbmodel.get(currentIndex).id
interfaceIndex = currentIndex.toString()
updateJson()
}
}
}
SetComboBox {
id: cbCmd
text: instructionName
width: parent.width/4
onCurrentIndexChanged: {
if(currentIndex > -1)
{
instructionName = text
instructionId = cbCmd.cbmodel.get(currentIndex).id.toString()
updateJson()
}
}
}
}
Rectangle{
color:"#222"
width: 1
height: parent.height
z: 1
}
}
}
}