CircularGeneratorMapVisual.qml 1.93 KB
Newer Older
1 2
import QtQuick 			2.0
import QGroundControl   1.0
3 4 5 6

Item {
    id: _root

7 8 9
    visible: true

    // Expects the following properties:
10 11 12 13
    property var map        ///< Map control to place item in
    property var generator
    property bool checked: false

14
    property var _referenceComponent: undefined
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

    signal clicked()

    onVisibleChanged:  {
        if (visible){
            _addRefPoint()
        } else {
            _destroyRefPoint()
        }
    }

    Component.onCompleted: {
        if (visible){
            _addRefPoint()
        }
    }

32
    Component.onDestruction: {
33 34 35
        _destroyRefPoint()
    }

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    function _addRefPoint(){
        if (!_referenceComponent){
            _referenceComponent = refPointComponent.createObject(_root)
            map.addMapItem(_referenceComponent)
        }
    }

    function _destroyRefPoint(){
        if (_referenceComponent){
            map.removeMapItem(_referenceComponent)
            _referenceComponent.destroy()
            _referenceComponent = undefined
        }
    }

51 52 53 54 55
    // Ref. point (Base Station)
    Component {
        id: refPointComponent

        DragCoordinate {
56 57 58 59
            id: dragCoordinate

            property var ref: _root.generator.reference

60 61 62
            map:        _root.map
            z:          QGroundControl.zOrderMapItems
            checked:    _root.checked
63
            coordinate: ref
64

65 66 67 68 69 70
            onDragReleased: {
                syncAndBind()
            }
            Component.onCompleted: {
                syncAndBind()
            }
71 72 73 74
            onClicked:  {
                _root.clicked()
            }

75 76 77 78 79 80
            function syncAndBind(){
                if (coordinate.latitude !== ref.latitude ||
                        coordinate.longitude !== ref.longitude){
                    _root.generator.reference = coordinate
                }
                coordinate = Qt.binding(function(){return _root.generator.reference})
81 82 83 84
            }
        }
    }
}