import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls 1.4

Item {
    id:root
    anchors.fill: parent
    anchors.margins: 1
    property  int fontsize:14
    property  string fontcolor:"black"
    //property  string text:"0.000"
    //property  int value:0
    //property  int value_tmp:0
    property  string text_state1:"合格"
    property  string text_state2:"不合格"
    property  string text_state3:"无此项"

    signal usateChanged

    state: "0"

    states:[
        State {
            name: "0"
            PropertyChanges {target:rb1; checked:true}
            PropertyChanges {target:rb2; checked:false}
            PropertyChanges {target:rb3; checked:false}
        },
        State {
            name: "1"
            PropertyChanges {target:rb1; checked:false}
            PropertyChanges {target:rb2; checked:true}
            PropertyChanges {target:rb3; checked:false}
        },
        State {
            name: "2"
            PropertyChanges {target:rb1; checked:false}
            PropertyChanges {target:rb2; checked:false}
            PropertyChanges {target:rb3; checked:true}
        }
    ]


    ButtonGroup{
        id:group
        buttons: row.children

        /*
        onClicked:{
            console.log("tristate clicked:", button.text)
            var old_state = state

            if(text_state1 === button.text){
                state = "0"
            }else if(text_state2 === button.text){
                state = "1"
            }else if(text_state3 === button.text){
                state = "2"
            }

            console.log("tristate old_state:", old_state)
            console.log("tristate state:", state)

            if(old_state !== state){
                //value = value_tmp
                root.usateChanged()
            }
        }

        */

    }

    Row{
        id: row


        UserRadioButton{
            id:rb1
            checked: true
            text: text_state1
            font.pixelSize: fontsize
            onCheckedChanged: {

                if("0" !== root.state){
                    //console.log("rb1 onCheckedChanged, rootstate:" , root.state)
                    root.state = "0"
                    root.usateChanged()
                }
            }

        }

        UserRadioButton{
            id:rb2
            checked: false
            text: text_state2
            font.pixelSize: fontsize
            onCheckedChanged: {
                if("1" !== root.state){
                    //console.log("rb2 onCheckedChanged, rootstate:" , root.state)
                    root.state = "1"
                    root.usateChanged()
                }
            }

        }

        UserRadioButton{
            id:rb3
            checked: false
            text: text_state3
            font.pixelSize: fontsize

            onCheckedChanged: {
                if("2" !== root.state){
                    //console.log("rb3 onCheckedChanged, rootstate:" , root.state)
                    root.state = "2"
                    root.usateChanged()
                }
            }

        }
    }
}
