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

10 11 12 13 14

/// @file
///     @author Don Gagne <don@thegagnes.com>

#include "VehicleComponent.h"
Don Gagne's avatar
Don Gagne committed
15
#include "AutoPilotPlugin.h"
16
#include "ParameterManager.h"
17

18
VehicleComponent::VehicleComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
19
    QObject(parent),
20
    _vehicle(vehicle),
Don Gagne's avatar
Don Gagne committed
21
    _autopilot(autopilot)
22
{
DonLakeFlyer's avatar
DonLakeFlyer committed
23 24 25
    if (!vehicle || !autopilot) {
        qWarning() << "Internal error";
    }
26 27 28 29 30 31
}

VehicleComponent::~VehicleComponent()
{
    
}
32 33 34

void VehicleComponent::addSummaryQmlComponent(QQmlContext* context, QQuickItem* parent)
{
DonLakeFlyer's avatar
DonLakeFlyer committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    if (context) {
        // FIXME: We own this object now, need to delete somewhere
        QQmlComponent component(context->engine(), QUrl::fromUserInput("qrc:/qml/VehicleComponentSummaryButton.qml"));
        if (component.status() == QQmlComponent::Error) {
            qWarning() << component.errors();
        } else {
            QQuickItem* item = qobject_cast<QQuickItem*>(component.create(context));
            if (item) {
                item->setParentItem(parent);
                item->setProperty("vehicleComponent", QVariant::fromValue(this));
            } else {
                qWarning() << "Internal error";
            }
        }
    } else {
        qWarning() << "Internal error";
51 52
    }
}
53 54 55 56 57

void VehicleComponent::setupTriggerSignals(void)
{
    // Watch for changed on trigger list params
    foreach (const QString &paramName, setupCompleteChangedTriggerList()) {
58 59
        if (_vehicle->parameterManager()->parameterExists(FactSystem::defaultComponentId, paramName)) {
            Fact* fact = _vehicle->parameterManager()->getParameter(FactSystem::defaultComponentId, paramName);
Don Gagne's avatar
Don Gagne committed
60 61
            connect(fact, &Fact::valueChanged, this, &VehicleComponent::_triggerUpdated);
        }
62 63 64 65 66 67 68
    }
}

void VehicleComponent::_triggerUpdated(QVariant /*value*/)
{
    emit setupCompleteChanged(setupComplete());
}
69 70 71 72 73 74

bool VehicleComponent::allowSetupWhileArmed(void) const
{
    // Default is to not allow setup while armed
    return false;
}