CircularSurveyMapVisual.qml 4.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
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick          2.3
import QtQuick.Controls 1.2
import QtLocation       5.3
import QtPositioning    5.3

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.FlightMap     1.0

/// Survey Complex Mission Item visuals
Item {
    id: _root

    property var map        ///< Map control to place item in
    property var qgcView    ///< QGCView to use for popping dialogs

    property var _missionItem:      object
29
    property var _transectsComponent
30 31 32 33 34
    property var _entryCoordinate
    property var _exitCoordinate

    signal clicked(int sequenceNumber)

35 36
    function _addTransectsComponent(){
        if (!_transectsComponent){
37
            _transectsComponent = visualTransectsComponent.createObject(_root)
38 39 40 41 42 43
            map.addMapItem(_transectsComponent)
        }
    }

    function _addExitCoordinate(){
        if (!_exitCoordinate){
44
            _exitCoordinate = exitPointComponent.createObject(_root)
45 46 47 48 49 50
            map.addMapItem(_exitCoordinate)
        }
    }

    function _addEntryCoordinate(){
        if (!_entryCoordinate){
51
            _entryCoordinate = entryPointComponent.createObject(_root)
52 53 54 55 56 57
            map.addMapItem(_entryCoordinate)
        }
    }

    function _destroyEntryCoordinate(){
        if (_entryCoordinate){
58
            map.removeMapItem(_entryCoordinate)
59 60 61 62 63 64 65
            _entryCoordinate.destroy()
            _entryCoordinate = undefined
        }
    }

    function _destroyExitCoordinate(){
        if (_exitCoordinate){
66
            map.removeMapItem(_exitCoordinate)
67 68 69
            _exitCoordinate.destroy()
            _exitCoordinate = undefined
        }
70 71
    }

72 73
    function _destroyTransectsComponent(){
        if (_transectsComponent){
74
            map.removeMapItem(_transectsComponent)
75 76 77
            _transectsComponent.destroy()
            _transectsComponent = undefined
        }
78 79 80
    }

    Component.onCompleted: {
81 82 83
        _addEntryCoordinate()
        _addExitCoordinate()
        _addTransectsComponent()
84 85 86
    }

    Component.onDestruction: {
87 88 89 90 91
        _destroyEntryCoordinate()
        _destroyExitCoordinate()
        _destroyTransectsComponent()
    }

92 93 94 95 96
    // Transect lines
    Component {
        id: visualTransectsComponent

        MapPolyline {
97
            property var transects: _missionItem.visualTransectPoints
98 99
            line.color: "white"
            line.width: 2
100
            path:       transects.length > 0 ? transects : []
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        }
    }

    // Entry point
    Component {
        id: entryPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.coordinate
            visible:        _missionItem.exitCoordinate.isValid

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.sequenceNumber
                label:      "Entry"
                checked:    _missionItem.isCurrentItem
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
            }
        }
    }

    // Exit point
    Component {
        id: exitPointComponent

        MapQuickItem {
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
            coordinate:     _missionItem.exitCoordinate
            visible:        _missionItem.exitCoordinate.isValid

            sourceItem: MissionItemIndexLabel {
                index:      _missionItem.lastSequenceNumber
                label:      "Exit"
                checked:    _missionItem.isCurrentItem
                onClicked:  _root.clicked(_missionItem.sequenceNumber)
            }
        }
    }
}