PlanElementController.cc 1.64 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

#include "PlanElementController.h"
#include "QGCApplication.h"
12
#include "MultiVehicleManager.h"
13 14 15 16

PlanElementController::PlanElementController(QObject* parent)
    : QObject(parent)
    , _multiVehicleMgr(qgcApp()->toolbox()->multiVehicleManager())
17
    , _activeVehicle(_multiVehicleMgr->offlineEditingVehicle())
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
    , _editMode(false)
{

}

PlanElementController::~PlanElementController()
{

}

void PlanElementController::start(bool editMode)
{
    _editMode = editMode;
    connect(_multiVehicleMgr, &MultiVehicleManager::activeVehicleChanged, this, &PlanElementController::_activeVehicleChanged);
    _activeVehicleChanged(_multiVehicleMgr->activeVehicle());
}

35 36 37 38 39 40
void PlanElementController::startStaticActiveVehicle(Vehicle* vehicle)
{
    _editMode = false;
    _activeVehicleChanged(vehicle);
}

41 42 43
void PlanElementController::_activeVehicleChanged(Vehicle* activeVehicle)
{
    if (_activeVehicle) {
44
        _activeVehicleBeingRemoved();
45
        _activeVehicle = NULL;
46 47
    }

48 49 50 51
    if (activeVehicle) {
        _activeVehicle = activeVehicle;
    } else {
        _activeVehicle = _multiVehicleMgr->offlineEditingVehicle();
52
    }
53
    _activeVehicleSet();
54 55 56

    // Whenever vehicle changes we need to update syncInProgress
    emit syncInProgressChanged(syncInProgress());
57 58

    emit vehicleChanged(_activeVehicle);
59
}