Skip to content
MultiVehicleSelector.qml 2.32 KiB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
Gus Grubba's avatar
Gus Grubba committed
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/


import QtQuick                              2.11
import QtQuick.Controls                     2.4
Gus Grubba's avatar
Gus Grubba committed

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
//-- Multiple Vehicle Selector
QGCComboBox {
Don Gagne's avatar
 
Don Gagne committed
    anchors.verticalCenter: parent.verticalCenter
    font.pointSize:         ScreenTools.mediumFontPointSize
    currentIndex:           -1
    sizeToContents:         true
    model:                  _vehicleModel
Don Gagne's avatar
 
Don Gagne committed

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

DonLakeFlyer's avatar
 
DonLakeFlyer committed
    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

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

DonLakeFlyer's avatar
 
DonLakeFlyer committed
    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
                }
            }
        }
DonLakeFlyer's avatar
 
DonLakeFlyer committed
        currentIndex = -1
        _vehicleModel = newModel
        currentIndex = newCurrentIndex
Gus Grubba's avatar
Gus Grubba committed
    }
DonLakeFlyer's avatar
 
DonLakeFlyer committed

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