import QtQuick 2.15 import QtQuick.Layouts 1.3 import QtQuick.Controls 1.2 //import QtQuick 2.11 //import QtQuick.Layouts 1.3 //import QtQuick.Controls 2.14 //import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.4 import Qt.labs.qmlmodels 1.0 //import QtQuick.LocalStorage 2.0 //import io.qt.DataBaseModel 1.0 import Qt.labs.platform 1.1 import TService 1.0 Item { id: root property var pagetype:rootitem.Page_Type_Testing property string title_str:"PID 参数整定" property var volume: [0,0,0,0,0] property var keeptime: [0,0,0,0,0] property var outermax: [0.0, 0.0, 0.0, 0.0, 0.0] property var outermini: [0.0, 0.0, 0.0, 0.0, 0.0] property var outerKp: [0.0, 0.0, 0.0, 0.0, 0.0] property var outerKi: [0.0, 0.0, 0.0, 0.0, 0.0] property var outerKd: [0.0, 0.0, 0.0, 0.0, 0.0] property var innermax: [0.0, 0.0, 0.0, 0.0, 0.0] property var innermini: [0.0, 0.0, 0.0, 0.0, 0.0] property var innerKp: [0.0, 0.0, 0.0, 0.0, 0.0] property var innerKi: [0.0, 0.0, 0.0, 0.0, 0.0] property var innerKd: [0.0, 0.0, 0.0, 0.0, 0.0] property var innermaxI: [0.0, 0.0, 0.0, 0.0, 0.0] property var innermaxIstep: [0.0, 0.0, 0.0, 0.0, 0.0] property var innermaxDstep: [0.0, 0.0, 0.0, 0.0, 0.0] property string background: "#d7e3bc" property string alterBackground: "white" property string highlight: "#e4f7d6" property string headerBkgnd: "#F0F0F0" property var normalG: Gradient { GradientStop { position: 0.0; color: "#c7d3ac" } GradientStop { position: 1.0; color: "#F0F0F0" } } property var hoverG: Gradient { GradientStop { position: 0.0; color: "white"; } GradientStop { position: 1.0; color: "#d7e3bc"; } } property var pressG: Gradient { GradientStop { position: 0.0; color: "#d7e3bc"; } GradientStop { position: 1.0; color: "white"; } } function set_paras(){ var Jsonobj={} var itemArrayJson=[] var j=0; for(var i = 0; i 0){ var item={} item.max_volume = row_record.volume item.keep_time = row_record.time item.outermax = row_record.out_max item.outermin = row_record.out_min item.outerkp = row_record.out_kp item.outerki = row_record.out_ki item.outerkd = row_record.out_kd item.innermax = row_record.inner_max item.innermin =row_record.inner_min item.innerkp = row_record.inner_kp item.innerki = row_record.inner_ki item.innerkd = row_record.inner_kd item.innermaxI = row_record.inner_maxI item.innerIstep = row_record.inner_maxIstep item.innerDstep = row_record.inner_maxDstep itemArrayJson[j] = item j++ } } Jsonobj.pids = itemArrayJson CalibrationPara.set_paras(JSON.stringify(Jsonobj) ); } function update_paras(index, item){ param_model.append({ "idx":index, "volume":item.max_volume, "time":item.keep_time, "out_max":item.outermax, "out_min":item.outermin, "out_kp":item.outerkp, "out_ki":item.outerki, "out_kd":item.outerkd, "inner_max":item.innermax, "inner_min":item.innermin, "inner_kp":item.innerkp, "inner_ki":item.innerki, "inner_kd":item.innerkd, "inner_maxI":item.innermaxI, "inner_maxIstep":item.innerIstep, "inner_maxDstep":item.innerDstep}) } function clear_paras(index){ if(index === 0){ volume1.text = 0 keep1.text = 0 outmax1.text = 0 outmini1.text = 0 outp1.text = 0 outi1.text = 0 outd1.text = 0 inmax1.text = 0 inmini1.text = 0 inp1.text = 0 ini1.text = 0 ind1.text = 0 inmaxI1.text = 0 inmaxIstep1.text = 0 inmaxDstep1.text = 0 }else if(index === 1){ volume2.text = 0 keep2.text = 0 outmax2.text = 0 outmini2.text = 0 outp2.text = 0 outi2.text = 0 outd2.text = 0 inmax2.text = 0 inmini2.text = 0 inp2.text = 0 ini2.text = 0 ind2.text = 0 inmaxI2.text = 0 inmaxIstep2.text = 0 inmaxDstep2.text = 0 }else if(index === 2){ volume3.text = 0 keep3.text = 0 outmax3.text = 0 outmini3.text = 0 outp3.text = 0 outi3.text = 0 outd3.text = 0 inmax3.text = 0 inmini3.text = 0 inp3.text = 0 ini3.text = 0 ind3.text = 0 inmaxI3.text = 0 inmaxIstep3.text = 0 inmaxDstep3.text = 0 }else if(index === 3){ volume4.text = 0 keep4.text = 0 outmax4.text = 0 outmini4.text = 0 outp4.text = 0 outi4.text = 0 outd4.text = 0 inmax4.text = 0 inmini4.text = 0 inp4.text = 0 ini4.text = 0 ind4.text = 0 inmaxI4.text = 0 inmaxIstep4.text = 0 inmaxDstep4.text = 0 }else if(index === 4){ volume5.text = 0 keep5.text = 0 outmax5.text = 0 outmini5.text = 0 outp5.text = 0 outi5.text = 0 outd5.text = 0 inmax5.text = 0 inmini5.text = 0 inp5.text = 0 ini5.text = 0 ind5.text = 0 inmaxI5.text = 0 inmaxIstep5.text = 0 inmaxDstep5.text = 0 } } function update_detail(){ var jsonobj = CalibrationPara.get_paras(); param_model.clear() for(var index= 0; index< jsonobj.count; index++){ update_paras(index, jsonobj.pids[index]) } } function get_role(column){ var role = "idx" switch(column){ case 1: role = "volume" break case 2: role = "time" break case 3: role = "out_max" break case 4: role = "out_min" break case 5: role = "out_kp" break case 6: role = "out_ki" break case 7: role = "out_kd" break case 8: role = "inner_max" break case 9: role = "inner_min" break case 10: role = "inner_kp" break case 11: role = "inner_ki" break case 12: role = "inner_kd" break case 13: role = "inner_maxI" break case 14: role = "inner_maxIstep" break case 15: role = "inner_maxDstep" break default: break } return role } DynamicGroupBox{ id:groupbox anchors.centerIn: parent anchors.fill: parent title: title_str Column{ Rectangle{ id:param_rect //x:-10 width: 1250 height: 420 //anchors.centerIn: parent color: "white" radius: 6 border.color: "black" Text{ id:text_title anchors.top: parent.top anchors.topMargin: 10 anchors.horizontalCenter: parent.horizontalCenter font.bold: true font.pixelSize: 24 text: "PID 参数标定" } Component{ id:itemDelegateTextEdit TextField { anchors.verticalCenter: parent.verticalCenter text: styleData.value font.pointSize: 10 //font.pixelSize: 24 //font.bold: true horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter validator:RegExpValidator { regExp: /(-?[0-9]\d*((.\d+)*))*/ // /(-?[0-9]\d*((.\d+)*))|(0.\d+)*/ ///[0-9]*/ } anchors.fill: parent onEditingFinished: { //console.log("row === "+styleData.row ); //console.log("column=== "+styleData.column); //console.log("role === "+get_role(styleData.column)); var role = get_role(styleData.column) if("idx" !== role){ param_model.setProperty(styleData.row, get_role(styleData.column), Number(text)) } } } } Component{ id:itemDelegateText Text { anchors.verticalCenter: parent.verticalCenter color: styleData.selected?"#1E90FF":"#000000" elide: styleData.elideMode text: styleData.value font.pointSize: 10 //font.pixelSize: 24 //font.bold: true horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter anchors.fill: parent } } TableView{ id:tableView //frameVisible: true width: parent.width focus: true //height: parent.height - 50 anchors.top: text_title.bottom anchors.bottom: parent.bottom anchors.topMargin: 10 TableViewColumn{role: "idx"; title: "ID"; width: 40; movable:false; delegate: itemDelegateText} TableViewColumn{role: "volume"; title: "容积≤(L)"; width: 120; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "time"; title: "稳压时间(秒)"; width: 120; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "out_max"; title: "外环max"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "out_min"; title: "外环min"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "out_kp"; title: "外环KP"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "out_ki"; title: "外环KI"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "out_kd"; title: "外环KD"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_max"; title: "内环max"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_min"; title: "内环min"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_kp"; title: "内环KP"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_ki"; title: "内环KI"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_kd"; title: "内环KD"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_maxI"; title: "内环maxI"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_maxIstep"; title: "内环Istep"; width: 80; movable:false; delegate: itemDelegateTextEdit} TableViewColumn{role: "inner_maxDstep"; title: "内环Rstep"; width: 80; movable:false; delegate: itemDelegateTextEdit} //model: modelItems headerDelegate: Rectangle{ implicitWidth: 16 implicitHeight: 24 gradient: styleData.pressed ? selftest_root.pressG : (styleData.containsMouse ? root.hoverG: root.normalG) border.color: "gray" border.width: 1 Text{ anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.leftMargin: 4 anchors.right: parent.right anchors.rightMargin: 4 text: styleData.value color: styleData.pressed ?"red" : "blue" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.bold: true } } rowDelegate: Rectangle{ height: 32 //border.color: "gray" //color: styleData.selected?"#f0b0b0af":(styleData.alternate?"#c3c3c0":"#c0c0c3") color: styleData.selected ? root.highlight : root.alterBackground } itemDelegate: Rectangle { height: 28 //border.color: "gray" color: "transparent" Text { //anchors.centerIn: parent //anchors.left: parent.left anchors.leftMargin: 6 anchors.verticalCenter: parent.verticalCenter //color: styleData.textColor color: styleData.selected ? "red" : styleData.textColor text: styleData.value verticalAlignment: Text.AlignVCenter font.pointSize: 13 } } model:ListModel{ id: param_model } } } Rectangle{ id:button_rect //x:-10 width: 1250 height: 60 color: "transparent" Row{ spacing:30 anchors.fill: parent UserButton { id: refresh_button; text: "刷新"; font.pixelSize: 20 anchors.verticalCenter: parent.verticalCenter width: 120 height: 45 onClicked: { update_detail() } } UserButton { id: save_button; text: "保存"; font.pixelSize: 20 anchors.verticalCenter: parent.verticalCenter width: 120 height: 45 onClicked: { set_paras() } } } } } /* Column{ //spacing:10 anchors.centerIn: parent width: 1200 Row{ width: parent.width height: 120 spacing: 50 Text { text: "1区参数 "; font.bold: true; font.pointSize: 12; } Column{ //spacing:10 Row{ spacing:10 InputLine{ id:volume1 paraName: "容积≤(L): " paraLength: 80 onTextChanged: { volume[0] = Number(text) } } InputLine{ id:keep1 paraName: "保持时间(秒): " paraLength: 80 onTextChanged: { keeptime[0] = Number(text) } } } Row{ //spacing:10 Text { text: "外环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:outmax1 paraName: "Max:" paraLength: 60 onTextChanged: { outermax[0] = Number(text) } } InputLine{ id:outmini1 paraName: "Mini:" paraLength: 60 onTextChanged: { outermini[0] = Number(text) } } InputLine{ id:outp1 paraName: "Kp:" paraLength: 60 onTextChanged: { outerKp[0] = Number(text) } } InputLine{ id:outi1 paraName: "Ki:" paraLength: 60 onTextChanged: { outerKi[0] = Number(text) } } InputLine{ id:outd1 paraName: "Kd:" paraLength: 60 onTextChanged: { outerKd[0] = Number(text) } } } Row{ //spacing:10 Text { text: "内环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:inmax1 paraName: "Max:" paraLength: 60 onTextChanged: { innermax[0] = Number(text) } } InputLine{ id:inmini1 paraName: "Mini:" paraLength: 60 onTextChanged: { innermini[0] = Number(text) } } InputLine{ id:inp1 paraName: "Kp:" paraLength: 60 onTextChanged: { innerKp[0] = Number(text) } } InputLine{ id:ini1 paraName: "Ki:" paraLength: 60 onTextChanged: { innerKi[0] = Number(text) } } InputLine{ id:ind1 paraName: "Kd:" paraLength: 60 onTextChanged: { innerKd[0] = Number(text) } } InputLine{ id:inmaxI1 paraName: "maxI:" paraLength: 60 onTextChanged: { innermaxI[0] = Number(text) } } InputLine{ id:inmaxIstep1 paraName: "maxIstep:" paraLength: 60 onTextChanged: { innermaxIstep[0] = Number(text) } } InputLine{ id:inmaxDstep1 paraName: "maxDstep:" paraLength: 60 onTextChanged: { innermaxDstep[0] = Number(text) } } } } } Row{ width: parent.width height: 120 spacing: 50 Text { text: "2区参数 "; font.bold: true; font.pointSize: 12; } Column{ //spacing:10 Row{ spacing:10 InputLine{ id:volume2 paraName: "容积≤(L): " paraLength: 80 onTextChanged: { volume[1] = Number(text) } } InputLine{ id:keep2 paraName: "保持时间(秒): " paraLength: 80 onTextChanged: { keeptime[1] = Number(text) } } } Row{ //spacing:30 Text { text: "外环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:outmax2 paraName: "Max:" paraLength: 60 onTextChanged: { outermax[1] = Number(text) } } InputLine{ id:outmini2 paraName: "Mini:" paraLength: 60 onTextChanged: { outermini[1] = Number(text) } } InputLine{ id:outp2 paraName: "Kp:" paraLength: 60 onTextChanged: { outerKp[1] = Number(text) } } InputLine{ id:outi2 paraName: "Ki:" paraLength: 60 onTextChanged: { outerKi[1] = Number(text) } } InputLine{ id:outd2 paraName: "Kd:" paraLength: 60 onTextChanged: { outerKd[1] = Number(text) } } } Row{ //spacing:30 Text { text: "内环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:inmax2 paraName: "Max:" paraLength: 60 onTextChanged: { innermax[1] = Number(text) } } InputLine{ id:inmini2 paraName: "Mini:" paraLength: 60 onTextChanged: { innermini[1] = Number(text) } } InputLine{ id:inp2 paraName: "Kp:" paraLength: 60 onTextChanged: { innerKp[1] = Number(text) } } InputLine{ id:ini2 paraName: "Ki:" paraLength: 60 onTextChanged: { innerKi[1] = Number(text) } } InputLine{ id:ind2 paraName: "Kd:" paraLength: 60 onTextChanged: { innerKd[1] = Number(text) } } InputLine{ id:inmaxI2 paraName: "maxI:" paraLength: 60 onTextChanged: { innermaxI[1] = Number(text) } } InputLine{ id:inmaxIstep2 paraName: "maxIstep:" paraLength: 60 onTextChanged: { innermaxIstep[1] = Number(text) } } InputLine{ id:inmaxDstep2 paraName: "maxDstep:" paraLength: 60 onTextChanged: { innermaxDstep[1] = Number(text) } } } } } Row{ width: parent.width height: 120 spacing: 50 Text { text: "3区参数 "; font.bold: true; font.pointSize: 12; } Column{ //spacing:10 Row{ spacing:10 InputLine{ id:volume3 paraName: "容积≤(L): " paraLength: 80 onTextChanged: { volume[2] = Number(text) } } InputLine{ id:keep3 paraName: "保持时间(秒): " paraLength: 80 onTextChanged: { keeptime[2] = Number(text) } } } Row{ //spacing:30 Text { text: "外环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:outmax3 paraName: "Max:" paraLength: 60 onTextChanged: { outermax[2] = Number(text) } } InputLine{ id:outmini3 paraName: "Mini:" paraLength: 60 onTextChanged: { outermini[2] = Number(text) } } InputLine{ id:outp3 paraName: "Kp:" paraLength: 60 onTextChanged: { outerKp[2] = Number(text) } } InputLine{ id:outi3 paraName: "Ki:" paraLength: 60 onTextChanged: { outerKi[2] = Number(text) } } InputLine{ id:outd3 paraName: "Kd:" paraLength: 60 onTextChanged: { outerKd[2] = Number(text) } } } Row{ //spacing:30 Text { text: "内环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:inmax3 paraName: "Max:" paraLength: 60 onTextChanged: { innermax[2] = Number(text) } } InputLine{ id:inmini3 paraName: "Mini:" paraLength: 60 onTextChanged: { innermini[2] = Number(text) } } InputLine{ id:inp3 paraName: "Kp:" paraLength: 60 onTextChanged: { innerKp[2] = Number(text) } } InputLine{ id:ini3 paraName: "Ki:" paraLength: 60 onTextChanged: { innerKi[2] = Number(text) } } InputLine{ id:ind3 paraName: "Kd:" paraLength: 60 onTextChanged: { innerKd[2] = Number(text) } } InputLine{ id:inmaxI3 paraName: "maxI:" paraLength: 60 onTextChanged: { innermaxI[2] = Number(text) } } InputLine{ id:inmaxIstep3 paraName: "maxIstep:" paraLength: 60 onTextChanged: { innermaxIstep[2] = Number(text) } } InputLine{ id:inmaxDstep3 paraName: "maxDstep:" paraLength: 60 onTextChanged: { innermaxDstep[2] = Number(text) } } } } } Row{ width: parent.width height: 120 spacing: 50 Text { text: "4区参数 "; font.bold: true; font.pointSize: 12; } Column{ //spacing:10 Row{ spacing:10 InputLine{ id:volume4 paraName: "容积≤(L): " paraLength: 80 onTextChanged: { volume[3] = Number(text) } } InputLine{ id:keep4 paraName: "保持时间(秒): " paraLength: 80 onTextChanged: { keeptime[3] = Number(text) } } } Row{ //spacing:30 Text { text: "外环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:outmax4 paraName: "Max:" paraLength: 60 onTextChanged: { outermax[3] = Number(text) } } InputLine{ id:outmini4 paraName: "Mini:" paraLength: 60 onTextChanged: { outermini[3] = Number(text) } } InputLine{ id:outp4 paraName: "Kp:" paraLength: 60 onTextChanged: { outerKp[3] = Number(text) } } InputLine{ id:outi4 paraName: "Ki:" paraLength: 60 onTextChanged: { outerKi[3] = Number(text) } } InputLine{ id:outd4 paraName: "Kd:" paraLength: 60 onTextChanged: { outerKd[3] = Number(text) } } } Row{ //spacing:30 Text { text: "内环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:inmax4 paraName: "Max:" paraLength: 60 onTextChanged: { innermax[3] = Number(text) } } InputLine{ id:inmini4 paraName: "Mini:" paraLength: 60 onTextChanged: { innermini[3] = Number(text) } } InputLine{ id:inp4 paraName: "Kp:" paraLength: 60 onTextChanged: { innerKp[3] = Number(text) } } InputLine{ id:ini4 paraName: "Ki:" paraLength: 60 onTextChanged: { innerKi[3] = Number(text) } } InputLine{ id:ind4 paraName: "Kd:" paraLength: 60 onTextChanged: { innerKd[3] = Number(text) } } InputLine{ id:inmaxI4 paraName: "maxI:" paraLength: 60 onTextChanged: { innermaxI[3] = Number(text) } } InputLine{ id:inmaxIstep4 paraName: "maxIstep:" paraLength: 60 onTextChanged: { innermaxIstep[3] = Number(text) } } InputLine{ id:inmaxDstep4 paraName: "maxDstep:" paraLength: 60 onTextChanged: { innermaxDstep[3] = Number(text) } } } } } Row{ width: parent.width height: 120 spacing: 50 Text { text: "5区参数 "; font.bold: true; font.pointSize: 12; } Column{ //spacing:10 Row{ spacing:10 InputLine{ id:volume5 paraName: "容积≤(L): " paraLength: 80 onTextChanged: { volume[4] = Number(text) } } InputLine{ id:keep5 paraName: "保持时间(秒): " paraLength: 80 onTextChanged: { keeptime[4] = Number(text) } } } Row{ //spacing:30 Text { text: "外环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:outmax5 paraName: "Max:" paraLength: 60 onTextChanged: { outermax[4] = Number(text) } } InputLine{ id:outmini5 paraName: "Mini:" paraLength: 60 onTextChanged: { outermini[4] = Number(text) } } InputLine{ id:outp5 paraName: "Kp:" paraLength: 60 onTextChanged: { outerKp[4] = Number(text) } } InputLine{ id:outi5 paraName: "Ki:" paraLength: 60 onTextChanged: { outerKi[4] = Number(text) } } InputLine{ id:outd5 paraName: "Kd:" paraLength: 60 onTextChanged: { outerKd[4] = Number(text) } } } Row{ //spacing:30 Text { text: "内环:"; font.bold: true; font.pointSize: 12; } InputLine{ id:inmax5 paraName: "Max:" paraLength: 60 onTextChanged: { innermax[4] = Number(text) } } InputLine{ id:inmini5 paraName: "Mini:" paraLength: 60 onTextChanged: { innermini[4] = Number(text) } } InputLine{ id:inp5 paraName: "Kp:" paraLength: 60 onTextChanged: { innerKp[4] = Number(text) } } InputLine{ id:ini5 paraName: "Ki:" paraLength: 60 onTextChanged: { innerKi[4] = Number(text) } } InputLine{ id:ind5 paraName: "Kd:" paraLength: 60 onTextChanged: { innerKd[4] = Number(text) } } InputLine{ id:inmaxI5 paraName: "maxI:" paraLength: 60 onTextChanged: { innermaxI[4] = Number(text) } } InputLine{ id:inmaxIstep5 paraName: "maxIstep:" paraLength: 60 onTextChanged: { innermaxIstep[4] = Number(text) } } InputLine{ id:inmaxDstep5 paraName: "maxDstep:" paraLength: 60 onTextChanged: { innermaxDstep[4] = Number(text) } } } } } Row{ spacing:30 UserButton { id: refresh_button; text: "刷新"; font.pixelSize: 20 anchors.verticalCenter: parent.verticalCenter width: 120 height: 45 onClicked: { update_detail() } } UserButton { id: save_button; text: "保存"; font.pixelSize: 20 anchors.verticalCenter: parent.verticalCenter width: 120 height: 45 onClicked: { set_paras() } } } } */ } Component.onCompleted: { update_detail() } }