diff --git a/qgroundcontrol.qrc b/qgroundcontrol.qrc index 407433977b57a564f217e163546cd5ebf71dc53a..6b317dc3b9ec2923dc8796babc486d2fe0149cfc 100644 --- a/qgroundcontrol.qrc +++ b/qgroundcontrol.qrc @@ -237,12 +237,20 @@ src/test.qml + qml/QGroundControl/FactControls/qmldir + + qml/QGroundControl/FactControls/SetupButton.qml + qml/QGroundControl/FactControls/FactLabel.qml + qml/QGroundControl/FactControls/FactTextField.qml + files/images/px4/airframes/octo_x.png files/images/px4/boards/px4fmu_2.x.png + src/VehicleSetup/SetupViewConnected.qml src/VehicleSetup/SetupViewDisconnected.qml + src/AutoPilotPlugins/PX4/SafetyComponent.qml diff --git a/qml/QGroundControl/FactControls/FactLabel.qml b/qml/QGroundControl/FactControls/FactLabel.qml new file mode 100644 index 0000000000000000000000000000000000000000..a98f050b6fe322ed63c9b4ce95f50b9d8142d114 --- /dev/null +++ b/qml/QGroundControl/FactControls/FactLabel.qml @@ -0,0 +1,13 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 +import QGroundControl.FactSystem 1.0 + +Label { + property Fact fact: Fact { value: "FactLabel" } + QGCPalette { id: palette; colorGroup: QGCPalette.Active } + + color: palette.windowText + + text: fact.value +} diff --git a/qml/QGroundControl/FactControls/FactTextField.qml b/qml/QGroundControl/FactControls/FactTextField.qml new file mode 100644 index 0000000000000000000000000000000000000000..b42ac3cc5823e9df3b6a2ed28799d85a9ef174b2 --- /dev/null +++ b/qml/QGroundControl/FactControls/FactTextField.qml @@ -0,0 +1,14 @@ +import QtQuick 2.2 +import QtQuick.Controls 1.2 +import QtQuick.Controls.Styles 1.2 +import QGroundControl.FactSystem 1.0 + +TextField { + property Fact fact: Fact { value: 0 } + + QGCPalette { id: palette; colorGroup: QGCPalette.Active } + + text: fact.value + + onAccepted: fact.value = text +} diff --git a/qml/QGroundControl/FactControls/qmldir b/qml/QGroundControl/FactControls/qmldir index 5c68157e2fac6b076dd322fa917cecda1d8281f5..b0c9edb64d6d83460d3840133bfbfd264fb6e4d4 100644 --- a/qml/QGroundControl/FactControls/qmldir +++ b/qml/QGroundControl/FactControls/qmldir @@ -1,2 +1,3 @@ Module QGroundControl.FactControls -SetupButton 1.0 SetupButton.qml \ No newline at end of file +FactLabel 1.0 FactLabel.qml +FactTextField 1.0 FactTextField.qml \ No newline at end of file diff --git a/src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc b/src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc index b3f20f47402ddd247e0401fdaf102b32a591d99f..a7fdf87ac74cf1624840a34bcccedeaac6f0d932 100644 --- a/src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc +++ b/src/AutoPilotPlugins/PX4/PX4ParameterFacts.cc @@ -263,4 +263,15 @@ void PX4ParameterFacts::clearStaticData(void) } _mapParameterName2FactMetaData.clear(); _parameterMetaDataLoaded = false; -} \ No newline at end of file +} + +/// Override from FactLoad which connects the meta data to the fact +void PX4ParameterFacts::_addMetaDataToFact(Fact* fact) +{ + if (_mapParameterName2FactMetaData.contains(fact->name())) { + fact->setMetaData(_mapParameterName2FactMetaData[fact->name()]); + } else { + // Use generic meta data + FactLoader::_addMetaDataToFact(fact); + } +} diff --git a/src/AutoPilotPlugins/PX4/PX4ParameterFacts.h b/src/AutoPilotPlugins/PX4/PX4ParameterFacts.h index 01771a264eaa63bd1f1ad6106fb16dae692b753f..e39ba6eac9c8ba72a7a4dc9165e9c3a877b46ccb 100644 --- a/src/AutoPilotPlugins/PX4/PX4ParameterFacts.h +++ b/src/AutoPilotPlugins/PX4/PX4ParameterFacts.h @@ -52,6 +52,10 @@ public: static void clearStaticData(void); private: + // Overrides from FactLoader + virtual void _addMetaDataToFact(Fact* fact); + + // Class methods static FactMetaData* _parseParameter(QXmlStreamReader& xml, const QString& group); static void _initMetaData(FactMetaData* metaData); static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool failOk = false); diff --git a/src/AutoPilotPlugins/PX4/SafetyComponent.qml b/src/AutoPilotPlugins/PX4/SafetyComponent.qml index 3ef0471745e8e844d74bc77e082bd45315da7a28..9e958ebdc90cd4f4378e7d0704eab6ef5ff51094 100644 --- a/src/AutoPilotPlugins/PX4/SafetyComponent.qml +++ b/src/AutoPilotPlugins/PX4/SafetyComponent.qml @@ -2,6 +2,7 @@ import QtQuick 2.2 import QtQuick.Controls 1.2 import QtQuick.Controls.Styles 1.2 import QGroundControl.FactSystem 1.0 +import QGroundControl.FactControls 1.0 Rectangle { QGCPalette { id: palette; colorGroup: QGCPalette.Active } @@ -12,6 +13,8 @@ Rectangle { Column { Label { text: "Work in Progress"; color: palette.windowText } - Label { text: autopilot.parameters["RTL_RETURN_ALT"].value; color: palette.windowText } + Label { text: "Return to Land Altitude"; color: palette.windowText } + FactLabel { fact: autopilot.parameters["RTL_RETURN_ALT"] } + FactTextField { fact: autopilot.parameters["RTL_RETURN_ALT"] } } } diff --git a/src/FactSystem/Fact.cc b/src/FactSystem/Fact.cc index e6bb1b4754a58b0d0aa8f3ccab9a35703fd1acea..11cd7b2012848449d26a0aaaf684e1a7cfef210f 100644 --- a/src/FactSystem/Fact.cc +++ b/src/FactSystem/Fact.cc @@ -28,10 +28,12 @@ #include -Fact::Fact(QObject* parent) : - QObject(parent) +Fact::Fact(QString name, QObject* parent) : + QObject(parent), + _name(name), + _metaData(NULL) { - + _value = ""; } void Fact::setValue(const QVariant& value) diff --git a/src/FactSystem/Fact.h b/src/FactSystem/Fact.h index 23ee2d6829e9a9a68680780f086f1e02bb09e260..ebfedfc57e717ea1a4ea798514340d767d8890b6 100644 --- a/src/FactSystem/Fact.h +++ b/src/FactSystem/Fact.h @@ -42,6 +42,7 @@ class Fact : public QObject { Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged USER true) Q_PROPERTY(QVariant defaultValue READ defaultValue CONSTANT) Q_PROPERTY(FactMetaData::ValueType_t type READ type CONSTANT) @@ -54,10 +55,13 @@ class Fact : public QObject Q_ENUMS(FactMetaData::ValueType_t) public: - Fact(QObject* parent = NULL); + Fact(QString name = "", QObject* parent = NULL); // Property system methods + /// Read accessor or name property + QString name(void) const { return _name; } + /// Read accessor for value property QVariant value(void) const { return _value; } @@ -102,6 +106,7 @@ signals: void _containerValueChanged(QVariant& value); private: + QString _name; ///< Fact name QVariant _value; ///< Fact value FactMetaData* _metaData; ///< FactMetaData object for Fact }; diff --git a/src/FactSystem/FactLoader.cc b/src/FactSystem/FactLoader.cc index c1ad52872f37b4d29d1cf1ab1e1fce9f1d66c4a5..5504b8826b1627e0c9d759d0fcc8b19a17bcaf0d 100644 --- a/src/FactSystem/FactLoader.cc +++ b/src/FactSystem/FactLoader.cc @@ -83,7 +83,9 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName } if (!_mapParameterName2Variant.contains(parameterName)) { - Fact* fact = new Fact(this); + qCDebug(FactLoaderLog) << "Adding new fact" << parameterName; + + Fact* fact = new Fact(parameterName, this); _mapParameterName2Variant[parameterName] = QVariant::fromValue(fact); _mapFact2ParameterName[fact] = parameterName; @@ -91,7 +93,7 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName // We need to know when the fact changes from QML so that we can send the new value to the parameter manager connect(fact, &Fact::_containerValueChanged, this, &FactLoader::_valueUpdated); - qCDebug(FactLoaderLog) << "Adding new fact" << parameterName; + _addMetaDataToFact(fact); } Q_ASSERT(_mapParameterName2Variant.contains(parameterName)); @@ -105,7 +107,7 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName /// Connected to Fact::valueUpdated /// -/// Sets the new value into the Parameter Manager. Paramter is persisted after send. +/// Sets the new value into the Parameter Manager. Parameter is persisted after send. void FactLoader::_valueUpdated(QVariant value) { Fact* fact = qobject_cast(sender()); @@ -157,3 +159,42 @@ void FactLoader::_paramMgrParameterListUpToDate(void) emit factsReady(); } } + +void FactLoader::_addMetaDataToFact(Fact* fact) +{ + // Create generic meta data based on value variant type + + FactMetaData::ValueType_t factType = FactMetaData::valueTypeInt32; // init to in32 to silence compiler warning + + switch ((QMetaType::Type)fact->value().type()) { + case QMetaType::Int: + factType = FactMetaData::valueTypeInt32; + break; + + case QMetaType::UInt: + factType = FactMetaData::valueTypeUint32; + break; + + case QMetaType::Double: + factType = FactMetaData::valueTypeDouble; + + case QMetaType::Short: + factType = FactMetaData::valueTypeInt16; + break; + + case QMetaType::UShort: + factType = FactMetaData::valueTypeUint16; + break; + + case QMetaType::Float: + factType = FactMetaData::valueTypeFloat; + break; + + default: + qCWarning(FactLoaderLog) << "Invalid variant type" << fact->value().type(); + break; + } + + FactMetaData* metaData = new FactMetaData(this); + metaData->initFromTypeOnly(factType); +} diff --git a/src/FactSystem/FactLoader.h b/src/FactSystem/FactLoader.h index ed9503df08a3d0bcccaf0255882bd195dbfb0984..699a1fbe0636c158904234d971783c97f73b201f 100644 --- a/src/FactSystem/FactLoader.h +++ b/src/FactSystem/FactLoader.h @@ -66,6 +66,11 @@ signals: /// Signalled when the full set of facts are ready void factsReady(void); +protected: + /// Base implementation adds generic meta data based on variant type. Derived class can override to provide + /// more details meta data. + virtual void _addMetaDataToFact(Fact* fact); + private slots: void _parameterChanged(int uas, int component, QString parameterName, QVariant value); void _valueUpdated(QVariant value); diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index 769bb49000b965f576fff4d171830a8d7c777557..1b4de8954b025362f1e1d6e40fa7de8562dc0d50 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -31,5 +31,12 @@ FactMetaData::FactMetaData(QObject* parent) : QObject(parent) { + initFromTypeOnly(valueTypeInt32); +} +void FactMetaData::initFromTypeOnly(ValueType_t initType) +{ + type = initType; + + // FIXME: NYI } diff --git a/src/FactSystem/FactMetaData.h b/src/FactSystem/FactMetaData.h index 9370b4316aadf9b56653df8c54fd2b86c8cd1afa..47924be5ee81e5a1fcde420f35c4f129874e9ac9 100644 --- a/src/FactSystem/FactMetaData.h +++ b/src/FactSystem/FactMetaData.h @@ -54,8 +54,12 @@ public: valueTypeDouble } ValueType_t; - QVariant defaultValue; + /// Initialize the meta data given only the type. + void initFromTypeOnly(ValueType_t initType); + + // FIXME: This needs to switch over to Q_PROPERTY mechanism ValueType_t type; + QVariant defaultValue; QString shortDescription; QString longDescription; QString units;