FlightDisplayView.qml 7.95 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
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

import QtQuick                  2.4
import QtQuick.Controls         1.3
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
28
import QtLocation               5.3
29
import QtPositioning            5.2
30

31
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
32
import QGroundControl.FlightDisplay 1.0
33 34 35 36
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
37
import QGroundControl.Vehicle       1.0
38
import QGroundControl.Controllers   1.0
39 40 41 42 43

/// Flight Display View
Item {
    id: root

44 45 46
    property alias latitude: flightMap.latitude
    property alias longitude: flightMap.longitude

47 48 49 50 51 52 53 54 55 56 57
    // Top margin for all widgets. Used to prevent overlap with the toolbar
    property real   topMargin: 0

    // Used by parent to hide widgets when it displays something above in the z order.
    // Prevents z order drawing problems.
    property bool hideWidgets: false

    readonly property alias zOrderTopMost:   flightMap.zOrderTopMost
    readonly property alias zOrderWidgets:   flightMap.zOrderWidgets
    readonly property alias zOrderMapItems:  flightMap.zOrderMapItems

58
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
59 60 61

    property var _activeVehicle: multiVehicleManager.activeVehicle

62 63 64 65 66 67 68 69
    readonly property var  _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
    readonly property real _defaultRoll:                0
    readonly property real _defaultPitch:               0
    readonly property real _defaultHeading:             0
    readonly property real _defaultAltitudeWGS84:       0
    readonly property real _defaultGroundSpeed:         0
    readonly property real _defaultAirSpeed:            0
    readonly property real _defaultClimbRate:           0
70

Don Gagne's avatar
Don Gagne committed
71 72 73
    readonly property string _mapName:              "FlightDisplayView"
    readonly property string _showMapBackgroundKey: "/showMapBackground"

Don Gagne's avatar
Don Gagne committed
74 75
    readonly property var _flightMap: flightMap

76 77
    property real _roll:            _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll
    property real _pitch:           _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch
78 79
    property real _heading:         _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading

80
    property var  _vehicleCoordinate:   _activeVehicle ? _activeVehicle.coordinate : _defaultVehicleCoordinate
81

82 83 84 85 86
    property real _altitudeWGS84:   _activeVehicle ? _activeVehicle.altitudeWGS84 : _defaultAltitudeWGS84
    property real _groundSpeed:     _activeVehicle ? _activeVehicle.groundSpeed : _defaultGroundSpeed
    property real _airSpeed:        _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed
    property real _climbRate:       _activeVehicle ? _activeVehicle.climbRate : _defaultClimbRate

87
    property bool _showMap: getBool(QGroundControl.flightMapSettings.loadMapSetting(flightMap.mapName, _showMapBackgroundKey, "1"))
Don Gagne's avatar
Don Gagne committed
88

89
    FlightDisplayViewController { id: _controller }
90
    MissionController { id: _missionController }
91

Don Gagne's avatar
Don Gagne committed
92 93 94 95
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

Don Gagne's avatar
Don Gagne committed
96
    // Validate _showMap setting
97
    Component.onCompleted: {
Don Gagne's avatar
Don Gagne committed
98 99
        delayLoader.source = "FlightDisplayViewDelayLoadOuter.qml"

100 101 102 103 104 105
        // We have to be careful to not reference root properties in a function which is in a subcomponent
        // until the root component has completed loading. Otherwise you get undefined references.
        flightMap.rootLoadCompleted = true
        flightMap.updateMapPosition(true /* force */)
        _setShowMap(_showMap)
    }
Don Gagne's avatar
Don Gagne committed
106

107 108 109 110 111 112 113 114
    function getBool(value) {
        return value === '0' ? false : true;
    }

    function setBool(value) {
        return value ? "1" : "0";
    }

Don Gagne's avatar
Don Gagne committed
115
    function _setShowMap(showMap) {
116
        _showMap = _controller.hasVideo ? showMap : true
117
        QGroundControl.flightMapSettings.saveMapSetting(flightMap.mapName, _showMapBackgroundKey, setBool(_showMap))
Don Gagne's avatar
Don Gagne committed
118 119
    }

120
    FlightMap {
Don Gagne's avatar
Don Gagne committed
121 122
        id:             flightMap
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
123
        mapName:        _mapName
Don Gagne's avatar
Don Gagne committed
124
        visible:        _showMap
125 126
        latitude:       root._defaultCoordinate.latitude
        longitude:      root._defaultCoordinate.longitude
127

128 129
        property var rootVehicleCoordinate: _vehicleCoordinate
        property bool rootLoadCompleted: false
Don Gagne's avatar
Don Gagne committed
130

131 132
        property bool _followVehicle: true

133
        onRootVehicleCoordinateChanged: updateMapPosition(false /* force */)
Don Gagne's avatar
Don Gagne committed
134

Don Gagne's avatar
Don Gagne committed
135 136
        Component.onCompleted: flightMapDelayLoader.source = "FlightDisplayViewDelayLoadInner.qml"

Don Gagne's avatar
Don Gagne committed
137
        function updateMapPosition(force) {
138 139 140
            if ((_followVehicle || force) && rootLoadCompleted) {
                flightMap.latitude = root._vehicleCoordinate.latitude
                flightMap.longitude = root._vehicleCoordinate.longitude
Don Gagne's avatar
Don Gagne committed
141 142
            }
        }
143 144 145 146 147
        // Home position
        MissionItemIndicator {
            label:          "H"
            coordinate:     (_activeVehicle && _activeVehicle.homePositionAvailable) ? _activeVehicle.homePosition : QtPositioning.coordinate(0, 0)
            visible:        _activeVehicle ? _activeVehicle.homePositionAvailable : false
148
            z:              flightMap.zOrderMapItems
149 150
        }

151 152 153 154 155 156 157 158
        // Add trajectory points to the map
        MapItemView {
            model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.trajectoryPoints : 0
            
            delegate:
                MapPolyline {
                    line.width: 3
                    line.color: "orange"
159 160
                    z:          flightMap.zOrderMapItems - 1

161 162 163 164 165 166 167 168

                    path: [
                        { latitude: object.coordinate1.latitude, longitude: object.coordinate1.longitude },
                        { latitude: object.coordinate2.latitude, longitude: object.coordinate2.longitude },
                    ]
                }
        }

169 170 171 172 173 174
        // Add the vehicles to the map
        MapItemView {
            model: multiVehicleManager.vehicles
            
            delegate:
                VehicleMapItem {
175
                        vehicle:        object
176
                        coordinate:     object.coordinate
177
                        isSatellite:    flightMap.isSatelliteMap
178
                        z:              flightMap.zOrderMapItems
179 180 181 182
                }
        }

        // Add the mission items to the map
183 184 185
        MissionItemView {
            model:          _missionController.missionItems
            zOrderMapItems: flightMap.zOrderMapItems
186 187
        }

188 189 190 191 192 193
        // Add lines between waypoints
        MissionLineView {
            model:          _missionController.waypointLines
            zOrderMapItems: flightMap.zOrderMapItems
        }

Don Gagne's avatar
Don Gagne committed
194 195 196
        Loader {
            id:             flightMapDelayLoader
            anchors.fill:   parent
197
        }
198 199 200 201 202

        // Used to make pinch zoom work
        MouseArea {
            anchors.fill: parent
        }
Don Gagne's avatar
Don Gagne committed
203 204
    } // Flight Map

Don Gagne's avatar
Don Gagne committed
205 206
    Loader {
        id:             delayLoader
Don Gagne's avatar
Don Gagne committed
207 208
        anchors.fill:   parent
    }
209
}