RallyPointMapVisuals.qml 3.8 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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

/// Rally Point map visuals
Item {
23
    id: _root
24 25 26 27 28 29 30 31 32
    z: QGroundControl.zOrderMapItems

    property var    map
    property var    myRallyPointController
    property bool   interactive:            false   ///< true: user can interact with items
    property bool   planView:               false   ///< true: visuals showing in plan view

    property bool   _interactive:           interactive
    property var    _rallyPointsComponent
33
    property bool   _rallyPointsSupported:  myRallyPointController.supported
34 35 36 37 38 39 40 41 42 43
    property var    _rallyPoints:           myRallyPointController.points

    Component.onCompleted: {
        _rallyPointsComponent = rallyPointsComponent.createObject(map)
    }

    Component.onDestruction: {
        _rallyPointsComponent.destroy()
    }

Don Gagne's avatar
Don Gagne committed
44 45 46 47
    Component {
        id: dragAreaComponent

        MissionItemIndicatorDrag {
48
            mapControl:     _root.map
Don Gagne's avatar
Don Gagne committed
49
            itemCoordinate: rallyPointObject.coordinate
50
            visible:        rallyPointObject === myRallyPointController.currentRallyPoint && _root.interactive
Don Gagne's avatar
Don Gagne committed
51 52 53 54 55 56 57

            property var rallyPointObject

            onItemCoordinateChanged: rallyPointObject.coordinate = itemCoordinate
        }
    }

58 59 60 61 62 63 64 65
    Component {
        id: rallyPointComponent

        MapQuickItem {
            id:             itemIndicator
            anchorPoint.x:  sourceItem.anchorPointX
            anchorPoint.y:  sourceItem.anchorPointY
            z:              QGroundControl.zOrderMapItems
66
            opacity:        _root.opacity
67 68 69 70

            property var rallyPointObject

            sourceItem: MissionItemIndexLabel {
Gus Grubba's avatar
Gus Grubba committed
71 72 73 74 75
                id:                 itemIndexLabel
                label:              qsTr("R", "rally point map item label")
                checked:            _editingLayer == _layerRallyPoints ? rallyPointObject === myRallyPointController.currentRallyPoint : false
                highlightSelected:  true
                onClicked:          myRallyPointController.currentRallyPoint = rallyPointObject
76 77 78 79 80 81 82 83 84 85 86 87
            }
        }
    }

    // Add all rally points to the map
    Component {
        id: rallyPointsComponent

        Repeater {
            model: _rallyPoints

            delegate: Item {
88
                opacity:        _root.opacity
89 90 91
                property var _visuals: [ ]

                Component.onCompleted: {
Don Gagne's avatar
Don Gagne committed
92 93 94 95 96 97 98
                    var rallyPointIndicator = rallyPointComponent.createObject(map)
                    rallyPointIndicator.coordinate = Qt.binding(function() { return object.coordinate })
                    rallyPointIndicator.rallyPointObject = Qt.binding(function() { return object })
                    map.addMapItem(rallyPointIndicator)
                    _visuals.push(rallyPointIndicator)

                    var dragArea = dragAreaComponent.createObject(map, { "itemIndicator": rallyPointIndicator, "rallyPointObject": object })
99 100 101 102 103 104 105 106 107 108 109 110 111 112
                    _visuals.push(dragArea)
                }

                Component.onDestruction: {
                    for (var i=0; i<_visuals.length; i++) {
                        _visuals[i].destroy()
                    }
                    _visuals = [ ]
                }
            }
        }
    }

}