FlightDisplayView.qml 7.83 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 47 48 49 50 51 52 53 54
    // 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

55 56 57 58
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }

    property var _activeVehicle: multiVehicleManager.activeVehicle

59 60 61 62 63 64 65 66
    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
67

Don Gagne's avatar
Don Gagne committed
68 69 70
    readonly property string _mapName:              "FlightDisplayView"
    readonly property string _showMapBackgroundKey: "/showMapBackground"

Don Gagne's avatar
Don Gagne committed
71 72
    readonly property var _flightMap: flightMap

73 74
    property real _roll:            _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll
    property real _pitch:           _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch
75 76
    property real _heading:         _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading

77
    property var  _vehicleCoordinate:   _activeVehicle ? _activeVehicle.coordinate : _defaultVehicleCoordinate
78

79 80 81 82 83
    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

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

86
    FlightDisplayViewController { id: _controller }
87

Don Gagne's avatar
Don Gagne committed
88 89 90 91
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

Don Gagne's avatar
Don Gagne committed
92
    // Validate _showMap setting
93
    Component.onCompleted: {
Don Gagne's avatar
Don Gagne committed
94 95
        delayLoader.source = "FlightDisplayViewDelayLoadOuter.qml"

96 97 98 99 100 101
        // 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
102

103 104 105 106 107 108 109 110
    function getBool(value) {
        return value === '0' ? false : true;
    }

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

Don Gagne's avatar
Don Gagne committed
111
    function _setShowMap(showMap) {
112
        _showMap = _controller.hasVideo ? showMap : true
113
        QGroundControl.flightMapSettings.saveMapSetting(flightMap.mapName, _showMapBackgroundKey, setBool(_showMap))
Don Gagne's avatar
Don Gagne committed
114 115
    }

116

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

125 126
        property var rootVehicleCoordinate: _vehicleCoordinate
        property bool rootLoadCompleted: false
Don Gagne's avatar
Don Gagne committed
127

128
        onRootVehicleCoordinateChanged: updateMapPosition(false /* force */)
Don Gagne's avatar
Don Gagne committed
129

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

Don Gagne's avatar
Don Gagne committed
132
        function updateMapPosition(force) {
133 134 135
            if ((_followVehicle || force) && rootLoadCompleted) {
                flightMap.latitude = root._vehicleCoordinate.latitude
                flightMap.longitude = root._vehicleCoordinate.longitude
Don Gagne's avatar
Don Gagne committed
136 137 138 139 140
            }
        }

        property bool _followVehicle: true

141 142 143 144 145
        // Home position
        MissionItemIndicator {
            label:          "H"
            coordinate:     (_activeVehicle && _activeVehicle.homePositionAvailable) ? _activeVehicle.homePosition : QtPositioning.coordinate(0, 0)
            visible:        _activeVehicle ? _activeVehicle.homePositionAvailable : false
146
            z:              flightMap.zOrderMapItems
147 148
        }

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

159 160 161 162 163 164 165 166

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

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

        // Add the mission items to the map
        MapItemView {
            model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.missionItems : 0
            
            delegate:
Don Gagne's avatar
Don Gagne committed
185 186 187 188
                MissionItemIndicator {
                    label:          object.sequenceNumber
                    isCurrentItem:  object.isCurrentItem
                    coordinate:     object.coordinate
189
                    z:              flightMap.zOrderMapItems
190 191 192
                }
        }

Don Gagne's avatar
Don Gagne committed
193 194 195
        Loader {
            id:             flightMapDelayLoader
            anchors.fill:   parent
196
        }
Don Gagne's avatar
Don Gagne committed
197 198
    } // Flight Map

Don Gagne's avatar
Don Gagne committed
199 200
    Loader {
        id:             delayLoader
Don Gagne's avatar
Don Gagne committed
201 202
        anchors.fill:   parent
    }
203
}