CircularGeneratorMapVisual.qml 2.04 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 14
    property var map        ///< Map control to place item in
    property var qgcView    ///< QGCView to use for popping dialogs
    property var generator
    property bool checked: false

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

    signal clicked()

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

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

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

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

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

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

        DragCoordinate {
57 58 59 60
            id: dragCoordinate

            property var ref: _root.generator.reference

61 62 63 64
            map:        _root.map
            qgcView:    _root.qgcView
            z:          QGroundControl.zOrderMapItems
            checked:    _root.checked
65
            coordinate: ref
66

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

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