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
    property alias latitude: flightMap.latitude
    property alias longitude: flightMap.longitude

47 48 49 50 51 52 53
    // 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

54
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
55 56 57

    property var _activeVehicle: multiVehicleManager.activeVehicle

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

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

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

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

76
    property var  _vehicleCoordinate:   _activeVehicle ? (_activeVehicle.coordinateValid ? _activeVehicle.coordinate : _defaultVehicleCoordinate) : _defaultVehicleCoordinate
77

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

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

85
    FlightDisplayViewController { id: _controller }
86 87 88 89 90 91

    MissionController {
        id: _missionController

        Component.onCompleted: start(false /* editMode */)
    }
92

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

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

101 102 103 104 105 106
        // 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
107

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

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

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

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

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

132 133
        property bool _followVehicle: true

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

        function updateMapPosition(force) {
137 138 139
            if ((_followVehicle || force) && rootLoadCompleted) {
                flightMap.latitude = root._vehicleCoordinate.latitude
                flightMap.longitude = root._vehicleCoordinate.longitude
Don Gagne's avatar
Don Gagne committed
140 141
            }
        }
dogmaphobic's avatar
dogmaphobic committed
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
Gus Grubba's avatar
Gus Grubba committed
148
            z:              QGroundControl.zOrderMapItems
149 150
        }

151 152 153
        // Add trajectory points to the map
        MapItemView {
            model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.trajectoryPoints : 0
Gus Grubba's avatar
Gus Grubba committed
154

155 156 157 158
            delegate:
                MapPolyline {
                    line.width: 3
                    line.color: "orange"
Gus Grubba's avatar
Gus Grubba committed
159
                    z:          QGroundControl.zOrderMapItems - 1
160

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
        // Add the vehicles to the map
        MapItemView {
            model: multiVehicleManager.vehicles
Gus Grubba's avatar
Gus Grubba committed
172

173 174
            delegate:
                VehicleMapItem {
175
                        vehicle:        object
176
                        coordinate:     object.coordinate
177
                        isSatellite:    flightMap.isSatelliteMap
Gus Grubba's avatar
Gus Grubba committed
178
                        z:              QGroundControl.zOrderMapItems
179 180 181 182
                }
        }

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

187 188 189 190 191
        // Add lines between waypoints
        MissionLineView {
            model:          _missionController.waypointLines
        }

192 193 194 195
        // Used to make pinch zoom work
        MouseArea {
            anchors.fill: parent
        }
Don Gagne's avatar
Don Gagne committed
196 197
    } // Flight Map

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