Commit f743d7d6 authored by Don Gagne's avatar Don Gagne

Merge pull request #1325 from DonLakeFlyer/QMLFact

Use FactBinder to access facts from Qml
parents 3ad5a209 e863bdae
...@@ -774,6 +774,7 @@ INCLUDEPATH += \ ...@@ -774,6 +774,7 @@ INCLUDEPATH += \
HEADERS += \ HEADERS += \
src/FactSystem/FactSystem.h \ src/FactSystem/FactSystem.h \
src/FactSystem/Fact.h \ src/FactSystem/Fact.h \
src/FactSystem/FactBinder.h \
src/FactSystem/FactMetaData.h \ src/FactSystem/FactMetaData.h \
src/FactSystem/FactValidator.h \ src/FactSystem/FactValidator.h \
src/FactSystem/FactLoader.h \ src/FactSystem/FactLoader.h \
...@@ -781,6 +782,7 @@ HEADERS += \ ...@@ -781,6 +782,7 @@ HEADERS += \
SOURCES += \ SOURCES += \
src/FactSystem/FactSystem.cc \ src/FactSystem/FactSystem.cc \
src/FactSystem/Fact.cc \ src/FactSystem/Fact.cc \
src/FactSystem/FactBinder.cc \
src/FactSystem/FactMetaData.cc \ src/FactSystem/FactMetaData.cc \
src/FactSystem/FactValidator.cc \ src/FactSystem/FactValidator.cc \
src/FactSystem/FactLoader.cc \ src/FactSystem/FactLoader.cc \
...@@ -62,3 +62,13 @@ void AutoPilotPlugin::refreshParametersPrefix(const QString& paramPrefix) ...@@ -62,3 +62,13 @@ void AutoPilotPlugin::refreshParametersPrefix(const QString& paramPrefix)
} }
} }
} }
bool AutoPilotPlugin::factExists(const QString& param)
{
return parameters().contains(param);
}
Fact* AutoPilotPlugin::getFact(const QString& name)
{
return parameters()[name].value<Fact*>();
}
...@@ -50,7 +50,6 @@ class AutoPilotPlugin : public QObject ...@@ -50,7 +50,6 @@ class AutoPilotPlugin : public QObject
public: public:
AutoPilotPlugin(UASInterface* uas, QObject* parent); AutoPilotPlugin(UASInterface* uas, QObject* parent);
Q_PROPERTY(QVariantMap parameters READ parameters CONSTANT)
Q_PROPERTY(QVariantList components READ components CONSTANT) Q_PROPERTY(QVariantList components READ components CONSTANT)
Q_PROPERTY(QUrl setupBackgroundImage READ setupBackgroundImage CONSTANT) Q_PROPERTY(QUrl setupBackgroundImage READ setupBackgroundImage CONSTANT)
...@@ -62,6 +61,10 @@ public: ...@@ -62,6 +61,10 @@ public:
// Request a refresh on all parameters that begin with the specified prefix // Request a refresh on all parameters that begin with the specified prefix
Q_INVOKABLE void refreshParametersPrefix(const QString& paramPrefix); Q_INVOKABLE void refreshParametersPrefix(const QString& paramPrefix);
Q_INVOKABLE bool factExists(const QString& param);
Fact* getFact(const QString& name);
// Property accessors // Property accessors
virtual const QVariantList& components(void) = 0; virtual const QVariantList& components(void) = 0;
......
...@@ -3,6 +3,7 @@ import QtQuick.Controls 1.2 ...@@ -3,6 +3,7 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import QGroundControl.FactSystem 1.0 import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
Column { Column {
...@@ -13,10 +14,10 @@ Column { ...@@ -13,10 +14,10 @@ Column {
width: parent.width width: parent.width
QGCLabel { id: systemId; text: "System ID:" } QGCLabel { id: systemId; text: "System ID:" }
QGCLabel { FactLabel {
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
width: parent.width - systemId.contentWidth width: parent.width - systemId.contentWidth
text: autopilot.parameters["MAV_SYS_ID"].value fact: Fact { name: "MAV_SYS_ID" }
} }
} }
...@@ -25,9 +26,10 @@ Column { ...@@ -25,9 +26,10 @@ Column {
QGCLabel { id: airframe; text: "Airframe:" } QGCLabel { id: airframe; text: "Airframe:" }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "SYS_AUTOSTART" }
horizontalAlignment: Text.AlignRight horizontalAlignment: Text.AlignRight
width: parent.width - airframe.contentWidth width: parent.width - airframe.contentWidth
text: autopilot.parameters["SYS_AUTOSTART"].value == 0 ? "Setup required" : autopilot.parameters["SYS_AUTOSTART"].value text: fact.value == 0 ? "Setup required" : fact.value
} }
} }
} }
...@@ -9,47 +9,51 @@ Column { ...@@ -9,47 +9,51 @@ Column {
anchors.fill: parent anchors.fill: parent
anchors.margins: 8 anchors.margins: 8
Row { Component {
width: parent.width id: component
QGCLabel { id: mode; text: "Mode switch:" } Row {
QGCLabel { width: parent.width
horizontalAlignment: Text.AlignRight
width: parent.width - mode.contentWidth QGCLabel { id: label; text: labelText }
text: autopilot.parameters["RC_MAP_MODE_SW"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_MODE_SW"].value QGCLabel {
property Fact fact: Fact { name: factName }
horizontalAlignment: Text.AlignRight
width: parent.width - label.contentWidth
text: fact.value == 0 ? zeroText : fact.value
}
} }
} }
Row { Loader {
property string labelText: "Mode switch:"
property string zeroText: "Setup required"
property string factName: "RC_MAP_MODE_SW"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: posctl; text: "Position Ctl switch:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - posctl.contentWidth
text: autopilot.parameters["RC_MAP_POSCTL_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_POSCTL_SW"].value
}
} }
Row { Loader {
property string labelText: "Position Ctl switch:"
property string zeroText: "Disabled"
property string factName: "RC_MAP_POSCTL_SW"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: loiter; text: "Loiter switch:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - loiter.contentWidth
text: autopilot.parameters["RC_MAP_LOITER_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_LOITER_SW"].value
}
} }
Row { Loader {
property string labelText: "Position Ctl switch:"
property string zeroText: "Disabled"
property string factName: "RC_MAP_LOITER_SW"
width: parent.width width: parent.width
sourceComponent: component
}
QGCLabel { id: rtl; text: "Return switch:" } Loader {
QGCLabel { property string labelText: "Return switch:"
horizontalAlignment: Text.AlignRight property string zeroText: "Disabled"
width: parent.width - rtl.contentWidth property string factName: "RC_MAP_RETURN_SW"
text: autopilot.parameters["RC_MAP_RETURN_SW"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_RETURN_SW"].value width: parent.width
} sourceComponent: component
} }
} }
...@@ -9,80 +9,75 @@ Column { ...@@ -9,80 +9,75 @@ Column {
anchors.fill: parent anchors.fill: parent
anchors.margins: 8 anchors.margins: 8
Row { Component {
width: parent.width id: component
QGCLabel { id: roll; text: "Roll:" } Row {
QGCLabel { width: parent.width
horizontalAlignment: Text.AlignRight
width: parent.width - roll.contentWidth QGCLabel { id: label; text: labelText }
text: autopilot.parameters["RC_MAP_ROLL"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_ROLL"].value QGCLabel {
Fact { id: fact; name: factName }
horizontalAlignment: Text.AlignRight
width: parent.width - label.contentWidth
text: fact.value == 0 ? zeroText : fact.value
}
} }
} }
Row { Loader {
property string labelText: "Roll:"
property string zeroText: "Setup required"
property string factName: "RC_MAP_ROLL"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: pitch; text: "Pitch:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - pitch.contentWidth
text: autopilot.parameters["RC_MAP_PITCH"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_PITCH"].value
}
} }
Row { Loader {
property string labelText: "Pitch:"
property string zeroText: "Setup required"
property string factName: "RC_MAP_PITCH"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: yaw; text: "Yaw:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - yaw.contentWidth
text: autopilot.parameters["RC_MAP_YAW"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_YAW"].value
}
} }
Row { Loader {
property string labelText: "Yaw:"
property string zeroText: "Setup required"
property string factName: "RC_MAP_YAW"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: throttle; text: "Throttle:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - throttle.contentWidth
text: autopilot.parameters["RC_MAP_THROTTLE"].value == 0 ? "Setup required" : autopilot.parameters["RC_MAP_THROTTLE"].value
}
} }
Row { Loader {
property string labelText: "Throttle:"
property string zeroText: "Setup required"
property string factName: "RC_MAP_THROTTLE"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: flaps; text: "Flaps:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - flaps.contentWidth
text: autopilot.parameters["RC_MAP_FLAPS"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_FLAPS"].value
}
} }
Row { Loader {
property string labelText: "Flaps:"
property string zeroText: "Disabled"
property string factName: "RC_MAP_FLAPS"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: aux1; text: "Aux1:" }
QGCLabel {
horizontalAlignment: Text.AlignRight
width: parent.width - aux1.contentWidth
text: autopilot.parameters["RC_MAP_AUX1"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_AUX1"].value
}
} }
Row { Loader {
property string labelText: "Aux1:"
property string zeroText: "Disabled"
property string factName: "RC_MAP_AUX1"
width: parent.width width: parent.width
sourceComponent: component
}
QGCLabel { id: aux2; text: "Aux2:" } Loader {
QGCLabel { property string labelText: "Aux2:"
horizontalAlignment: Text.AlignRight property string zeroText: "Disabled"
width: parent.width - aux2.contentWidth property string factName: "RC_MAP_AUX2"
text: autopilot.parameters["RC_MAP_AUX2"].value == 0 ? "Disabled" : autopilot.parameters["RC_MAP_AUX2"].value width: parent.width
} sourceComponent: component
} }
} }
...@@ -61,7 +61,7 @@ Rectangle { ...@@ -61,7 +61,7 @@ Rectangle {
QGCLabel { text: "Return Home after"; anchors.baseline: rcLossField.baseline } QGCLabel { text: "Return Home after"; anchors.baseline: rcLossField.baseline }
FactTextField { FactTextField {
id: rcLossField id: rcLossField
fact: autopilot.parameters["COM_RC_LOSS_T"] fact: Fact { name: "COM_RC_LOSS_T" }
showUnits: true showUnits: true
} }
} }
...@@ -70,7 +70,7 @@ Rectangle { ...@@ -70,7 +70,7 @@ Rectangle {
spacing: 10 spacing: 10
FactCheckBox { FactCheckBox {
id: telemetryTimeoutCheckbox id: telemetryTimeoutCheckbox
fact: autopilot.parameters["COM_DL_LOSS_EN"] fact: Fact { name: "COM_DL_LOSS_EN" }
checkedValue: 1 checkedValue: 1
uncheckedValue: 0 uncheckedValue: 0
text: "Telemetry Signal Timeout" text: "Telemetry Signal Timeout"
...@@ -80,7 +80,7 @@ Rectangle { ...@@ -80,7 +80,7 @@ Rectangle {
QGCLabel { text: "Return Home after"; anchors.baseline: telemetryLossField.baseline } QGCLabel { text: "Return Home after"; anchors.baseline: telemetryLossField.baseline }
FactTextField { FactTextField {
id: telemetryLossField id: telemetryLossField
fact: autopilot.parameters["COM_DL_LOSS_T"]; fact: Fact { name: "COM_DL_LOSS_T" }
showUnits: true showUnits: true
enabled: telemetryTimeoutCheckbox.checked enabled: telemetryTimeoutCheckbox.checked
} }
...@@ -125,7 +125,7 @@ Rectangle { ...@@ -125,7 +125,7 @@ Rectangle {
QGCLabel { text: "Climb to altitude of" } QGCLabel { text: "Climb to altitude of" }
FactTextField { FactTextField {
id: climbField id: climbField
fact: autopilot.parameters["RTL_RETURN_ALT"] fact: Fact { name: "RTL_RETURN_ALT" }
showUnits: true showUnits: true
} }
} }
...@@ -137,7 +137,8 @@ Rectangle { ...@@ -137,7 +137,8 @@ Rectangle {
QGCCheckBox { QGCCheckBox {
id: homeLoiterCheckbox id: homeLoiterCheckbox
property Fact fact: autopilot.parameters["RTL_LAND_DELAY"] property Fact fact: Fact { name: "RTL_LAND_DELAY" }
checked: fact.value > 0 checked: fact.value > 0
text: "Loiter at Home altitude for" text: "Loiter at Home altitude for"
onClicked: { onClicked: {
...@@ -145,7 +146,7 @@ Rectangle { ...@@ -145,7 +146,7 @@ Rectangle {
} }
} }
FactTextField { FactTextField {
fact: autopilot.parameters["RTL_LAND_DELAY"]; fact: Fact { name: "RTL_LAND_DELAY" }
showUnits: true showUnits: true
enabled: homeLoiterCheckbox.checked == true enabled: homeLoiterCheckbox.checked == true
} }
...@@ -251,7 +252,7 @@ Rectangle { ...@@ -251,7 +252,7 @@ Rectangle {
} }
FactTextField { FactTextField {
id: descendField; id: descendField;
fact: autopilot.parameters["RTL_DESCEND_ALT"]; fact: Fact { name: "RTL_DESCEND_ALT" }
enabled: homeLoiterCheckbox.checked == true enabled: homeLoiterCheckbox.checked == true
showUnits: true showUnits: true
} }
...@@ -263,17 +264,19 @@ Rectangle { ...@@ -263,17 +264,19 @@ Rectangle {
} }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "NAV_RCL_OBC" }
width: parent.width width: parent.width
font.pointSize: 14 font.pointSize: 14
text: "Warning: You have an advanced safety configuration set using the NAV_RCL_OBC parameter. The above settings may not apply."; text: "Warning: You have an advanced safety configuration set using the NAV_RCL_OBC parameter. The above settings may not apply.";
visible: autopilot.parameters["NAV_RCL_OBC"].value != 0 visible: fact.value != 0
wrapMode: Text.Wrap wrapMode: Text.Wrap
} }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "NAV_DLL_OBC" }
width: parent.width width: parent.width
font.pointSize: 14 font.pointSize: 14
text: "Warning: You have an advanced safety configuration set using the NAV_DLL_OBC parameter. The above settings may not apply."; text: "Warning: You have an advanced safety configuration set using the NAV_DLL_OBC parameter. The above settings may not apply.";
visible: autopilot.parameters["NAV_DLL_OBC"].value != 0 visible: fact.value != 0
wrapMode: Text.Wrap wrapMode: Text.Wrap
} }
} }
......
...@@ -3,6 +3,7 @@ import QtQuick.Controls 1.2 ...@@ -3,6 +3,7 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2 import QtQuick.Controls.Styles 1.2
import QGroundControl.FactSystem 1.0 import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
Column { Column {
...@@ -13,10 +14,10 @@ Column { ...@@ -13,10 +14,10 @@ Column {
width: parent.width width: parent.width
QGCLabel { id: rtlMinAlt; text: "RTL min alt:" } QGCLabel { id: rtlMinAlt; text: "RTL min alt:" }
QGCLabel { FactLabel {
fact: Fact { name: "RTL_RETURN_ALT" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - rtlMinAlt.contentWidth; width: parent.width - rtlMinAlt.contentWidth;
text: autopilot.parameters["RTL_RETURN_ALT"].valueString
} }
} }
...@@ -24,10 +25,10 @@ Column { ...@@ -24,10 +25,10 @@ Column {
width: parent.width width: parent.width
QGCLabel { id: rtlHomeAlt; text: "RTL home alt:" } QGCLabel { id: rtlHomeAlt; text: "RTL home alt:" }
QGCLabel { FactLabel {
fact: Fact { name: "RTL_DESCEND_ALT" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - rtlHomeAlt.contentWidth; width: parent.width - rtlHomeAlt.contentWidth;
text: autopilot.parameters["RTL_DESCEND_ALT"].valueString
} }
} }
...@@ -36,9 +37,10 @@ Column { ...@@ -36,9 +37,10 @@ Column {
QGCLabel { id: rtlLoiter; text: "RTL loiter delay:" } QGCLabel { id: rtlLoiter; text: "RTL loiter delay:" }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "RTL_LAND_DELAY" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - rtlLoiter.contentWidth; width: parent.width - rtlLoiter.contentWidth;
text: autopilot.parameters["RTL_LAND_DELAY"].value < 0 ? "Disabled" : autopilot.parameters["RTL_LAND_DELAY"].valueString text: fact.value < 0 ? "Disabled" : fact.valueString
} }
} }
...@@ -47,9 +49,10 @@ Column { ...@@ -47,9 +49,10 @@ Column {
QGCLabel { id: commLoss; text: "Telemetry loss RTL:" } QGCLabel { id: commLoss; text: "Telemetry loss RTL:" }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "COM_DL_LOSS_EN" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - commLoss.contentWidth; width: parent.width - commLoss.contentWidth;
text: autopilot.parameters["COM_DL_LOSS_EN"].value != 1 ? "Disabled" : autopilot.parameters["COM_DL_LOSS_T"].valueString text: fact.value != 1 ? "Disabled" : fact.valueString
} }
} }
...@@ -57,10 +60,10 @@ Column { ...@@ -57,10 +60,10 @@ Column {
width: parent.width width: parent.width
QGCLabel { id: rcLoss; text: "RC loss RTL (seconds):" } QGCLabel { id: rcLoss; text: "RC loss RTL (seconds):" }
QGCLabel { FactLabel {
fact: Fact { name: "COM_RC_LOSS_T" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - rcLoss.contentWidth; width: parent.width - rcLoss.contentWidth;
text: autopilot.parameters["COM_RC_LOSS_T"].valueString
} }
} }
} }
...@@ -75,33 +75,41 @@ Rectangle { ...@@ -75,33 +75,41 @@ Rectangle {
QGCLabel { text: "Calibrate:"; anchors.baseline: firstButton.baseline } QGCLabel { text: "Calibrate:"; anchors.baseline: firstButton.baseline }
IndicatorButton { IndicatorButton {
property Fact fact: Fact { name: "CAL_MAG0_ID" }
id: firstButton id: firstButton
width: parent.buttonWidth width: parent.buttonWidth
text: "Compass" text: "Compass"
indicatorGreen: autopilot.parameters["CAL_MAG0_ID"].value != 0 indicatorGreen: fact.value != 0
onClicked: controller.calibrateCompass() onClicked: controller.calibrateCompass()
} }
IndicatorButton { IndicatorButton {
property Fact fact: Fact { name: "CAL_GYRO0_ID" }
width: parent.buttonWidth width: parent.buttonWidth
text: "Gyroscope" text: "Gyroscope"
indicatorGreen: autopilot.parameters["CAL_GYRO0_ID"].value != 0 indicatorGreen: fact.value != 0
onClicked: controller.calibrateGyro() onClicked: controller.calibrateGyro()
} }
IndicatorButton { IndicatorButton {
property Fact fact: Fact { name: "CAL_ACC0_ID" }
width: parent.buttonWidth width: parent.buttonWidth
text: "Accelerometer" text: "Accelerometer"
indicatorGreen: autopilot.parameters["CAL_ACC0_ID"].value != 0 indicatorGreen: fact.value != 0
onClicked: controller.calibrateAccel() onClicked: controller.calibrateAccel()
} }
IndicatorButton { IndicatorButton {
property Fact fact: Fact { name: "SENS_DPRES_OFF" }
width: parent.buttonWidth width: parent.buttonWidth
text: "Airspeed" text: "Airspeed"
visible: controller.fixedWing visible: controller.fixedWing
indicatorGreen: autopilot.parameters["SENS_DPRES_OFF"].value != 0 indicatorGreen: fact.value != 0
onClicked: controller.calibrateAirspeed() onClicked: controller.calibrateAirspeed()
} }
} }
...@@ -232,11 +240,15 @@ Rectangle { ...@@ -232,11 +240,15 @@ Rectangle {
} }
Column { Column {
property Fact cal_mag0_rot: Fact { name: "CAL_MAG0_ROT" }
property Fact cal_mag1_rot: Fact { name: "CAL_MAG1_ROT" }
property Fact cal_mag2_rot: Fact { name: "CAL_MAG2_ROT" }
// Compass rotation parameter < 0 indicates either internal compass, or no compass. So in // Compass rotation parameter < 0 indicates either internal compass, or no compass. So in
// both those cases we do not show a rotation combo. // both those cases we do not show a rotation combo.
property bool showCompass0: autopilot.parameters["CAL_MAG0_ROT"].value >= 0 property bool showCompass0: cal_mag0_rot.value >= 0
property bool showCompass1: autopilot.parameters["CAL_MAG1_ROT"].value >= 0 property bool showCompass1: cal_mag1_rot.value >= 0
property bool showCompass2: autopilot.parameters["CAL_MAG2_ROT"].value >= 0 property bool showCompass2: cal_mag2_rot.value >= 0
x: parent.width - rotationColumnWidth x: parent.width - rotationColumnWidth
...@@ -245,7 +257,7 @@ Rectangle { ...@@ -245,7 +257,7 @@ Rectangle {
FactComboBox { FactComboBox {
width: rotationColumnWidth; width: rotationColumnWidth;
model: rotations model: rotations
fact: autopilot.parameters["SENS_BOARD_ROT"] fact: Fact { name: "SENS_BOARD_ROT" }
} }
// Compass 0 rotation // Compass 0 rotation
...@@ -260,7 +272,7 @@ Rectangle { ...@@ -260,7 +272,7 @@ Rectangle {
FactComboBox { FactComboBox {
width: rotationColumnWidth width: rotationColumnWidth
model: rotations model: rotations
fact: autopilot.parameters["CAL_MAG0_ROT"] fact: Fact { name: "CAL_MAG0_ROT" }
} }
} }
Loader { sourceComponent: parent.showCompass0 ? compass0ComponentLabel : null } Loader { sourceComponent: parent.showCompass0 ? compass0ComponentLabel : null }
...@@ -278,7 +290,7 @@ Rectangle { ...@@ -278,7 +290,7 @@ Rectangle {
FactComboBox { FactComboBox {
width: rotationColumnWidth width: rotationColumnWidth
model: rotations model: rotations
fact: autopilot.parameters["CAL_MAG1_ROT"] fact: Fact { name: "CAL_MAG1_ROT" }
} }
} }
Loader { sourceComponent: parent.showCompass1 ? compass1ComponentLabel : null } Loader { sourceComponent: parent.showCompass1 ? compass1ComponentLabel : null }
...@@ -296,7 +308,7 @@ Rectangle { ...@@ -296,7 +308,7 @@ Rectangle {
FactComboBox { FactComboBox {
width: rotationColumnWidth width: rotationColumnWidth
model: rotations model: rotations
fact: autopilot.parameters["CAL_MAG2_ROT"] fact: Fact { name: "CAL_MAG2_ROT" }
} }
} }
Loader { sourceComponent: parent.showCompass2 ? compass2ComponentLabel : null } Loader { sourceComponent: parent.showCompass2 ? compass2ComponentLabel : null }
......
...@@ -13,36 +13,40 @@ Column { ...@@ -13,36 +13,40 @@ Column {
anchors.fill: parent anchors.fill: parent
anchors.margins: 8 anchors.margins: 8
Row { Component {
width: parent.width id: component
QGCLabel { id: compass; text: "Compass:" } Row {
QGCLabel { width: parent.width
horizontalAlignment: Text.AlignRight;
width: parent.width - compass.contentWidth; QGCLabel { id: label; text: labelText }
text: autopilot.parameters["CAL_MAG0_ID"].value == 0 ? "Setup required" : "Ready" QGCLabel {
property Fact fact: Fact { name: factName }
horizontalAlignment: Text.AlignRight;
width: parent.width - label.contentWidth;
text: fact.value == 0 ? "Setup required" : "Ready"
}
} }
} }
Row { Loader {
property string labelText: "Compass:"
property string factName: "CAL_MAG0_ID"
width: parent.width width: parent.width
sourceComponent: component
QGCLabel { id: gyro; text: "Gyro:" }
QGCLabel {
horizontalAlignment: Text.AlignRight;
width: parent.width - gyro.contentWidth;
text: autopilot.parameters["CAL_GYRO0_ID"].value == 0 ? "Setup required" : "Ready"
}
} }
Row { Loader {
property string labelText: "Gyro:"
property string factName: "CAL_GYRO0_ID"
width: parent.width width: parent.width
sourceComponent: component
}
QGCLabel { id: accel; text: "Accelerometer:" } Loader {
QGCLabel { property string labelText: "Accelerometer:"
horizontalAlignment: Text.AlignRight; property string factName: "CAL_ACC0_ID"
width: parent.width - accel.contentWidth; width: parent.width
text: autopilot.parameters["CAL_ACC0_ID"].value == 0 ? "Setup required" : "Ready" sourceComponent: component
}
} }
} }
...@@ -18,9 +18,10 @@ Column { ...@@ -18,9 +18,10 @@ Column {
QGCLabel { id: compass; text: "Compass:" } QGCLabel { id: compass; text: "Compass:" }
QGCLabel { QGCLabel {
horizontalAlignment: Text.AlignRight; property Fact fact: Fact { name: "CAL_MAG0_ID" }
width: parent.width - compass.contentWidth; horizontalAlignment: Text.AlignRight;
text: autopilot.parameters["CAL_MAG0_ID"].value == 0 ? "Setup required" : "Ready" width: parent.width - compass.contentWidth;
text: fact.value == 0 ? "Setup required" : "Ready"
} }
} }
...@@ -29,9 +30,10 @@ Column { ...@@ -29,9 +30,10 @@ Column {
QGCLabel { id: gyro; text: "Gyro:" } QGCLabel { id: gyro; text: "Gyro:" }
QGCLabel { QGCLabel {
horizontalAlignment: Text.AlignRight; property Fact fact: Fact { name: "CAL_GYRO0_ID" }
width: parent.width - gyro.contentWidth; horizontalAlignment: Text.AlignRight;
text: autopilot.parameters["CAL_GYRO0_ID"].value == 0 ? "Setup required" : "Ready" width: parent.width - compass.contentWidth;
text: fact.value == 0 ? "Setup required" : "Ready"
} }
} }
...@@ -40,9 +42,10 @@ Column { ...@@ -40,9 +42,10 @@ Column {
QGCLabel { id: accel; text: "Accelerometer:" } QGCLabel { id: accel; text: "Accelerometer:" }
QGCLabel { QGCLabel {
horizontalAlignment: Text.AlignRight; property Fact fact: Fact { name: "CAL_ACC0_ID" }
width: parent.width - accel.contentWidth; horizontalAlignment: Text.AlignRight;
text: autopilot.parameters["CAL_ACC0_ID"].value == 0 ? "Setup required" : "Ready" width: parent.width - compass.contentWidth;
text: fact.value == 0 ? "Setup required" : "Ready"
} }
} }
...@@ -51,9 +54,10 @@ Column { ...@@ -51,9 +54,10 @@ Column {
QGCLabel { id: airspeed; text: "Airspeed:" } QGCLabel { id: airspeed; text: "Airspeed:" }
QGCLabel { QGCLabel {
property Fact fact: Fact { name: "SENS_DPRES_OFF" }
horizontalAlignment: Text.AlignRight; horizontalAlignment: Text.AlignRight;
width: parent.width - airspeed.contentWidth; width: parent.width - airspeed.contentWidth;
text: autopilot.parameters["SENS_DPRES_OFF"].value == 0.0 ? "Setup required" : "Ready" text: fact.value == 0.0 ? "Setup required" : "Ready"
} }
} }
} }
/*=====================================================================
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 "FactBinder.h"
#include "UASManager.h"
#include "AutoPilotPluginManager.h"
FactBinder::FactBinder(void) :
_autopilotPlugin(NULL),
_fact(NULL)
{
UASInterface* uas = UASManager::instance()->getActiveUAS();
Q_ASSERT(uas);
_autopilotPlugin = AutoPilotPluginManager::instance()->getInstanceForAutoPilotPlugin(uas);
Q_ASSERT(_autopilotPlugin);
Q_ASSERT(_autopilotPlugin->pluginIsReady());
}
QString FactBinder::name(void) const
{
if (_fact) {
return _fact->name();
} else {
return QString();
}
}
void FactBinder::setName(const QString& name)
{
if (_fact) {
disconnect(_fact, &Fact::valueChanged, this, &FactBinder::valueChanged);
_fact = NULL;
}
if (!name.isEmpty()) {
if (_autopilotPlugin->factExists(name)) {
_fact = _autopilotPlugin->getFact(name);
connect(_fact, &Fact::valueChanged, this, &FactBinder::valueChanged);
} else {
Q_ASSERT(false);
}
}
emit valueChanged();
emit nameChanged();
}
QVariant FactBinder::value(void) const
{
if (_fact) {
return _fact->value();
} else {
return QVariant(0);
}
}
void FactBinder::setValue(const QVariant& value)
{
if (_fact) {
_fact->setValue(value);
} else {
Q_ASSERT(false);
}
}
QString FactBinder::valueString(void) const
{
if (_fact) {
return _fact->valueString();
} else {
return QString();
}
}
QString FactBinder::units(void) const
{
if (_fact) {
return _fact->units();
} else {
return QString();
}
}
/*=====================================================================
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>
#ifndef FACTBINDER_H
#define FACTBINDER_H
#include "Fact.h"
#include "AutoPilotPlugin.h"
#include <QObject>
#include <QString>
/// This object is used to instantiate a connection to a Fact from within Qml.
class FactBinder : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true)
Q_PROPERTY(QVariant valueString READ valueString NOTIFY valueChanged)
Q_PROPERTY(QString units READ units CONSTANT)
public:
FactBinder(void);
QString name(void) const;
void setName(const QString& name);
QVariant value(void) const;
void setValue(const QVariant& value);
QString valueString(void) const;
/// Read accesor for units property
QString units(void) const;
signals:
void nameChanged(void);
void valueChanged(void);
private:
AutoPilotPlugin* _autopilotPlugin;
Fact* _fact;
};
#endif
\ No newline at end of file
...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0 ...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
QGCCheckBox { QGCCheckBox {
property Fact fact: Fact { value: 0 } property Fact fact: Fact { }
property variant checkedValue: 1 property variant checkedValue: 1
property variant uncheckedValue: 0 property variant uncheckedValue: 0
......
...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0 ...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
QGCComboBox { QGCComboBox {
property Fact fact: Fact { value: 0 } property Fact fact: Fact { }
currentIndex: fact.value currentIndex: fact.value
onActivated: fact.value = index onActivated: fact.value = index
} }
...@@ -7,6 +7,6 @@ import QGroundControl.Palette 1.0 ...@@ -7,6 +7,6 @@ import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
QGCLabel { QGCLabel {
property Fact fact: Fact { value: "FactLabel" } property Fact fact: Fact { }
text: fact.valueString text: fact.valueString
} }
...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0 ...@@ -7,7 +7,7 @@ import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
QGCTextField { QGCTextField {
property Fact fact: Fact { value: 0 } property Fact fact: Fact { }
text: fact.valueString text: fact.valueString
unitsLabel: fact.units unitsLabel: fact.units
onEditingFinished: fact.value = text onEditingFinished: fact.value = text
......
...@@ -38,14 +38,6 @@ ...@@ -38,14 +38,6 @@
Q_DECLARE_LOGGING_CATEGORY(FactLoaderLog) Q_DECLARE_LOGGING_CATEGORY(FactLoaderLog)
/// Connects to Parameter Manager to load/update Facts /// Connects to Parameter Manager to load/update Facts
///
/// These Facts are available for binding within QML code. For example:
/// @code{.unparsed}
/// TextInput {
/// text: autopilot.parameters["RC_MAP_THROTTLE"].value
/// }
/// @endcode
class FactLoader : public QObject class FactLoader : public QObject
{ {
Q_OBJECT Q_OBJECT
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "UASManager.h" #include "UASManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "VehicleComponent.h" #include "VehicleComponent.h"
#include "FactBinder.h"
#include <QtQml> #include <QtQml>
...@@ -38,8 +39,7 @@ const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem"; ...@@ -38,8 +39,7 @@ const char* FactSystem::_factSystemQmlUri = "QGroundControl.FactSystem";
FactSystem::FactSystem(QObject* parent) : FactSystem::FactSystem(QObject* parent) :
QGCSingleton(parent) QGCSingleton(parent)
{ {
qmlRegisterType<Fact>(_factSystemQmlUri, 1, 0, "Fact"); qmlRegisterType<FactBinder>(_factSystemQmlUri, 1, 0, "Fact");
qmlRegisterType<FactValidator>(_factSystemQmlUri, 1, 0, "FactValidator");
// FIXME: Where should these go? // FIXME: Where should these go?
qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponent", "Can only reference VehicleComponent"); qmlRegisterUncreatableType<VehicleComponent>(_factSystemQmlUri, 1, 0, "VehicleComponent", "Can only reference VehicleComponent");
......
...@@ -5,11 +5,12 @@ import QGroundControl.FactSystem 1.0 ...@@ -5,11 +5,12 @@ import QGroundControl.FactSystem 1.0
Item { Item {
TextInput { TextInput {
objectName: "testControl" objectName: "testControl"
text: autopilot.parameters["RC_MAP_THROTTLE"].value Fact { id: fact; name: "RC_MAP_THROTTLE" }
text: fact.value
font.family: "Helvetica" font.family: "Helvetica"
font.pointSize: 24 font.pointSize: 24
color: "red" color: "red"
focus: true focus: true
onAccepted: { autopilot.parameters["RC_MAP_THROTTLE"].value = text; } onAccepted: { fact.value = text; }
} }
} }
\ No newline at end of file
...@@ -4,7 +4,6 @@ import QtQuick.Controls.Styles 1.2 ...@@ -4,7 +4,6 @@ import QtQuick.Controls.Styles 1.2
import QGroundControl.Palette 1.0 import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0 import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
Rectangle { Rectangle {
...@@ -449,55 +448,6 @@ Rectangle { ...@@ -449,55 +448,6 @@ Rectangle {
enabled: false enabled: false
} }
// FactLabel
Loader {
sourceComponent: ctlRowHeader
property var text: "FactLabel"
}
FactLabel {
width: 100
height: 20
}
FactLabel {
width: 100
height: 20
enabled: false
}
// FactCheckBox
Loader {
sourceComponent: ctlRowHeader
property var text: "FactCheckBox"
}
FactCheckBox {
width: 100
height: 20
text: "Fact CheckBox"
}
FactCheckBox {
width: 100
height: 20
text: "Fact CheckBox"
enabled: false
}
// FactTextField
Loader {
sourceComponent: ctlRowHeader
property var text: "FactTextField"
}
FactTextField {
width: 100
height: 20
text: "FactTextField"
}
FactTextField {
width: 100
height: 20
text: "FactTextField"
enabled: false
}
// QGCComboBox // QGCComboBox
Loader { Loader {
sourceComponent: ctlRowHeader sourceComponent: ctlRowHeader
......
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