VehicleComponent.cc 2.04 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

17
VehicleComponent::VehicleComponent(Vehicle* vehicle, AutoPilotPlugin* autopilot, QObject* parent) :
18
    QObject(parent),
19
    _vehicle(vehicle),
Don Gagne's avatar
Don Gagne committed
20
    _autopilot(autopilot)
21
{
22
    Q_ASSERT(vehicle);
Don Gagne's avatar
Don Gagne committed
23
    Q_ASSERT(autopilot);
24 25 26 27 28 29
}

VehicleComponent::~VehicleComponent()
{
    
}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

void VehicleComponent::addSummaryQmlComponent(QQmlContext* context, QQuickItem* parent)
{
    Q_ASSERT(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) {
        qDebug() << component.errors();
        Q_ASSERT(false);
    }
    
    QQuickItem* item = qobject_cast<QQuickItem*>(component.create(context));
    Q_ASSERT(item);
    item->setParentItem(parent);
    item->setProperty("vehicleComponent", QVariant::fromValue(this));
}
47 48 49 50 51

void VehicleComponent::setupTriggerSignals(void)
{
    // Watch for changed on trigger list params
    foreach (const QString &paramName, setupCompleteChangedTriggerList()) {
Don Gagne's avatar
Don Gagne committed
52 53 54 55
        if (_autopilot->parameterExists(FactSystem::defaultComponentId, paramName)) {
            Fact* fact = _autopilot->getParameterFact(FactSystem::defaultComponentId, paramName);
            connect(fact, &Fact::valueChanged, this, &VehicleComponent::_triggerUpdated);
        }
56 57 58 59 60 61 62
    }
}

void VehicleComponent::_triggerUpdated(QVariant /*value*/)
{
    emit setupCompleteChanged(setupComplete());
}
63 64 65 66 67 68

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