AreaDataEditor.qml 3.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
import QtQuick 2.0

import QtQuick.Layouts 1.11
import QtQuick.Controls 1.4
import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.ScreenTools   1.0

GridLayout {
    id:_root

    property bool checked: true
    property var missionItem: undefined
    property int availableWidth: 300

    property var _areaData: missionItem.areaData
    property real   _margin: ScreenTools.defaultFontPixelWidth / 2

    width:      availableWidth
    columnSpacing:  _margin
    rowSpacing:     _margin
    columns:        2

    Component.onCompleted: {
        console.assert(missionItem !== undefined, "please set the missionItem property")
    }

    ExclusiveGroup{id:areaGroup}

    Repeater{
        id: areaSelector

        property int selectedIndex: -1

        model: _missionItem.areaData.areaList
        delegate: QGCRadioButton {
            text: object.objectName
            checkable: _root.checked
            Layout.fillWidth: true
            Layout.columnSpan: 2

            onCheckedChanged: {
                if (checked){
                    areaSelector.selectedIndex = index
                }
            }

            Component.onCompleted: {
                if (index === 0){
                    checked = true
                }
                object.interactive = Qt.binding(function(){return checked && _root.checked})
            }

        }
    } // area Repeater

    ColumnLayout {
        id:editorParent
        Layout.fillWidth: true
        Layout.columnSpan: 2
    }

    Repeater{
        id:areaEditorRepeater

        model: _missionItem.areaData.areaList
        delegate: Item{
            id:editor
            visible: index == areaSelector.selectedIndex

            property var _visualItem: undefined
            property var geoArea: object

            Component.onCompleted: {
                if (geoArea.editorQML && !_visualItem) {
                    var component = Qt.createComponent(geoArea.editorQML)
                    if (component.status === Component.Error) {
                        console.log("Error loading Qml: ", geoArea.editorQML, component.errorString())
                    } else {
                        _visualItem = component.createObject(editorParent, {
                                                                 geoArea: editor.geoArea,
                                                                 visible: Qt.binding(function(){return editor.visible}),
                                                                 availableWidth: Qt.binding(function(){return editorParent.width})})
                    }
                }
            }

            Component.onDestruction: {
                if (_visualItem) {
                    _visualItem.destroy()
                }
            }
        } // editor
    } // areaEditorRepeater


    QGCButton{
        text: "Check Rules"
        enabled: _root.checked
        Layout.fillWidth: true
        onClicked: {
            _areaData.isCorrect()
        }
    }

    QGCButton{
        text: "Intersection"
        enabled: _root.checked
        Layout.fillWidth: true
        onClicked: {
            _areaData.intersection()
        }
    }
}