PlanView.qml 29.6 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9 10


11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
13
import QtQuick.Dialogs  1.2
14 15 16
import QtLocation       5.3
import QtPositioning    5.3
import QtQuick.Layouts  1.2
17
import QtQuick.Window   2.2
Don Gagne's avatar
Don Gagne committed
18

19
import QGroundControl               1.0
Don Gagne's avatar
Don Gagne committed
20 21 22
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
23
import QGroundControl.FactSystem    1.0
24
import QGroundControl.FactControls  1.0
Don Gagne's avatar
Don Gagne committed
25
import QGroundControl.Palette       1.0
Don Gagne's avatar
Don Gagne committed
26
import QGroundControl.Mavlink       1.0
27
import QGroundControl.Controllers   1.0
Gus Grubba's avatar
Gus Grubba committed
28
import QGroundControl.Airmap        1.0
Don Gagne's avatar
Don Gagne committed
29 30

/// Mission Editor
Don Gagne's avatar
Don Gagne committed
31

Don Gagne's avatar
Don Gagne committed
32
QGCView {
33
    id:         _qgcView
34
    viewPanel:  panel
35
    z:          QGroundControl.zOrderTopMost
36

37
    readonly property int   _decimalPlaces:             8
Gus Grubba's avatar
Gus Grubba committed
38
    readonly property real  _horizontalMargin:          ScreenTools.defaultFontPixelWidth  * 0.5
39
    readonly property real  _margin:                    ScreenTools.defaultFontPixelHeight * 0.5
Gus Grubba's avatar
Gus Grubba committed
40
    readonly property real  _radius:                    ScreenTools.defaultFontPixelWidth  * 0.5
41 42 43 44 45
    readonly property var   _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle
    readonly property real  _rightPanelWidth:           Math.min(parent.width / 3, ScreenTools.defaultFontPixelWidth * 30)
    readonly property real  _toolButtonTopMargin:       parent.height - ScreenTools.availableHeight + (ScreenTools.defaultFontPixelHeight / 2)
    readonly property var   _defaultVehicleCoordinate:  QtPositioning.coordinate(37.803784, -122.462276)
    readonly property bool  _waypointsOnlyMode:         QGroundControl.corePlugin.options.missionWaypointsOnly
46

47 48 49 50 51
    property var    _planMasterController:      masterController
    property var    _missionController:         _planMasterController.missionController
    property var    _geoFenceController:        _planMasterController.geoFenceController
    property var    _rallyPointController:      _planMasterController.rallyPointController
    property var    _visualItems:               _missionController.visualItems
52 53
    property bool   _lightWidgetBorders:        editorMap.isSatelliteMap
    property bool   _addWaypointOnClick:        false
54
    property bool   _addROIOnClick:             false
55
    property bool   _singleComplexItem:         _missionController.complexMissionItemNames.length === 1
56 57
    property real   _toolbarHeight:             _qgcView.height - ScreenTools.availableHeight
    property int    _editingLayer:              _layerMission
58

59 60 61 62
    readonly property int       _layerMission:              1
    readonly property int       _layerGeoFence:             2
    readonly property int       _layerRallyPoints:          3
    readonly property string    _armedVehicleUploadPrompt:  qsTr("Vehicle is currently armed. Do you want to upload the mission to the vehicle?")
63

64
    Component.onCompleted: {
65
        toolbar.planMasterController =  Qt.binding(function () { return _planMasterController })
66
        toolbar.currentMissionItem =    Qt.binding(function () { return _missionController.currentPlanViewItem })
67 68
    }

69 70 71 72 73
    function addComplexItem(complexItemName) {
        var coordinate = editorMap.center
        coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
        coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
        coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
74
        insertComplexMissionItem(complexItemName, coordinate, _missionController.visualItems.count)
75 76 77
    }

    function insertComplexMissionItem(complexItemName, coordinate, index) {
78
        var sequenceNumber = _missionController.insertComplexMissionItem(complexItemName, coordinate, index)
79
        _missionController.setCurrentPlanViewIndex(sequenceNumber, true)
80 81
    }

82 83 84 85 86
    property bool _firstMissionLoadComplete:    false
    property bool _firstFenceLoadComplete:      false
    property bool _firstRallyLoadComplete:      false
    property bool _firstLoadComplete:           false

87 88 89 90
    MapFitFunctions {
        id:                         mapFitFunctions
        map:                        editorMap
        usePlannedHomePosition:     true
91
        planMasterController:       _planMasterController
92 93
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    Connections {
        target: QGroundControl.settingsManager.appSettings.defaultMissionItemAltitude

        onRawValueChanged: {
            if (_visualItems.count > 1) {
                _qgcView.showDialog(applyNewAltitude, qsTr("Apply new alititude"), showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
            }
        }
    }

    Component {
        id: applyNewAltitude

        QGCViewMessage {
            message:    qsTr("You have changed the default altitude for mission items. Would you like to apply that altitude to all the items in the current mission?")

            function accept() {
                hideDialog()
112
                _missionController.applyDefaultMissionAltitude()
DonLakeFlyer's avatar
DonLakeFlyer committed
113 114 115 116
            }
        }
    }

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    Component {
        id: activeMissionUploadDialogComponent

        QGCViewDialog {

            Column {
                anchors.fill:   parent
                spacing:        ScreenTools.defaultFontPixelHeight

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       qsTr("Your vehicle is currently flying a mission. In order to upload a new or modified mission the current mission will be paused.")
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       qsTr("After the mission is uploaded you can adjust the current waypoint and start the mission.")
                }

                QGCButton {
                    text:       qsTr("Pause and Upload")
                    onClicked: {
                        _activeVehicle.flightMode = _activeVehicle.pauseFlightMode
142
                        _planMasterController.sendToVehicle()
143
                        hideDialog()
144 145 146 147 148 149
                    }
                }
            }
        }
    }

150 151 152 153 154 155 156 157
    Component {
        id: noItemForKML

        QGCViewMessage {
            message:    qsTr("You need at least one item to create a KML.")
        }
    }

158
    PlanMasterController {
159
        id: masterController
160

161 162
        Component.onCompleted: {
            start(true /* editMode */)
163
            _missionController.setCurrentPlanViewIndex(0, true)
164 165
        }

166
        function upload() {
167
            if (_activeVehicle && _activeVehicle.armed && _activeVehicle.flightMode === _activeVehicle.missionFlightMode) {
168
                _qgcView.showDialog(activeMissionUploadDialogComponent, qsTr("Plan Upload"), _qgcView.showDialogDefaultWidth, StandardButton.Cancel)
169
            } else {
170 171
                sendToVehicle()
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
172 173
        }

174
        function loadFromSelectedFile() {
175
            fileDialog.title =          qsTr("Select Plan File")
176
            fileDialog.selectExisting = true
177
            fileDialog.nameFilters =    masterController.loadNameFilters
178
            fileDialog.openForLoad()
179 180 181
        }

        function saveToSelectedFile() {
182
            fileDialog.title =          qsTr("Save Plan")
183
            fileDialog.plan =           true
184
            fileDialog.selectExisting = false
185
            fileDialog.nameFilters =    masterController.saveNameFilters
186
            fileDialog.openForSave()
187 188
        }

189
        function fitViewportToItems() {
190
            mapFitFunctions.fitMapViewportToMissionItems()
191
        }
192 193 194 195 196 197 198 199

        function saveKmlToSelectedFile() {
            fileDialog.title =          qsTr("Save KML")
            fileDialog.plan =           false
            fileDialog.selectExisting = false
            fileDialog.nameFilters =    masterController.saveKmlFilters
            fileDialog.openForSave()
        }
200
    }
201

202 203
    Connections {
        target: _missionController
204

205
        onNewItemsFromVehicle: {
206 207 208
            if (_visualItems && _visualItems.count != 1) {
                mapFitFunctions.fitMapViewportToMissionItems()
            }
209
            _missionController.setCurrentPlanViewIndex(0, true)
210 211
        }
    }
212

213
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
Don Gagne's avatar
Don Gagne committed
214

215 216 217 218
    ExclusiveGroup {
        id: _mapTypeButtonsExclusiveGroup
    }

219 220 221 222
    /// Inserts a new simple mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertSimpleMissionItem(coordinate, index) {
223
        var sequenceNumber = _missionController.insertSimpleMissionItem(coordinate, index)
224
        _missionController.setCurrentPlanViewIndex(sequenceNumber, true)
225 226
    }

227 228 229 230 231 232 233 234 235 236
    /// Inserts a new ROI mission item
    ///     @param coordinate Location to insert item
    ///     @param index Insert item at this index
    function insertROIMissionItem(coordinate, index) {
        var sequenceNumber = _missionController.insertROIMissionItem(coordinate, index)
        _missionController.setCurrentPlanViewIndex(sequenceNumber, true)
        _addROIOnClick = false
        toolStrip.uncheckAll()
    }

237 238
    property int _moveDialogMissionItemIndex

239 240 241
    QGCFileDialog {
        id:             fileDialog
        qgcView:        _qgcView
242
        property var plan:           true
243
        folder:         QGroundControl.settingsManager.appSettings.missionSavePath
244 245
        fileExtension:  QGroundControl.settingsManager.appSettings.planFileExtension
        fileExtension2: QGroundControl.settingsManager.appSettings.missionFileExtension
246

247
        onAcceptedForSave: {
248
            plan ? masterController.saveToFile(file) : masterController.saveToKml(file)
249
            close()
250 251
        }

252
        onAcceptedForLoad: {
253 254
            masterController.loadFromFile(file)
            masterController.fitViewportToItems()
255
            _missionController.setCurrentPlanViewIndex(0, true)
256
            close()
257 258 259
        }
    }

260 261 262 263 264 265 266 267 268 269
    Component {
        id: moveDialog

        QGCViewDialog {
            function accept() {
                var toIndex = toCombo.currentIndex

                if (toIndex == 0) {
                    toIndex = 1
                }
270
                _missionController.moveMissionItem(_moveDialogMissionItemIndex, toIndex)
271 272 273 274 275 276 277 278 279 280 281 282
                hideDialog()
            }

            Column {
                anchors.left:   parent.left
                anchors.right:  parent.right
                spacing:        ScreenTools.defaultFontPixelHeight

                QGCLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
283
                    text:           qsTr("Move the selected mission item to the be after following mission item:")
284 285 286 287
                }

                QGCComboBox {
                    id:             toCombo
288
                    model:          _visualItems.count
289 290 291 292 293 294
                    currentIndex:   _moveDialogMissionItemIndex
                }
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
295 296
    QGCViewPanel {
        id:             panel
297
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
298

299
        FlightMap {
300 301 302 303 304
            id:                         editorMap
            anchors.fill:               parent
            mapName:                    "MissionEditor"
            allowGCSLocationCenter:     true
            allowVehicleLocationCenter: true
305
            planView:                   true
Don Gagne's avatar
Don Gagne committed
306

307
            // This is the center rectangle of the map which is not obscured by tools
Gus Grubba's avatar
Gus Grubba committed
308
            property rect centerViewport:   Qt.rect(_leftToolWidth, _toolbarHeight, editorMap.width - _leftToolWidth - _rightPanelWidth, editorMap.height - _statusHeight - _toolbarHeight)
309

310 311
            property real _leftToolWidth:   toolStrip.x + toolStrip.width
            property real _statusHeight:    waypointValuesDisplay.visible ? editorMap.height - waypointValuesDisplay.y : 0
312

313
            readonly property real animationDuration: 500
314

315 316
            // Initial map position duplicates Fly view position
            Component.onCompleted: editorMap.center = QGroundControl.flightMapPosition
317

318 319 320 321 322 323
            Behavior on zoomLevel {
                NumberAnimation {
                    duration:       editorMap.animationDuration
                    easing.type:    Easing.InOutQuad
                }
            }
324

325 326 327 328 329 330 331 332 333 334 335
            QGCMapPalette { id: mapPal; lightColors: editorMap.isSatelliteMap }

            MouseArea {
                //-- It's a whole lot faster to just fill parent and deal with top offset below
                //   than computing the coordinate offset.
                anchors.fill: parent
                onClicked: {
                    //-- Don't pay attention to items beneath the toolbar.
                    var topLimit = parent.height - ScreenTools.availableHeight
                    if(mouse.y < topLimit) {
                        return
336 337
                    }

338 339 340 341
                    var coordinate = editorMap.toCoordinate(Qt.point(mouse.x, mouse.y), false /* clipToViewPort */)
                    coordinate.latitude = coordinate.latitude.toFixed(_decimalPlaces)
                    coordinate.longitude = coordinate.longitude.toFixed(_decimalPlaces)
                    coordinate.altitude = coordinate.altitude.toFixed(_decimalPlaces)
342

343 344 345
                    switch (_editingLayer) {
                    case _layerMission:
                        if (_addWaypointOnClick) {
346
                            insertSimpleMissionItem(coordinate, _missionController.visualItems.count)
347 348 349
                        } else if (_addROIOnClick) {
                            _addROIOnClick = false
                            insertROIMissionItem(coordinate, _missionController.visualItems.count)
350
                        }
351 352
                        break
                    case _layerRallyPoints:
353
                        if (_rallyPointController.supported) {
354
                            _rallyPointController.addPoint(coordinate)
355
                        }
356
                        break
Don Gagne's avatar
Don Gagne committed
357
                    }
Don Gagne's avatar
Don Gagne committed
358
                }
359
            }
Don Gagne's avatar
Don Gagne committed
360

361 362
            // Add the mission item visuals to the map
            Repeater {
363
                model: _editingLayer == _layerMission ? _missionController.visualItems : undefined
364

365 366
                delegate: MissionItemMapVisual {
                    map:        editorMap
DonLakeFlyer's avatar
DonLakeFlyer committed
367
                    qgcView:    _qgcView
368
                    onClicked:  _missionController.setCurrentPlanViewIndex(sequenceNumber, false)
369
                    visible:    _editingLayer == _layerMission
370
                }
371
            }
372

373 374
            // Add lines between waypoints
            MissionLineView {
375
                model: _editingLayer == _layerMission ? _missionController.waypointLines : undefined
376
            }
377

378 379 380 381 382 383 384
            // Add the vehicles to the map
            MapItemView {
                model: QGroundControl.multiVehicleManager.vehicles
                delegate:
                    VehicleMapItem {
                    vehicle:        object
                    coordinate:     object.coordinate
385
                    map:            editorMap
386 387
                    size:           ScreenTools.defaultFontPixelHeight * 3
                    z:              QGroundControl.zOrderMapItems - 1
388
                }
389
            }
390

391 392
            GeoFenceMapVisuals {
                map:                    editorMap
393
                myGeoFenceController:   _geoFenceController
394
                interactive:            _editingLayer == _layerGeoFence
395
                homePosition:           _missionController.plannedHomePosition
396 397
                planView:               true
            }
398

399 400
            RallyPointMapVisuals {
                map:                    editorMap
401
                myRallyPointController: _rallyPointController
402 403
                interactive:            _editingLayer == _layerRallyPoints
                planView:               true
404
            }
405

406 407 408 409 410 411 412 413 414
            ToolStrip {
                id:                 toolStrip
                anchors.leftMargin: ScreenTools.defaultFontPixelWidth
                anchors.left:       parent.left
                anchors.topMargin:  _toolButtonTopMargin
                anchors.top:        parent.top
                color:              qgcPal.window
                title:              qsTr("Plan")
                z:                  QGroundControl.zOrderWidgets
415 416 417 418 419
                showAlternateIcon:  [ false, false, false, masterController.dirty, false, false, false ]
                rotateImage:        [ false, false, false, masterController.syncInProgress, false, false, false ]
                animateImage:       [ false, false, false, masterController.dirty, false, false, false ]
                buttonEnabled:      [ true, true, true, !masterController.syncInProgress, true, true, true ]
                buttonVisible:      [ true, _waypointsOnlyMode, true, true, true, _showZoom, _showZoom ]
420 421 422 423 424 425 426 427 428 429
                maxHeight:          mapScale.y - toolStrip.y

                property bool _showZoom: !ScreenTools.isMobile

                model: [
                    {
                        name:       "Waypoint",
                        iconSource: "/qmlimages/MapAddMission.svg",
                        toggle:     true
                    },
430 431 432 433 434
                    {
                        name:       "ROI",
                        iconSource: "/qmlimages/MapAddMission.svg",
                        toggle:     true
                    },
435
                    {
436
                        name:               _singleComplexItem ? _missionController.complexMissionItemNames[0] : "Pattern",
437 438 439
                        iconSource:         "/qmlimages/MapDrawShape.svg",
                        dropPanelComponent: _singleComplexItem ? undefined : patternDropPanel
                    },
440 441 442 443 444 445
                    {
                        name:                   "Sync",
                        iconSource:             "/qmlimages/MapSync.svg",
                        alternateIconSource:    "/qmlimages/MapSyncChanged.svg",
                        dropPanelComponent:     syncDropPanel
                    },
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
                    {
                        name:               "Center",
                        iconSource:         "/qmlimages/MapCenter.svg",
                        dropPanelComponent: centerMapDropPanel
                    },
                    {
                        name:               "In",
                        iconSource:         "/qmlimages/ZoomPlus.svg"
                    },
                    {
                        name:               "Out",
                        iconSource:         "/qmlimages/ZoomMinus.svg"
                    }
                ]

                onClicked: {
                    switch (index) {
                    case 0:
                        _addWaypointOnClick = checked
465
                        _addROIOnClick = false
466 467
                        break
                    case 1:
468 469 470 471
                        _addROIOnClick = checked
                        _addWaypointOnClick = false
                        break
                    case 2:
472
                        if (_singleComplexItem) {
473
                            addComplexItem(_missionController.complexMissionItemNames[0])
474
                        }
475
                        break
476
                    case 5:
477 478
                        editorMap.zoomLevel += 0.5
                        break
479
                    case 6:
480 481 482 483 484
                        editorMap.zoomLevel -= 0.5
                        break
                    }
                }
            }
Gus Grubba's avatar
Gus Grubba committed
485 486
        }
        //-----------------------------------------------------------
487 488 489
        // Right pane for mission editing controls
        Rectangle {
            id:                 rightPanel
490
            height:             ScreenTools.availableHeight
491 492
            width:              _rightPanelWidth
            color:              qgcPal.window
493
            opacity:            0.2
Gus Grubba's avatar
Gus Grubba committed
494 495 496
            anchors.bottom:     parent.bottom
            anchors.right:      parent.right
            anchors.rightMargin: ScreenTools.defaultFontPixelWidth
497 498
        }
        Item {
Gus Grubba's avatar
Gus Grubba committed
499 500 501 502
            anchors.fill:           rightPanel
            Column {
                id:                 rightControls
                spacing:            ScreenTools.defaultFontPixelHeight * 0.25
503 504
                anchors.left:       parent.left
                anchors.right:      parent.right
Gus Grubba's avatar
Gus Grubba committed
505 506 507 508 509 510
                anchors.top:        parent.top
                anchors.topMargin:  ScreenTools.defaultFontPixelHeight * 0.25
                //-------------------------------------------------------
                // Airmap Airspace Control
                AirspaceControl {
                    width:      parent.width
511
                }
Gus Grubba's avatar
Gus Grubba committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                //-------------------------------------------------------
                // Mission Controls (Colapsed)
                Rectangle {
                    id:         planColapsed
                    width:      parent.width
                    height:     colapsedRow.height + ScreenTools.defaultFontPixelHeight
                    color:      qgcPal.missionItemEditor
                    radius:     _radius
                    Row {
                        id:                     colapsedRow
                        spacing:                ScreenTools.defaultFontPixelWidth
                        anchors.left:           parent.left
                        anchors.leftMargin:     ScreenTools.defaultFontPixelWidth
                        anchors.verticalCenter: parent.verticalCenter
                        QGCColoredImage {
                            width:                  height
                            height:                 ScreenTools.defaultFontPixelWidth * 2.5
                            sourceSize.height:      height
                            source:                 "qrc:/res/waypoint.svg"
                            color:                  qgcPal.text
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCLabel {
                            id:     colapsedPlanLabel
                            text:   qsTr("Plan")
                            color:  qgcPal.text
                            anchors.verticalCenter: parent.verticalCenter
539 540
                        }
                    }
Gus Grubba's avatar
Gus Grubba committed
541
                }
542
            }
Gus Grubba's avatar
Gus Grubba committed
543
        }
544 545 546 547 548 549 550 551 552 553 554 555 556 557

        MapScale {
            id:                 mapScale
            anchors.margins:    ScreenTools.defaultFontPixelHeight * (0.66)
            anchors.bottom:     waypointValuesDisplay.visible ? waypointValuesDisplay.top : parent.bottom
            anchors.left:       parent.left
            mapControl:         editorMap
            visible:            !ScreenTools.isTinyScreen
        }

        MissionItemStatus {
            id:                 waypointValuesDisplay
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            anchors.left:       parent.left
558
            height:             ScreenTools.defaultFontPixelHeight * 7
559
            maxWidth:           parent.width - rightPanel.width - x
560
            anchors.bottom:     parent.bottom
561
            missionItems:       _missionController.visualItems
562
            visible:            _editingLayer === _layerMission && (ScreenTools.isMobile ? height < Screen.height * 0.25 : true)
563
        }
Don Gagne's avatar
Don Gagne committed
564
    } // QGCViewPanel
565

566 567 568 569
    Component {
        id: syncLoadFromVehicleOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
Don Gagne's avatar
Don Gagne committed
570
            message:   qsTr("You have unsaved/unsent changes. Loading from the Vehicle will lose these changes. Are you sure you want to load from the Vehicle?")
571 572
            function accept() {
                hideDialog()
573
                masterController.loadFromVehicle()
574 575 576 577 578 579 580 581
            }
        }
    }

    Component {
        id: syncLoadFromFileOverwrite
        QGCViewMessage {
            id:         syncLoadFromVehicleCheck
DonLakeFlyer's avatar
DonLakeFlyer committed
582
            message:   qsTr("You have unsaved/unsent changes. Loading from a file will lose these changes. Are you sure you want to load from a file?")
583 584
            function accept() {
                hideDialog()
585
                masterController.loadFromSelectedFile()
586 587 588 589
            }
        }
    }

590 591 592
    Component {
        id: removeAllPromptDialog
        QGCViewMessage {
593 594
            message: qsTr("Are you sure you want to remove all items? ") +
                     (_planMasterController.offline ? "" : qsTr("This will also remove all items from the vehicle."))
595
            function accept() {
596 597 598 599 600
                if (_planMasterController.offline) {
                    masterController.removeAll()
                } else {
                    masterController.removeAllFromVehicle()
                }
601 602 603 604 605
                hideDialog()
            }
        }
    }

606 607 608 609 610 611 612 613 614 615 616
    //- ToolStrip DropPanel Components

    Component {
        id: centerMapDropPanel

        CenterMapDropPanel {
            map:            editorMap
            fitFunctions:   mapFitFunctions
        }
    }

617 618 619 620 621 622 623 624 625
    Component {
        id: patternDropPanel

        ColumnLayout {
            spacing:    ScreenTools.defaultFontPixelWidth * 0.5

            QGCLabel { text: qsTr("Create complex pattern:") }

            Repeater {
626
                model: _missionController.complexMissionItemNames
627 628 629 630 631 632

                QGCButton {
                    text:               modelData
                    Layout.fillWidth:   true

                    onClicked: {
633
                        addComplexItem(modelData)
634 635 636 637 638 639
                        dropPanel.hide()
                    }
                }
            }
        } // Column
    }
640 641

    Component {
642
        id: syncDropPanel
643

644 645 646
        Column {
            id:         columnHolder
            spacing:    _margin
647

648
            property string _overwriteText: (_editingLayer == _layerMission) ? qsTr("Mission overwrite") : ((_editingLayer == _layerGeoFence) ? qsTr("GeoFence overwrite") : qsTr("Rally Points overwrite"))
649

650 651 652
            QGCLabel {
                width:      sendSaveGrid.width
                wrapMode:   Text.WordWrap
653
                text:       masterController.dirty ?
654 655
                                qsTr("You have unsaved changes. You should upload to your vehicle, or save to a file:") :
                                qsTr("Sync:")
656 657
            }

658 659 660 661 662 663
            GridLayout {
                id:                 sendSaveGrid
                columns:            2
                anchors.margins:    _margin
                rowSpacing:         _margin
                columnSpacing:      ScreenTools.defaultFontPixelWidth
664

665 666 667
                QGCButton {
                    text:               qsTr("Upload")
                    Layout.fillWidth:   true
668
                    enabled:            !masterController.offline && !masterController.syncInProgress
669 670
                    onClicked: {
                        dropPanel.hide()
671
                        masterController.upload()
672 673
                    }
                }
674

675 676 677
                QGCButton {
                    text:               qsTr("Download")
                    Layout.fillWidth:   true
678
                    enabled:            !masterController.offline && !masterController.syncInProgress
679 680
                    onClicked: {
                        dropPanel.hide()
681
                        if (masterController.dirty) {
682 683
                            _qgcView.showDialog(syncLoadFromVehicleOverwrite, columnHolder._overwriteText, _qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
                        } else {
684
                            masterController.loadFromVehicle()
685 686 687
                        }
                    }
                }
688

689 690 691
                QGCButton {
                    text:               qsTr("Save To File...")
                    Layout.fillWidth:   true
692
                    enabled:            !masterController.syncInProgress
693 694
                    onClicked: {
                        dropPanel.hide()
695
                        masterController.saveToSelectedFile()
696 697 698 699 700 701
                    }
                }

                QGCButton {
                    text:               qsTr("Load From File...")
                    Layout.fillWidth:   true
702
                    enabled:            !masterController.syncInProgress
703 704
                    onClicked: {
                        dropPanel.hide()
705
                        if (masterController.dirty) {
706 707
                            _qgcView.showDialog(syncLoadFromFileOverwrite, columnHolder._overwriteText, _qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.Cancel)
                        } else {
708
                            masterController.loadFromSelectedFile()
709 710 711 712 713 714 715 716 717 718 719 720
                        }
                    }
                }

                QGCButton {
                    text:               qsTr("Remove All")
                    Layout.fillWidth:   true
                    onClicked:  {
                        dropPanel.hide()
                        _qgcView.showDialog(removeAllPromptDialog, qsTr("Remove all"), _qgcView.showDialogDefaultWidth, StandardButton.Yes | StandardButton.No)
                    }
                }
721 722 723 724 725 726

                QGCButton {
                    text:               qsTr("Save KML...")
                    Layout.fillWidth:   true
                    enabled:            !masterController.syncInProgress
                    onClicked: {
727 728 729 730 731
                        // First point do not count
                        if (_visualItems.count < 2) {
                            _qgcView.showDialog(noItemForKML, qsTr("KML"), _qgcView.showDialogDefaultWidth, StandardButton.Cancel)
                            return
                        }
732 733 734 735
                        dropPanel.hide()
                        masterController.saveKmlToSelectedFile()
                    }
                }
736
            }
737 738
        }
    }
Don Gagne's avatar
Don Gagne committed
739
} // QGCVIew