Commit e79c7162 authored by Don Gagne's avatar Don Gagne

Fix generic metadata loading

parent c041e95b
...@@ -82,18 +82,18 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName ...@@ -82,18 +82,18 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName
Q_ASSERT(component == _lastSeenComponent); Q_ASSERT(component == _lastSeenComponent);
} }
bool setMetaData = false;
if (!_mapParameterName2Variant.contains(parameterName)) { if (!_mapParameterName2Variant.contains(parameterName)) {
qCDebug(FactLoaderLog) << "Adding new fact" << parameterName; qCDebug(FactLoaderLog) << "Adding new fact" << parameterName;
Fact* fact = new Fact(parameterName, this); Fact* fact = new Fact(parameterName, this);
setMetaData = true;
_mapParameterName2Variant[parameterName] = QVariant::fromValue(fact); _mapParameterName2Variant[parameterName] = QVariant::fromValue(fact);
_mapFact2ParameterName[fact] = parameterName; _mapFact2ParameterName[fact] = parameterName;
// We need to know when the fact changes from QML so that we can send the new value to the parameter manager // 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); connect(fact, &Fact::_containerValueChanged, this, &FactLoader::_valueUpdated);
_addMetaDataToFact(fact);
} }
Q_ASSERT(_mapParameterName2Variant.contains(parameterName)); Q_ASSERT(_mapParameterName2Variant.contains(parameterName));
...@@ -103,6 +103,10 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName ...@@ -103,6 +103,10 @@ void FactLoader::_parameterChanged(int uas, int component, QString parameterName
Fact* fact = _mapParameterName2Variant[parameterName].value<Fact*>(); Fact* fact = _mapParameterName2Variant[parameterName].value<Fact*>();
Q_ASSERT(fact); Q_ASSERT(fact);
fact->_containerSetValue(value); fact->_containerSetValue(value);
if (setMetaData) {
_addMetaDataToFact(fact);
}
} }
/// Connected to Fact::valueUpdated /// Connected to Fact::valueUpdated
...@@ -122,23 +126,26 @@ void FactLoader::_valueUpdated(QVariant value) ...@@ -122,23 +126,26 @@ void FactLoader::_valueUpdated(QVariant value)
case FactMetaData::valueTypeInt8: case FactMetaData::valueTypeInt8:
case FactMetaData::valueTypeInt16: case FactMetaData::valueTypeInt16:
case FactMetaData::valueTypeInt32: case FactMetaData::valueTypeInt32:
typedValue = QVariant(value.value<int>()); typedValue.setValue(QVariant(value.toInt()));
break;
case FactMetaData::valueTypeUint8: case FactMetaData::valueTypeUint8:
case FactMetaData::valueTypeUint16: case FactMetaData::valueTypeUint16:
case FactMetaData::valueTypeUint32: case FactMetaData::valueTypeUint32:
typedValue = QVariant(value.value<uint>()); typedValue.setValue(value.toUInt());
break; break;
case FactMetaData::valueTypeFloat: case FactMetaData::valueTypeFloat:
typedValue = QVariant(value.toFloat()); typedValue.setValue(value.toFloat());
break; break;
case FactMetaData::valueTypeDouble: case FactMetaData::valueTypeDouble:
typedValue = QVariant(value.toDouble()); typedValue.setValue(value.toDouble());
break; break;
} }
qCDebug(FactLoaderLog) << "Set parameter" << fact->name() << typedValue;
_paramMgr->setParameter(_lastSeenComponent, _mapFact2ParameterName[fact], typedValue); _paramMgr->setParameter(_lastSeenComponent, _mapFact2ParameterName[fact], typedValue);
_paramMgr->sendPendingParameters(true /* persistAfterSend */, false /* forceSend */); _paramMgr->sendPendingParameters(true /* persistAfterSend */, false /* forceSend */);
} }
...@@ -191,7 +198,7 @@ void FactLoader::_addMetaDataToFact(Fact* fact) ...@@ -191,7 +198,7 @@ void FactLoader::_addMetaDataToFact(Fact* fact)
break; break;
default: default:
qCWarning(FactLoaderLog) << "Invalid variant type" << fact->value().type(); qWarning() << fact->name() << "Invalid variant type" << fact->value().type();
break; break;
} }
......
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