FlightDisplayView.qml 7.58 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
    MissionController { id: _missionController }
88

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

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

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

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

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

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

117

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

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

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

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

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

        property bool _followVehicle: true

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

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

160 161 162 163 164 165 166 167

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

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

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

Don Gagne's avatar
Don Gagne committed
187 188 189
        Loader {
            id:             flightMapDelayLoader
            anchors.fill:   parent
190
        }
Don Gagne's avatar
Don Gagne committed
191 192
    } // Flight Map

Don Gagne's avatar
Don Gagne committed
193 194
    Loader {
        id:             delayLoader
Don Gagne's avatar
Don Gagne committed
195 196
        anchors.fill:   parent
    }
197
}