Commit 1f618979 authored by Don Gagne's avatar Don Gagne

Merge pull request #1120 from DonLakeFlyer/FSVariantArray

Switch parameter facts to QVariantMap
parents 277c1618 a9e3af1e
......@@ -53,10 +53,9 @@ public:
/// Returns the parameter facts for the specified UAS.
///
/// Access to parameter properties is done through QObject::property or the full
/// QMetaObject methods. The property name is the parameter name. You should not
/// request parameter facts until the plugin reports that it is ready.
virtual QObject* parameterFacts(void) const = 0;
/// Key is parameter name. Get Fact object like this: _mapParameterName2Variant["RC_MAP_THROTTLE"].value<Fact*>().
/// You should not request parameter facts until the plugin reports that it is ready.
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.
......
......@@ -86,14 +86,15 @@ QString GenericAutoPilotPlugin::getShortModeText(uint8_t baseMode, uint32_t cust
void GenericAutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const
{
Q_UNUSED(context);
// Qml not yet supported for Generic
Q_ASSERT(false);
Q_ASSERT_X(false, "Not yet implemented", "");
}
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)
......
......@@ -42,7 +42,7 @@ public:
// Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) 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; }
static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
......
......@@ -212,7 +212,7 @@ void PX4AutoPilotPlugin::addFactsToQmlContext(QQmlContext* context) const
Q_ASSERT(_parameterFacts->factsAreReady());
context->setContextProperty("parameterFacts", _parameterFacts);
context->setContextProperty("parameters", _parameterFacts->factMap());
}
void PX4AutoPilotPlugin::clearStaticData(void)
......
......@@ -44,7 +44,7 @@ public:
// Overrides from AutoPilotPlugin
virtual QList<VehicleComponent*> getVehicleComponents(void) 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;
static QList<AutoPilotPluginManager::FullMode_t> getModes(void);
......
......@@ -64,7 +64,7 @@ PX4ParameterFacts::~PX4ParameterFacts()
foreach(Fact* fact, _mapFact2ParameterName.keys()) {
delete fact;
}
_mapParameterName2Fact.clear();
_mapParameterName2Variant.clear();
_mapFact2ParameterName.clear();
}
......@@ -93,28 +93,31 @@ void PX4ParameterFacts::_parameterChanged(int uas, int component, QString parame
Q_ASSERT(component == _lastSeenComponent);
}
// If we don't have meta data for the parameter it can't be part of the FactSystem
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)) {
if (!_mapParameterName2Variant.contains(parameterName)) {
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;
// 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);
//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
......
......@@ -96,13 +96,11 @@ void FactSystemTest::_parameter_test(void)
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin);
QObject* parameterFacts = plugin->parameterFacts();
QVERIFY(parameterFacts != NULL);
const QVariantMap& parameterFacts = plugin->parameterFacts();
// Compare the value in the Parameter Manager with the value from the FactSystem
QVariant factVariant = parameterFacts->property("RC_MAP_THROTTLE");
Fact* fact = factVariant.value<Fact*>();
Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>();
QVERIFY(fact != NULL);
QVariant factValue = fact->value();
QCOMPARE(factValue.isValid(), true);
......@@ -142,11 +140,9 @@ void FactSystemTest::_paramMgrSignal_test(void)
AutoPilotPlugin* plugin = pluginMgr->getInstanceForAutoPilotPlugin(_uas);
Q_ASSERT(plugin);
QObject* parameterFacts = plugin->parameterFacts();
QVERIFY(parameterFacts != NULL);
const QVariantMap& parameterFacts = plugin->parameterFacts();
QVariant factVariant = parameterFacts->property("RC_MAP_THROTTLE");
Fact* fact = factVariant.value<Fact*>();
Fact* fact = parameterFacts["RC_MAP_THROTTLE"].value<Fact*>();
QVERIFY(fact != NULL);
// Setting a new value into the parameter should trigger a valueChanged signal on the Fact
......
......@@ -6,11 +6,11 @@ import QGroundControlFactControls 1.0
Item {
TextInput {
objectName: "testControl"
text: parameterFacts.RC_MAP_THROTTLE.value
text: parameters["RC_MAP_THROTTLE"].value
font.family: "Helvetica"
font.pointSize: 24
color: "red"
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;
/// The validator uses the FactMetaData to impose restrictions on the input. It is used as follows:
/// @code{.unparsed}
/// TextInput {
/// validator: FactValidator { fact: parameterFacts.RC_MAP_THROTTLE; }
/// validator: FactValidator { fact: parameters["RC_MAP_THROTTLE"]; }
/// }
/// @endcode
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