MultiVehicleSelector.qml 2.32 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 32 33
    property var    _activeVehicle:     QGroundControl.multiVehicleManager.activeVehicle
    property bool   _multipleVehicles:  _activeVehicle ? QGroundControl.multiVehicleManager.vehicles.count > 1 : false
    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
    }

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

    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
52 53 54
                }
            }
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
55 56 57
        currentIndex = -1
        _vehicleModel = newModel
        currentIndex = newCurrentIndex
Gus Grubba's avatar
Gus Grubba committed
58
    }
DonLakeFlyer's avatar
DonLakeFlyer committed
59 60 61 62 63

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