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


11 12
import QtQuick                              2.11
import QtQuick.Controls                     2.4
Gus Grubba's avatar
Gus Grubba committed
13 14 15 16 17 18 19 20

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0

//-------------------------------------------------------------------------
DonLakeFlyer's avatar
DonLakeFlyer committed
21 22
//-- Multiple Vehicle Selector
QGCComboBox {
23 24 25 26 27
    anchors.verticalCenter: parent.verticalCenter
    font.pointSize:         ScreenTools.mediumFontPointSize
    currentIndex:           -1
    sizeToContents:         true
    model:                  _vehicleModel
28 29

    property bool showIndicator: _multipleVehicles
Gus Grubba's avatar
Gus Grubba committed
30

DonLakeFlyer's avatar
DonLakeFlyer committed
31
    property var    _activeVehicle:     QGroundControl.multiVehicleManager.activeVehicle
32
    property bool   _multipleVehicles:  QGroundControl.multiVehicleManager.vehicles.count > 1
DonLakeFlyer's avatar
DonLakeFlyer committed
33
    property var    _vehicleModel:      [ ]
Gus Grubba's avatar
Gus Grubba committed
34 35 36

    Connections {
        target:         QGroundControl.multiVehicleManager.vehicles
DonLakeFlyer's avatar
DonLakeFlyer committed
37
        onCountChanged:  _updateVehicleModel()
Gus Grubba's avatar
Gus Grubba committed
38 39
    }

40 41
    Component.onCompleted:      _updateVehicleModel()
    on_ActiveVehicleChanged:    _updateVehicleModel()
DonLakeFlyer's avatar
DonLakeFlyer committed
42 43 44 45 46 47 48 49 50 51 52

    function _updateVehicleModel() {
        var newCurrentIndex = -1
        var newModel = [ ]
        if (_multipleVehicles) {
            for (var i = 0; i < QGroundControl.multiVehicleManager.vehicles.count; i++) {
                var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
                newModel.push(qsTr("Vehicle") + " " + vehicle.id)

                if (vehicle.id === _activeVehicle.id) {
                    newCurrentIndex = i
Gus Grubba's avatar
Gus Grubba committed
53 54 55
                }
            }
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
56 57 58
        currentIndex = -1
        _vehicleModel = newModel
        currentIndex = newCurrentIndex
Gus Grubba's avatar
Gus Grubba committed
59
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
60 61 62 63 64

    onActivated: {
        var vehicleId = textAt(index).split(" ")[1]
        var vehicle = QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
        QGroundControl.multiVehicleManager.activeVehicle = vehicle
Gus Grubba's avatar
Gus Grubba committed
65 66
    }
}
DonLakeFlyer's avatar
DonLakeFlyer committed
67