Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 5.26 KB | None | 0 0
  1. import QtQuick 2.9
  2.  
  3. import QtQuick.Window 2.2
  4.  
  5. import QtQuick.Controls 2.5
  6.  
  7. import QtQuick.Dialogs 1.2
  8.  
  9. import changer 1.0
  10.  
  11. Window {
  12.  
  13.     visible: true
  14.  
  15.     width: 640
  16.  
  17.     height: 480
  18.  
  19.     title: qsTr("Hello World")
  20.  
  21.     color: "#ffffff"
  22.  
  23.    ListModel{
  24.  
  25.     id: listMod
  26.  
  27.     ListElement{
  28.  
  29.      state: "bad"
  30.  
  31.      textid: "id"
  32.  
  33.      place: "placeid"
  34.  
  35.      measure: "2.25"
  36.  
  37.     }
  38.  
  39.    }
  40.  
  41.     ListView {
  42.  
  43.        property int model_value: 14
  44.  
  45.         id: mainList
  46.  
  47.         spacing: -15
  48.  
  49.         layoutDirection: "LeftToRight"
  50.  
  51.         orientation:
  52.  
  53.             "Horizontal"
  54.  
  55.         delegate:
  56.  
  57.              Item{
  58.  
  59.                  id: delegatetolistItem
  60.  
  61.                    Rectangle {
  62.  
  63.                      id: roundforgenerator
  64.  
  65.                      height: 25
  66.  
  67.                      width: 25
  68.  
  69.                      radius:25
  70.  
  71.                   //   color: "#008000"
  72.  
  73.                      border.width: 1
  74.  
  75.                      state: model.state || "good"
  76.  
  77.                      ToolTip {
  78.  
  79.                      id: rectangleToolTip
  80.  
  81.                      visible: rectangleToolTip.text ? rectangleArea.containsMouse : false
  82.  
  83.                      text: descriptionforgenerator.text
  84.  
  85.                      }
  86.  
  87.                      MouseArea {
  88.  
  89.                          id: rectangleArea
  90.  
  91.                          anchors.fill: parent
  92.  
  93.                          hoverEnabled: true
  94.  
  95.                              }
  96.  
  97.                      Text {
  98.  
  99.                          y: parent.height + 2
  100.  
  101.                          font.pixelSize: 13
  102.  
  103.                          id: textforgenerator
  104.  
  105.                          text: model.textid || qsTr("id")
  106.  
  107.                          }
  108.  
  109.                      Text{
  110.  
  111.                          id: descriptionforgenerator
  112.  
  113.                          text: model.place || qsTr("place")
  114.  
  115.                          visible: false
  116.  
  117.                          }/**Tooltip text*/
  118.  
  119.                      Text {
  120.  
  121.                         id: textformeasuregenerator
  122.  
  123.                         text: model.measure || qsTr("0")
  124.  
  125.                         visible: true
  126.  
  127.                         anchors.centerIn: parent
  128.  
  129.                          }
  130.  
  131.                      states: [
  132.  
  133.                              State {
  134.  
  135.                                  name: "good"
  136.  
  137.                                  PropertyChanges {
  138.  
  139.                                      target: roundforgenerator; color: "green"
  140.  
  141.                                  }
  142.  
  143.                              },
  144.  
  145.                              State {
  146.  
  147.                                  name: "bad"
  148.  
  149.                                  PropertyChanges {
  150.  
  151.                                      target: roundforgenerator; color: "red"
  152.  
  153.                                  }
  154.  
  155.                              },
  156.  
  157.                              State {
  158.  
  159.                                  name: "working"
  160.  
  161.                                  PropertyChanges {
  162.  
  163.                                      target: roundforgenerator; color: "yellow"
  164.  
  165.                                  }
  166.  
  167.                              },
  168.  
  169.                              State {
  170.  
  171.                                  name: "available"
  172.  
  173.                                  PropertyChanges {
  174.  
  175.                                      target: roundforgenerator; color: "blue"
  176.  
  177.                                  }
  178.  
  179.                              }
  180.  
  181.                          ]
  182.  
  183.                  }
  184.  
  185.              }
  186.  
  187.         model: listMod
  188.  
  189.       //  anchors.bottom: parent
  190.  
  191.         //anchors.centerIn: parent
  192.  
  193.         }
  194.  
  195.    function add_component(idfromapp,data,sig,place){
  196.  
  197.       // listMod.append({"attributes":[{"state":sig},{"textid":idfromapp},{"place":place},{"measure":data}]})
  198.  
  199.          listMod.append({"state":sig, "textid":idfromapp,"place":place,"measure":data})
  200.  
  201.    }
  202.  
  203.    function update(idbutt,idfromapp,data,sig,place){
  204.  
  205.         listMod.set(idbutt,{"state":sig,"textid":idfromapp,"place":place,"measure":data})
  206.  
  207.    }
  208.  
  209.    function remove(idbutt){
  210.  
  211.        listMod.remove(idbutt)
  212.  
  213.    }
  214.  
  215.    function updateMeasure(idbutt,data,sig){
  216.  
  217.        listmod.set(idbutt,{"state":sig,"measure":data})
  218.  
  219.    }
  220.  
  221.    Changer{
  222.  
  223.    id: changeit
  224.  
  225.    onUpdate: {
  226.  
  227.         update(idbutt,idfromapp,data,sig,place)}
  228.  
  229.    onUpdateMeasure: {
  230.  
  231.        updateMeasure(idbutt,data,sig)
  232.  
  233.    }
  234.  
  235.    onAdding: {
  236.  
  237.        console.log("pew-pew it work!")
  238.  
  239.       add_component(idfromapp,data,sig,place)
  240.  
  241.        // listMod.insert({"state":sig, "textid":idfromapp,"place":place,"measure":data})
  242.  
  243.    }
  244.  
  245.    onDeleteSig: {
  246.  
  247.        remove(idbutt)
  248.  
  249.    }
  250.  
  251.    onComplete: {
  252.  
  253.    console.log("pew-pew it work!")
  254.  
  255.    }
  256.  
  257.    }
  258.  
  259. /*signals add remove with listView work*/
  260.  
  261.    Button{
  262.  
  263.   /*  onClicked: add_component()*/
  264.  
  265.    x:20
  266.  
  267.    y:30
  268.  
  269.    height: 50
  270.  
  271.    width: 50
  272.  
  273.    text: qsTr("ñíÿòèå")
  274.  
  275.    onClicked: changeit.sensors_poll()
  276.  
  277.    }
  278.  
  279.    Button{
  280.  
  281.     x:50
  282.  
  283.     y:30
  284.  
  285.     height: 50
  286.  
  287.     width: 50
  288.  
  289.     text: qsTr("DB")
  290.  
  291.     onClicked: changeit.first_load()
  292.  
  293.    }
  294.  
  295.     Button{
  296.  
  297.         x:100
  298.  
  299.         y:30
  300.  
  301.         height: 50
  302.  
  303.         width: 50
  304.  
  305.         text: qsTr("Start")
  306.  
  307.         onClicked: add_component("1","1","bad","1")
  308.  
  309.     }
  310.  
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement