VehicleComponent.cc 2.1 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
{
23
    Q_ASSERT(vehicle);
Don Gagne's avatar
Don Gagne committed
24
    Q_ASSERT(autopilot);
25 26 27 28 29 30
}

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

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));
}
48 49 50 51 52

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

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

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