Commit a9e3af1e authored by Don Gagne's avatar Don Gagne

Switch parameter facts to QVariantMap

This way you don’t need to know parameter set ahead of time.
parent 0f4a168f
...@@ -53,10 +53,9 @@ public: ...@@ -53,10 +53,9 @@ public:
/// Returns the parameter facts for the specified UAS. /// Returns the parameter facts for the specified UAS.
/// ///
/// Access to parameter properties is done through QObject::property or the full /// Key is parameter name. Get Fact object like this: _mapParameterName2Variant["RC_MAP_THROTTLE"].value<Fact*>().
/// QMetaObject methods. The property name is the parameter name. You should not /// You should not request parameter facts until the plugin reports that it is ready.
/// request parameter facts until the plugin reports that it is ready. virtual const QVariantMap& parameterFacts(void) const = 0;
virtual QObject* parameterFacts(void) const = 0;
/// Adds the FactSystem properties to the Qml context. You should not call /// Adds the FactSystem properties to the Qml context. You should not call
/// this method until the plugin reports that it is ready. /// this method until the plugin reports that it is ready.
......
...@@ -86,14 +86,15 @@ QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t cust ...@@ -86,14 +86,15 @@ QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t cust
void GenericAutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const void GenericAutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const
{ {
Q_UNUSED(context); Q_UNUSED(context);
Q_ASSERT_X(false, "Not yet implemented", "");
// Qml not yet supported for Generic
Q_ASSERT(false);
} }
QObject* GenericAutoPilotPlugin::parameterFacts(void) const const QVariantMap& GenericAutoPilotPlugin::parameterFacts(void) const
{ {
return NULL; static QVariantMap staticMap;
Q_ASSERT_X(false, "Not yet implemented", "");
return staticMap;
} }
void GenericAutoPilotPlugin::clearStaticData(void) void GenericAutoPilotPlugin::clearStaticData(void)
......
...@@ -42,7 +42,7 @@ public: ...@@ -42,7 +42,7 @@ public:
// Overrides from AutoPilotPlugin // Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) const ; virtual QList<VehicleComponent*> getVehicleComponents(void) const ;
virtual void addFactsToQmlContext(QQmlContext* context) const; virtual void addFactsToQmlContext(QQmlContext* context) const;
virtual QObject* parameterFacts(void) const; virtual const QVariantMap& parameterFacts(void) const;
virtual bool pluginIsReady(void) const { return true; } virtual bool pluginIsReady(void) const { return true; }
static QList<AutoPilotPluginManager::FullMode_t> getModes(void); static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
......
...@@ -212,7 +212,7 @@ void PX4AutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const ...@@ -212,7 +212,7 @@ void PX4AutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const
Q_ASSERT(_parameterFacts->factsAreReady()); Q_ASSERT(_parameterFacts->factsAreReady());
context->setContextProperty("parameterFacts", _parameterFacts); context->setContextProperty("parameters", _parameterFacts->factMap());
} }
void PX4AutoPilotPlugin::clearStaticData(void) void PX4AutoPilotPlugin::clearStaticData(void)
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
// Overrides from AutoPilotPlugin // Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) const ; virtual QList<VehicleComponent*> getVehicleComponents(void) const ;
virtual void addFactsToQmlContext(QQmlContext* context) const; virtual void addFactsToQmlContext(QQmlContext* context) const;
virtual QObject* parameterFacts(void) const { return _parameterFacts; } virtual const QVariantMap& parameterFacts(void) const { return _parameterFacts->factMap(); }
virtual bool pluginIsReady(void) const; virtual bool pluginIsReady(void) const;
static QList<AutoPilotPluginManager::FullMode_t> getModes(void); static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
......
...@@ -64,7 +64,7 @@ PX4ParameterFacts::~PX4ParameterFacts() ...@@ -64,7 +64,7 @@ PX4ParameterFacts::~PX4ParameterFacts()
foreach(Fact* fact, _mapFact2ParameterName.keys()) { foreach(Fact* fact, _mapFact2ParameterName.keys()) {
delete fact; delete fact;
} }
_mapParameterName2Fact.clear(); _mapParameterName2Variant.clear();
_mapFact2ParameterName.clear(); _mapFact2ParameterName.clear();
} }
...@@ -93,28 +93,31 @@ void PX4ParameterFacts::_parameterChanged(int uas, int component, QString parame ...@@ -93,28 +93,31 @@ void PX4ParameterFacts::_parameterChanged(int uas, int component, QString parame
Q_ASSERT(component == _lastSeenComponent); Q_ASSERT(component == _lastSeenComponent);
} }
// If we don't have meta data for the parameter it can't be part of the FactSystem if (!_mapParameterName2Variant.contains(parameterName)) {
if (!_mapParameterName2FactMetaData.contains(parameterName)) {
// FIXME: Debug or Warning. Warning will fail TC
qDebug() << "FactSystem meta data out of date. Missing parameter:" << parameterName;
return;
}
if (!_mapParameterName2Fact.contains(parameterName)) {
Fact* fact = new Fact(this); Fact* fact = new Fact(this);
fact->setMetaData(_mapParameterName2FactMetaData[parameterName]); if (_mapParameterName2FactMetaData.contains(parameterName)) {
fact->setMetaData(_mapParameterName2FactMetaData[parameterName]);
} else {
qDebug() << "FactSystem meta data out of date. Missing parameter:" << parameterName;
}
_mapParameterName2Fact[parameterName] = fact; _mapParameterName2Variant[parameterName] = QVariant::fromValue(fact);
_mapFact2ParameterName[fact] = parameterName; _mapFact2ParameterName[fact] = parameterName;
// We need to know when the fact changes so that we can send the new value to the parameter manager // We need to know when the fact changes so that we can send the new value to the parameter manager
connect(fact, &Fact::_containerValueChanged, this, &PX4ParameterFacts::_valueUpdated); connect(fact, &Fact::_containerValueChanged, this, &PX4ParameterFacts::_valueUpdated);
//qDebug() << "Adding new fact" << parameterName; qCDebug(PX4ParameterFactsLog) << "Adding new fact" << parameterName;
} }
//qDebug() << "Updating fact value" << parameterName << value;
_mapParameterName2Fact[parameterName]->_containerSetValue(value); Q_ASSERT(_mapParameterName2Variant.contains(parameterName));
qCDebug(PX4ParameterFactsLog) << "Updating fact value" << parameterName << value;
Fact* fact = _mapParameterName2Variant[parameterName].value<Fact*>();
Q_ASSERT(fact);
fact->_containerSetValue(value);
} }
/// Connected to Fact::valueUpdated /// Connected to Fact::valueUpdated
......
...@@ -96,13 +96,11 @@ void FactSystemTest::_parameter_test(void) ...@@ -96,13 +96,11 @@ void FactSystemTest::_parameter_test(void)
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas); AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin); Q_ASSERT(plugin);
QObject* parameterFacts = plugin->parameterFacts(); const QVariantMap& parameterFacts = plugin->parameterFacts();
QVERIFY(parameterFacts != NULL);
// 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
QVariant factVariant = parameterFacts->property("RC_MAP_THROTTLE"); Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>();
Fact* fact = factVariant.value<Fact*>();
QVERIFY(fact != NULL); QVERIFY(fact != NULL);
QVariant factValue = fact->value(); QVariant factValue = fact->value();
QCOMPARE(factValue.isValid(), true); QCOMPARE(factValue.isValid(), true);
...@@ -142,11 +140,9 @@ void FactSystemTest::_paramMgrSignal_test(void) ...@@ -142,11 +140,9 @@ void FactSystemTest::_paramMgrSignal_test(void)
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas); AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin); Q_ASSERT(plugin);
QObject* parameterFacts = plugin->parameterFacts(); const QVariantMap& parameterFacts = plugin->parameterFacts();
QVERIFY(parameterFacts != NULL);
QVariant factVariant = parameterFacts->property("RC_MAP_THROTTLE"); Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>();
Fact* fact = factVariant.value<Fact*>();
QVERIFY(fact != NULL); QVERIFY(fact != NULL);
// Setting a new value into the parameter should trigger a valueChanged signal on the Fact // Setting a new value into the parameter should trigger a valueChanged signal on the Fact
......
...@@ -6,11 +6,11 @@ import QGroundControlFactControls 1.0 ...@@ -6,11 +6,11 @@ import QGroundControlFactControls 1.0
Item { Item {
TextInput { TextInput {
objectName: "testControl" objectName: "testControl"
text: parameterFacts.RC_MAP_THROTTLE.value text: 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: { parameterFacts.RC_MAP_THROTTLE.value = text; } onAccepted: { parameters["RC_MAP_THROTTLE"].value = text; }
} }
} }
\ No newline at end of file
...@@ -36,7 +36,7 @@ class Fact; ...@@ -36,7 +36,7 @@ class Fact;
/// The validator uses the FactMetaData to impose restrictions on the input. It is used as follows: /// The validator uses the FactMetaData to impose restrictions on the input. It is used as follows:
/// @code{.unparsed} /// @code{.unparsed}
/// TextInput { /// TextInput {
/// validator: FactValidator { fact: parameterFacts.RC_MAP_THROTTLE; } /// validator: FactValidator { fact: parameters["RC_MAP_THROTTLE"]; }
/// } /// }
/// @endcode /// @endcode
class FactValidator : public QValidator class FactValidator : public QValidator
......
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