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

Item {
    id: _root

8 9 10
    visible: true

    // Expects the following properties:
11 12 13 14 15
    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

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

    signal clicked()

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

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

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

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

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

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

        DragCoordinate {
58 59 60 61
            id: dragCoordinate

            property var ref: _root.generator.reference

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

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

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