Commit 558b23f8 authored by Don Gagne's avatar Don Gagne

AutoPilot plugin restructuring for better QML support

- properties now hand off of main “autopilot” object in qml
- Added support for summary items through qml
parent b82bfe84
import QtQuick 2.2
import QtQuick.Controls 1.2
import QGroundControl.FactSystem 1.0
TextInput {
property Fact fact
text: fact.value
font.family: "Helvetica"
font.pointSize: 24
color: "red"
focus: true
onAccepted: { fact.value = text; }
}
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Button {
text: "Button"
property bool setupComplete: false
property var summaryModel: ListModel {
ListElement { name: "Row 1"; state: "State 1" }
ListElement { name: "Row 2"; state: "State 2" }
ListElement { name: "Row 3"; state: "State 3" }
}
style: ButtonStyle {
id: buttonStyle
background: Rectangle {
id: innerRect
readonly property real titleHeight: 30
//property alias summaryModel: summaryList.model
border.color: "#888"
radius: 10
color: control.activeFocus ? "#47b" : "white"
opacity: control.hovered || control.activeFocus ? 1 : 0.75
Behavior on opacity {NumberAnimation{ duration: 100 }}
Text {
id: titleBar
width: parent.width
height: parent.titleHeight
verticalAlignment: TextEdit.AlignVCenter
horizontalAlignment: TextEdit.AlignHCenter
text: control.text
font.pixelSize: 12
Rectangle {
id: setupIndicator
property bool setupComplete: true
readonly property real indicatorRadius: 6
x: parent.width - (indicatorRadius * 2) - 5
y: (parent.height - (indicatorRadius * 2)) / 2
width: indicatorRadius * 2
height: indicatorRadius * 2
radius: indicatorRadius
color: control.setupComplete ? "green" : "red"
}
}
Rectangle {
width: parent.width
height: parent.height - parent.titleHeight
y: parent.titleHeight
border.color: "#888"
gradient: Gradient {
GradientStop { position: 0; color: "#ffffff" }
GradientStop { position: 1; color: "#000000" }
}
ListView {
id: summaryList
anchors.fill: parent
model: control.summaryModel
delegate: Row {
Text { text: modelData.name }
Text { text: modelData.state }
}
}
}
}
label: Item {}
}
}
/*
Rectangle {
readonly property real titleHeight: 30
property alias title: titleBar.text
property alias setupComplete: setupIndicator.setupComplete
//property alias summaryModel: summaryList.model
border.color: "#888"
radius: 10
gradient: Gradient {
GradientStop { position: 0 ; color: "#cccccc" }
GradientStop { position: 1 ; color: "#aaa" }
}
Text {
id: titleBar
width: parent.width
height: parent.titleHeight
verticalAlignment: TextEdit.AlignVCenter
horizontalAlignment: TextEdit.AlignHCenter
text: qsTr("TITLE")
font.pixelSize: 12
Rectangle {
id: setupIndicator
property bool setupComplete: true
readonly property real indicatorRadius: 6
x: parent.width - (indicatorRadius * 2) - 5
y: (parent.height - (indicatorRadius * 2)) / 2
width: indicatorRadius * 2
height: indicatorRadius * 2
radius: indicatorRadius
color: setupComplete ? "green" : "red"
}
}
Rectangle {
width: parent.width
height: parent.height - parent.titleHeight
y: parent.titleHeight
border.color: "#888"
gradient: Gradient {
GradientStop {
position: 0
color: "#ffffff"
}
GradientStop {
position: 1
color: "#000000"
}
}
ListView {
id: summaryList
anchors.fill: parent
model: ListModel {
ListElement { name: "Row 1"; state: "State 1" }
ListElement { name: "Row 2"; state: "State 2" }
ListElement { name: "Row 3"; state: "State 3" }
}
delegate: Row { Text { text: modelData.name } Text { text: modelData.state } }
}
}
}
*/
\ No newline at end of file
Module QGroundControl.FactControls Module QGroundControl.FactControls
FactTextInput 1.0 FactTextInput.qml SetupButton 1.0 SetupButton.qml
\ No newline at end of file \ No newline at end of file
...@@ -48,18 +48,14 @@ class AutoPilotPlugin : public QObject ...@@ -48,18 +48,14 @@ class AutoPilotPlugin : public QObject
Q_OBJECT Q_OBJECT
public: public:
/// @brief Returns the list of VehicleComponent objects associated with the AutoPilot. Q_PROPERTY(QVariantMap parameters READ parameters CONSTANT)
virtual QList<VehicleComponent*> getVehicleComponents(void) const = 0; Q_PROPERTY(QVariantList components READ components CONSTANT)
Q_PROPERTY(QUrl setupBackgroundImage READ setupBackgroundImage CONSTANT)
/// Returns the parameter facts for the specified UAS. // Property accessors
/// virtual const QVariantList& components(void) = 0;
/// Key is parameter name. Get Fact object like this: _mapParameterName2Variant["RC_MAP_THROTTLE"].value<Fact*>(). virtual const QVariantMap& parameters(void) = 0;
/// You should not request parameter facts until the plugin reports that it is ready. virtual QUrl setupBackgroundImage(void) = 0;
virtual const QVariantMap& parameterFacts(void) const = 0;
/// Adds the FactSystem properties to the Qml context. You should not call
/// this method until the plugin reports that it is ready.
virtual void addFactsToQmlContext(QQmlContext* context) const = 0;
/// Returns true if the plugin is ready for use /// Returns true if the plugin is ready for use
virtual bool pluginIsReady(void) const = 0; virtual bool pluginIsReady(void) const = 0;
...@@ -72,8 +68,9 @@ signals: ...@@ -72,8 +68,9 @@ signals:
void pluginReady(void); void pluginReady(void);
protected: protected:
// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin /// All access to AutoPilotPugin objects is through getInstanceForAutoPilotPlugin
AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { } AutoPilotPlugin(QObject* parent = NULL) : QObject(parent) { }
}; };
#endif #endif
...@@ -32,12 +32,6 @@ GenericAutoPilotPlugin::GenericAutoPilotPlugin(UASInterface* uas, QObject* paren ...@@ -32,12 +32,6 @@ GenericAutoPilotPlugin::GenericAutoPilotPlugin(UASInterface* uas, QObject* paren
Q_UNUSED(uas); Q_UNUSED(uas);
} }
QList<VehicleComponent*> GenericAutoPilotPlugin::getVehicleComponents(void) const
{
// Generic autopilot has no configurable components
return QList<VehicleComponent*>();
}
QList<AutoPilotPluginManager::FullMode_t> GenericAutoPilotPlugin::getModes(void) QList<AutoPilotPluginManager::FullMode_t> GenericAutoPilotPlugin::getModes(void)
{ {
AutoPilotPluginManager::FullMode_t fullMode; AutoPilotPluginManager::FullMode_t fullMode;
...@@ -83,13 +77,20 @@ QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t cust ...@@ -83,13 +77,20 @@ QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t cust
return mode; return mode;
} }
void GenericAutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const void GenericAutoPilotPlugin::clearStaticData(void)
{ {
Q_UNUSED(context); // No Static data yet
}
const QVariantList& GenericAutoPilotPlugin::components(void)
{
static QVariantList staticList;
Q_ASSERT_X(false, "Not yet implemented", ""); Q_ASSERT_X(false, "Not yet implemented", "");
return staticList;
} }
const QVariantMap& GenericAutoPilotPlugin::parameterFacts(void) const const QVariantMap& GenericAutoPilotPlugin::parameters(void)
{ {
static QVariantMap staticMap; static QVariantMap staticMap;
...@@ -97,7 +98,10 @@ const QVariantMap& GenericAutoPilotPlugin::parameterFacts(void) const ...@@ -97,7 +98,10 @@ const QVariantMap& GenericAutoPilotPlugin::parameterFacts(void) const
return staticMap; return staticMap;
} }
void GenericAutoPilotPlugin::clearStaticData(void) QUrl GenericAutoPilotPlugin::setupBackgroundImage(void)
{ {
// No Static data yet static QUrl url;
Q_ASSERT_X(false, "Not yet implemented", "");
return url;
} }
...@@ -40,14 +40,16 @@ public: ...@@ -40,14 +40,16 @@ public:
GenericAutoPilotPlugin(UASInterface* uas, QObject* parent = NULL); GenericAutoPilotPlugin(UASInterface* uas, QObject* parent = NULL);
// Overrides from AutoPilotPlugin // Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) const ;
virtual void addFactsToQmlContext(QQmlContext* context) const;
virtual const QVariantMap& parameterFacts(void) const;
virtual bool pluginIsReady(void) const { return true; } virtual bool pluginIsReady(void) const { return true; }
virtual QUrl setupBackgroundImage(void);
virtual const QVariantList& components(void);
virtual const QVariantMap& parameters(void);
static QList<AutoPilotPluginManager::FullMode_t> getModes(void); static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
static QString getShortModeText(uint8_t baseMode, uint32_t customMode); static QString getShortModeText(uint8_t baseMode, uint32_t customMode);
static void clearStaticData(void); static void clearStaticData(void);
protected:
}; };
#endif #endif
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "AirframeComponent.h" #include "AirframeComponent.h"
#include "QGCPX4AirframeConfig.h" #include "QGCPX4AirframeConfig.h"
#include "VehicleComponentSummaryItem.h"
/// @brief Parameters which signal a change in setupComplete state /// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "SYS_AUTOSTART", NULL }; static const char* triggerParams[] = { "SYS_AUTOSTART", NULL };
...@@ -161,56 +162,65 @@ QWidget* AirframeComponent::setupWidget(void) const ...@@ -161,56 +162,65 @@ QWidget* AirframeComponent::setupWidget(void) const
return new QGCPX4AirframeConfig; return new QGCPX4AirframeConfig;
} }
QList<QStringList> AirframeComponent::summaryItems(void) const const QVariantList& AirframeComponent::summaryItems(void)
{ {
// Fill the items on first reference
// FIXME: These items are not live
if (!_summaryItems.count()) {
QString name;
QString state;
QVariant value; QVariant value;
QStringList row;
QList<QStringList> items;
row << "System ID:"; name = "System ID:";
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "MAV_SYS_ID", value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "MAV_SYS_ID", value)) {
if (value.toInt() == 0) { if (value.toInt() == 0) {
row << "Setup required"; state = "Setup required";
} else { } else {
row << value.toString(); state = value.toString();
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
} }
items << row;
row.clear(); VehicleComponentSummaryItem* item = new VehicleComponentSummaryItem(name, state, this);
row << "Airframe:"; _summaryItems.append(QVariant::fromValue(item));
name = "Airframe:";
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "SYS_AUTOSTART", value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "SYS_AUTOSTART", value)) {
if (value.toInt() == 0) { if (value.toInt() == 0) {
row << "Setup required"; state = "Setup required";
} else { } else {
row << value.toString(); state = value.toString();
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
} }
items << row;
row.clear(); item = new VehicleComponentSummaryItem(name, state, this);
row << "Type:"; _summaryItems.append(QVariant::fromValue(item));
name = "Type:";
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "MAV_TYPE", value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), "MAV_TYPE", value)) {
int index = value.toInt(); int index = value.toInt();
if (index < 0 || index >= (int)cMavTypes) { if (index < 0 || index >= (int)cMavTypes) {
row << "Unknown"; state = "Unknown";
} else { } else {
row << mavTypeInfo[index].description; state = mavTypeInfo[index].description;
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
row << "Unknown"; state = "Unknown";
}
item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
} }
items << row;
return items; return _summaryItems;
} }
...@@ -49,10 +49,11 @@ public: ...@@ -49,10 +49,11 @@ public:
virtual QString setupStateDescription(void) const; virtual QString setupStateDescription(void) const;
virtual QWidget* setupWidget(void) const; virtual QWidget* setupWidget(void) const;
virtual QStringList paramFilterList(void) const; virtual QStringList paramFilterList(void) const;
virtual QList<QStringList> summaryItems(void) const; virtual const QVariantList& summaryItems(void);
private: private:
const QString _name; const QString _name;
QVariantList _summaryItems;
}; };
#endif #endif
...@@ -6,27 +6,28 @@ ...@@ -6,27 +6,28 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>831</width> <width>642</width>
<height>1286</height> <height>645</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>642</width>
<height>645</height>
</size>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_8">
<property name="font">
<font>
<pointsize>22</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>This implementation is a work in progress. Visuals are meant to be functional only. Active display of switch positions is not yet implemented. If this entire screen is disabled, you must do a Radio Calibration before settings Flight Modes.</string> <string>This implementation is a work in progress. Visuals are meant to be functional only. Active display of switch positions is not yet implemented. If this entire screen is disabled, you must do a Radio Calibration before settings Flight Modes.</string>
</property> </property>
...@@ -205,19 +206,6 @@ ...@@ -205,19 +206,6 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "FlightModesComponent.h" #include "FlightModesComponent.h"
#include "FlightModeConfig.h" #include "FlightModeConfig.h"
#include "VehicleComponentSummaryItem.h"
/// @brief Parameters which signal a change in setupComplete state /// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "RC_MAP_MODE_SW", NULL }; static const char* triggerParams[] = { "RC_MAP_MODE_SW", NULL };
...@@ -116,17 +117,18 @@ QWidget* FlightModesComponent::setupWidget(void) const ...@@ -116,17 +117,18 @@ QWidget* FlightModesComponent::setupWidget(void) const
return new FlightModeConfig(); return new FlightModeConfig();
} }
QList<QStringList> FlightModesComponent::summaryItems(void) const const QVariantList& FlightModesComponent::summaryItems(void)
{ {
QList<QStringList> items; if (!_summaryItems.count()) {
// Create summary items for each mode switch // Create summary items for each mode switch
for (size_t i=0; i<cSwitchList; i++) { for (size_t i=0; i<cSwitchList; i++) {
QString name;
QString state;
QVariant value; QVariant value;
QStringList row;
row << switchList[i].name; name = switchList[i].name;
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), switchList[i].param, value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), switchList[i].param, value)) {
int chan = value.toInt(); int chan = value.toInt();
...@@ -136,21 +138,23 @@ QList<QStringList> FlightModesComponent::summaryItems(void) const ...@@ -136,21 +138,23 @@ QList<QStringList> FlightModesComponent::summaryItems(void) const
if (i == 0) { if (i == 0) {
// Mode switch is required // Mode switch is required
Q_ASSERT(strcmp(switchList[0].param, "RC_MAP_MODE_SW") == 0); Q_ASSERT(strcmp(switchList[0].param, "RC_MAP_MODE_SW") == 0);
row << "Setup required"; state = "Setup required";
} else { } else {
row << "None"; state = "None";
} }
} else { } else {
row << tr("Chan %1").arg(chan); state = tr("Chan %1").arg(chan);
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
row << "Unknown"; state = "Unknown";
} }
items << row; VehicleComponentSummaryItem* item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
}
} }
return items; return _summaryItems;
} }
...@@ -49,10 +49,11 @@ public: ...@@ -49,10 +49,11 @@ public:
virtual QString setupStateDescription(void) const; virtual QString setupStateDescription(void) const;
virtual QWidget* setupWidget(void) const; virtual QWidget* setupWidget(void) const;
virtual QStringList paramFilterList(void) const; virtual QStringList paramFilterList(void) const;
virtual QList<QStringList> summaryItems(void) const; virtual const QVariantList& summaryItems(void);
private: private:
const QString _name; const QString _name;
QVariantList _summaryItems;
}; };
#endif #endif
...@@ -86,33 +86,6 @@ PX4AutoPilotPlugin::~PX4AutoPilotPlugin() ...@@ -86,33 +86,6 @@ PX4AutoPilotPlugin::~PX4AutoPilotPlugin()
PX4ParameterFacts::deleteParameterFactMetaData(); PX4ParameterFacts::deleteParameterFactMetaData();
} }
QList<VehicleComponent*> PX4AutoPilotPlugin::getVehicleComponents(void) const
{
Q_ASSERT(_uas);
QList<VehicleComponent*> components;
VehicleComponent* component;
component = new AirframeComponent(_uas);
Q_CHECK_PTR(component);
components.append(component);
component = new RadioComponent(_uas);
Q_CHECK_PTR(component);
components.append(component);
component = new FlightModesComponent(_uas);
Q_CHECK_PTR(component);
components.append(component);
component = new SensorsComponent(_uas);
Q_CHECK_PTR(component);
components.append(component);
return components;
}
QList<AutoPilotPluginManager::FullMode_t> PX4AutoPilotPlugin::getModes(void) QList<AutoPilotPluginManager::FullMode_t> PX4AutoPilotPlugin::getModes(void)
{ {
union px4_custom_mode px4_cm; union px4_custom_mode px4_cm;
...@@ -206,21 +179,49 @@ QString PX4AutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMo ...@@ -206,21 +179,49 @@ QString PX4AutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t customMo
return mode; return mode;
} }
void PX4AutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const void PX4AutoPilotPlugin::clearStaticData(void)
{ {
Q_ASSERT(context); PX4ParameterFacts::clearStaticData();
}
Q_ASSERT(_parameterFacts->factsAreReady()); bool PX4AutoPilotPlugin::pluginIsReady(void) const
{
return _parameterFacts->factsAreReady();
}
const QVariantList& PX4AutoPilotPlugin::components(void)
{
if (_components.count() == 0) {
VehicleComponent* component;
Q_ASSERT(_uas);
component = new AirframeComponent(_uas);
Q_CHECK_PTR(component);
_components.append(QVariant::fromValue(component));
component = new RadioComponent(_uas);
Q_CHECK_PTR(component);
_components.append(QVariant::fromValue(component));
component = new FlightModesComponent(_uas);
Q_CHECK_PTR(component);
_components.append(QVariant::fromValue(component));
component = new SensorsComponent(_uas);
Q_CHECK_PTR(component);
_components.append(QVariant::fromValue(component));
}
context->setContextProperty("parameters", _parameterFacts->factMap()); return _components;
} }
void PX4AutoPilotPlugin::clearStaticData(void) const QVariantMap& PX4AutoPilotPlugin::parameters(void)
{ {
PX4ParameterFacts::clearStaticData(); return _parameterFacts->factMap();
} }
bool PX4AutoPilotPlugin::pluginIsReady(void) const QUrl PX4AutoPilotPlugin::setupBackgroundImage(void)
{ {
return _parameterFacts->factsAreReady(); return QUrl::fromUserInput("qrc:/qml/px4fmu_2.x.png");
} }
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "UASInterface.h" #include "UASInterface.h"
#include "PX4ParameterFacts.h" #include "PX4ParameterFacts.h"
#include <QImage>
/// @file /// @file
/// @brief This is the PX4 specific implementation of the AutoPilot class. /// @brief This is the PX4 specific implementation of the AutoPilot class.
/// @author Don Gagne <don@thegagnes.com> /// @author Don Gagne <don@thegagnes.com>
...@@ -42,10 +44,10 @@ public: ...@@ -42,10 +44,10 @@ public:
~PX4AutoPilotPlugin(); ~PX4AutoPilotPlugin();
// Overrides from AutoPilotPlugin // Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) const ;
virtual void addFactsToQmlContext(QQmlContext* context) const;
virtual const QVariantMap& parameterFacts(void) const { return _parameterFacts->factMap(); }
virtual bool pluginIsReady(void) const; virtual bool pluginIsReady(void) const;
virtual const QVariantList& components(void);
virtual const QVariantMap& parameters(void);
virtual QUrl setupBackgroundImage(void);
static QList<AutoPilotPluginManager::FullMode_t> getModes(void); static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
static QString getShortModeText(uint8_t baseMode, uint32_t customMode); static QString getShortModeText(uint8_t baseMode, uint32_t customMode);
...@@ -55,6 +57,7 @@ private: ...@@ -55,6 +57,7 @@ private:
UASInterface* _uas; UASInterface* _uas;
PX4ParameterFacts* _parameterFacts; PX4ParameterFacts* _parameterFacts;
bool _pluginReady; bool _pluginReady;
QVariantList _components;
}; };
#endif #endif
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "RadioComponent.h" #include "RadioComponent.h"
#include "PX4RCCalibration.h" #include "PX4RCCalibration.h"
#include "VehicleComponentSummaryItem.h"
/// @brief Parameters which signal a change in setupComplete state /// @brief Parameters which signal a change in setupComplete state
static const char* triggerParams[] = { "RC_MAP_MODE_SW", NULL }; static const char* triggerParams[] = { "RC_MAP_MODE_SW", NULL };
...@@ -100,15 +101,18 @@ QWidget* RadioComponent::setupWidget(void) const ...@@ -100,15 +101,18 @@ QWidget* RadioComponent::setupWidget(void) const
return new PX4RCCalibration; return new PX4RCCalibration;
} }
QList<QStringList> RadioComponent::summaryItems(void) const const QVariantList& RadioComponent::summaryItems(void)
{ {
QList<QStringList> items; if (!_summaryItems.count()) {
QString name;
QStringList row; QString state;
// FIXME: Need to pull receiver type from RSSI value // FIXME: Need to pull receiver type from RSSI value
row << "Receiver type:" << "n/a"; name = "Receiver type:";
items << row; state = "n/a";
VehicleComponentSummaryItem* item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
static const char* stickParams[] = { "RC_MAP_ROLL", "RC_MAP_PITCH", "RC_MAP_YAW", "RC_MAP_THROTTLE" }; static const char* stickParams[] = { "RC_MAP_ROLL", "RC_MAP_PITCH", "RC_MAP_YAW", "RC_MAP_THROTTLE" };
...@@ -139,9 +143,12 @@ QList<QStringList> RadioComponent::summaryItems(void) const ...@@ -139,9 +143,12 @@ QList<QStringList> RadioComponent::summaryItems(void) const
summary = "Not mapped"; summary = "Not mapped";
} }
row.clear(); name = "Ail, Ele, Rud, Throt:";
row << "Ail, Ele, Rud, Throt:" << summary; state = summary;
items << row;
item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
}
return items; return _summaryItems;
} }
...@@ -50,10 +50,11 @@ public: ...@@ -50,10 +50,11 @@ public:
virtual QString setupStateDescription(void) const; virtual QString setupStateDescription(void) const;
virtual QWidget* setupWidget(void) const; virtual QWidget* setupWidget(void) const;
virtual QStringList paramFilterList(void) const; virtual QStringList paramFilterList(void) const;
virtual QList<QStringList> summaryItems(void) const; virtual const QVariantList& summaryItems(void);
private: private:
const QString _name; const QString _name;
QVariantList _summaryItems;
}; };
#endif #endif
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "SensorsComponent.h" #include "SensorsComponent.h"
#include "QGCPX4SensorCalibration.h" #include "QGCPX4SensorCalibration.h"
#include "VehicleComponentSummaryItem.h"
// These two list must be kept in sync // These two list must be kept in sync
...@@ -116,30 +117,33 @@ QWidget* SensorsComponent::setupWidget(void) const ...@@ -116,30 +117,33 @@ QWidget* SensorsComponent::setupWidget(void) const
return new QGCPX4SensorCalibration; return new QGCPX4SensorCalibration;
} }
QList<QStringList> SensorsComponent::summaryItems(void) const const QVariantList& SensorsComponent::summaryItems(void)
{ {
QList<QStringList> items; if (!_summaryItems.count()) {
QString name;
QString state;
// Summary item for each Sensor // Summary item for each Sensor
int i = 0; int i = 0;
while (triggerParams[i] != NULL) { while (triggerParams[i] != NULL) {
QVariant value; QVariant value;
QStringList row;
row << tr("%1:").arg(triggerSensors[i]); name = tr("%1:").arg(triggerSensors[i]);
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParams[i], value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), triggerParams[i], value)) {
if (value.toFloat() == 0.0f) { if (value.toFloat() == 0.0f) {
row << "Setup required"; state = "Setup required";
} else { } else {
row << "Ready"; state = "Ready";
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
} }
items << row;
VehicleComponentSummaryItem* item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
i++; i++;
} }
...@@ -195,27 +199,26 @@ QList<QStringList> SensorsComponent::summaryItems(void) const ...@@ -195,27 +199,26 @@ QList<QStringList> SensorsComponent::summaryItems(void) const
for (size_t i=0; i<cOrientationSensors; i++) { for (size_t i=0; i<cOrientationSensors; i++) {
QVariant value; QVariant value;
QStringList row;
row.clear();
row << orientationSensors[i]; name = orientationSensors[i];
if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), orientationParams[i], value)) { if (_paramMgr->getParameterValue(_paramMgr->getDefaultComponentId(), orientationParams[i], value)) {
int index = value.toInt(); int index = value.toInt();
if (index < 0 || index >= (int)cOrientationValues) { if (index < 0 || index >= (int)cOrientationValues) {
row << "Setup required"; state = "Setup required";
} else { } else {
row << orientationValues[index]; state = orientationValues[index];
} }
} else { } else {
// Why is the parameter missing? // Why is the parameter missing?
Q_ASSERT(false); Q_ASSERT(false);
row << "Unknown"; state = "Unknown";
} }
items << row; VehicleComponentSummaryItem* item = new VehicleComponentSummaryItem(name, state, this);
_summaryItems.append(QVariant::fromValue(item));
}
} }
return items; return _summaryItems;
} }
...@@ -49,10 +49,11 @@ public: ...@@ -49,10 +49,11 @@ public:
virtual QString setupStateDescription(void) const; virtual QString setupStateDescription(void) const;
virtual QWidget* setupWidget(void) const; virtual QWidget* setupWidget(void) const;
virtual QStringList paramFilterList(void) const; virtual QStringList paramFilterList(void) const;
virtual QList<QStringList> summaryItems(void) const; virtual const QVariantList& summaryItems(void);
private: private:
const QString _name; const QString _name;
QVariantList _summaryItems;
}; };
#endif #endif
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "FactSystem.h" #include "FactSystem.h"
#include "UASManager.h" #include "UASManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "VehicleComponent.h"
#include <QtQml> #include <QtQml>
...@@ -39,6 +40,10 @@ FactSystem::FactSystem(QObject* parent) : ...@@ -39,6 +40,10 @@ FactSystem::FactSystem(QObject* parent) :
{ {
qmlRegisterType<Fact>(_factSystemQmlUri, 1, 0, "Fact"); qmlRegisterType<Fact>(_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterType<FactValidator>(_factSystemQmlUri, 1, 0, "FactValidator"); qmlRegisterType<FactValidator>(_factSystemQmlUri, 1, 0, "FactValidator");
// FIXME: Where should this go? Also creation string
qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponent", "Can only reference VehicleComponent");
qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponentSummaryItem", "Can only reference VehicleComponentSummaryItem");
} }
FactSystem::~FactSystem() FactSystem::~FactSystem()
......
...@@ -90,13 +90,7 @@ void FactSystemTest::_parameter_test(void) ...@@ -90,13 +90,7 @@ void FactSystemTest::_parameter_test(void)
{ {
// Get the parameter facts from the AutoPilot // Get the parameter facts from the AutoPilot
AutoPilotPluginManager* pluginMgr = AutoPilotPluginManager::instance(); const QVariantMap& parameterFacts = _plugin->parameters();
Q_ASSERT(pluginMgr);
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin);
const QVariantMap& parameterFacts = plugin->parameterFacts();
// Compare the value in the Parameter Manager with the value from the FactSystem // Compare the value in the Parameter Manager with the value from the FactSystem
...@@ -116,6 +110,8 @@ void FactSystemTest::_qml_test(void) ...@@ -116,6 +110,8 @@ void FactSystemTest::_qml_test(void)
{ {
QGCQuickWidget* widget = new QGCQuickWidget; QGCQuickWidget* widget = new QGCQuickWidget;
widget->setAutoPilot(_plugin);
widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml")); widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml"));
QQuickItem* rootObject = widget->rootObject(); QQuickItem* rootObject = widget->rootObject();
...@@ -134,13 +130,7 @@ void FactSystemTest::_paramMgrSignal_test(void) ...@@ -134,13 +130,7 @@ void FactSystemTest::_paramMgrSignal_test(void)
{ {
// Get the parameter Fact from the AutoPilot // Get the parameter Fact from the AutoPilot
AutoPilotPluginManager* pluginMgr = AutoPilotPluginManager::instance(); const QVariantMap& parameterFacts = _plugin->parameters();
Q_ASSERT(pluginMgr);
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin);
const QVariantMap& parameterFacts = plugin->parameterFacts();
Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>(); Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>();
QVERIFY(fact != NULL); QVERIFY(fact != NULL);
...@@ -170,6 +160,8 @@ void FactSystemTest::_qmlUpdate_test(void) ...@@ -170,6 +160,8 @@ void FactSystemTest::_qmlUpdate_test(void)
{ {
QGCQuickWidget* widget = new QGCQuickWidget; QGCQuickWidget* widget = new QGCQuickWidget;
widget->setAutoPilot(_plugin);
widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml")); widget->setSource(QUrl::fromUserInput("qrc:unittest/FactSystemTest.qml"));
// Change the value using param manager // Change the value using param manager
......
import QtQuick 2.2 import QtQuick 2.2
import QtQuick.Controls 1.2 import QtQuick.Controls 1.2
import QGroundControl.FactSystem 1.0 import QGroundControl.FactSystem 1.0
import QGroundControlFactControls 1.0
Item { Item {
TextInput { TextInput {
objectName: "testControl" objectName: "testControl"
text: parameters["RC_MAP_THROTTLE"].value text: autopilot.parameters["RC_MAP_THROTTLE"].value
font.family: "Helvetica" font.family: "Helvetica"
font.pointSize: 24 font.pointSize: 24
color: "red" color: "red"
focus: true focus: true
onAccepted: { parameters["RC_MAP_THROTTLE"].value = text; } onAccepted: { autopilot.parameters["RC_MAP_THROTTLE"].value = text; }
} }
} }
\ No newline at end of file
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
======================================================================*/ ======================================================================*/
#include "QGCQuickWidget.h" #include "QGCQuickWidget.h"
#include "UASManager.h"
#include "AutoPilotPluginManager.h" #include "AutoPilotPluginManager.h"
#include <QQmlContext> #include <QQmlContext>
...@@ -37,13 +36,10 @@ ...@@ -37,13 +36,10 @@
QGCQuickWidget::QGCQuickWidget(QWidget* parent) : QGCQuickWidget::QGCQuickWidget(QWidget* parent) :
QQuickWidget(parent) QQuickWidget(parent)
{ {
UASManagerInterface* uasMgr = UASManager::instance();
Q_ASSERT(uasMgr);
UASInterface* uas = uasMgr->getActiveUAS();
Q_ASSERT(uas);
rootContext()->engine()->addImportPath("qrc:/qml"); rootContext()->engine()->addImportPath("qrc:/qml");
}
AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(uas)->addFactsToQmlContext(rootContext()); void QGCQuickWidget::setAutoPilot(AutoPilotPlugin* autoPilot)
{
rootContext()->setContextProperty("autopilot", autoPilot);
} }
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <QQuickWidget> #include <QQuickWidget>
#include "UASInterface.h" #include "AutoPilotPlugin.h"
/// @file /// @file
/// @brief Subclass of QQuickWidget which injects Facts and the Pallete object into /// @brief Subclass of QQuickWidget which injects Facts and the Pallete object into
...@@ -39,7 +39,9 @@ class QGCQuickWidget : public QQuickWidget { ...@@ -39,7 +39,9 @@ class QGCQuickWidget : public QQuickWidget {
public: public:
QGCQuickWidget(QWidget* parent = NULL); QGCQuickWidget(QWidget* parent = NULL);
};
/// Sets the UAS into the widget which in turn will load facts into the context
void setAutoPilot(AutoPilotPlugin* autoPilot);
};
#endif #endif
...@@ -38,3 +38,20 @@ VehicleComponent::~VehicleComponent() ...@@ -38,3 +38,20 @@ VehicleComponent::~VehicleComponent()
{ {
} }
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));
}
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#define VEHICLECOMPONENT_H #define VEHICLECOMPONENT_H
#include <QObject> #include <QObject>
#include <QQmlContext>
#include <QQuickItem>
#include "UASInterface.h" #include "UASInterface.h"
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
class VehicleComponent : public QObject class VehicleComponent : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString description READ description CONSTANT) Q_PROPERTY(QString description READ description CONSTANT)
Q_PROPERTY(bool requiresSetup READ requiresSetup CONSTANT) Q_PROPERTY(bool requiresSetup READ requiresSetup CONSTANT)
...@@ -44,6 +47,7 @@ class VehicleComponent : public QObject ...@@ -44,6 +47,7 @@ class VehicleComponent : public QObject
Q_PROPERTY(QString setupStateDescription READ setupStateDescription STORED false) Q_PROPERTY(QString setupStateDescription READ setupStateDescription STORED false)
Q_PROPERTY(QString icon READ icon CONSTANT) Q_PROPERTY(QString icon READ icon CONSTANT)
Q_PROPERTY(QWidget* setupWidget READ setupWidget STORED false) Q_PROPERTY(QWidget* setupWidget READ setupWidget STORED false)
Q_PROPERTY(QVariantList summaryItems READ summaryItems CONSTANT);
public: public:
VehicleComponent(UASInterface* uas, QObject* parent = NULL); VehicleComponent(UASInterface* uas, QObject* parent = NULL);
...@@ -57,7 +61,9 @@ public: ...@@ -57,7 +61,9 @@ public:
virtual QString setupStateDescription(void) const = 0; virtual QString setupStateDescription(void) const = 0;
virtual QWidget* setupWidget(void) const = 0; virtual QWidget* setupWidget(void) const = 0;
virtual QStringList paramFilterList(void) const = 0; virtual QStringList paramFilterList(void) const = 0;
virtual QList<QStringList> summaryItems(void) const = 0; virtual const QVariantList& summaryItems(void) = 0;
virtual void addSummaryQmlComponent(QQmlContext* context, QQuickItem* parent);
signals: signals:
void setupCompleteChanged(void); void setupCompleteChanged(void);
......
import QtQuick 2.2
import QtQuick.Controls 1.2
import QGroundControlFactControls 1.0
SetupButton {
width: 300
height: 200
title: vehicleComponent.name
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
/// @file
/// @author Don Gagne <don@thegagnes.com>
#include "VehicleComponentSummaryItem.h"
VehicleComponentSummaryItem::VehicleComponentSummaryItem(const QString& name, const QString& state, QObject* parent) :
QObject(parent),
_name(name),
_state(state)
{
}
/*=====================================================================
QGroundControl Open Source Ground Control Station
(c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
This file is part of the QGROUNDCONTROL project
QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
======================================================================*/
#ifndef VehicleComponentSummaryItem_H
#define VehicleComponentSummaryItem_H
#include <QObject>
#include <QQmlContext>
#include <QQuickItem>
#include "UASInterface.h"
/// @file
/// @brief Vehicle Component class. A vehicle component is an object which
/// abstracts the physical portion of a vehicle into a set of
/// configurable values and user interface.
/// @author Don Gagne <don@thegagnes.com>
class VehicleComponentSummaryItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name CONSTANT)
Q_PROPERTY(QString state READ state CONSTANT)
public:
VehicleComponentSummaryItem(const QString& name, const QString& state, QObject* parent = NULL);
QString name(void) const { return _name; }
QString state(void) const { return _state; }
protected:
QString _name;
QString _state;
};
#endif
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
//import QGroundControl.FactControls 1.0
Row {
width: 200
Text { id: firstCol; text: "Col 1" }
Text { horizontalAlignment: Text.AlignRight; width: parent.width - firstCol.contentWidth; text: "Col 2" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment