Unverified Commit ecdf6d7a authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #9044 from DonLakeFlyer/RegexParamMetadata

COMPONENT_INFORMATION:COMP_METADATA_TYPE_PARAMETER Changed parameter name regex support
parents a11fb32c 14ab96cd
...@@ -76,30 +76,58 @@ void CompInfoParam::setJson(const QString& metadataJsonFileName, const QString& ...@@ -76,30 +76,58 @@ void CompInfoParam::setJson(const QString& metadataJsonFileName, const QString&
} }
FactMetaData* newMetaData = FactMetaData::createFromJsonObject(parameterValue.toObject(), emptyDefineMap, this); FactMetaData* newMetaData = FactMetaData::createFromJsonObject(parameterValue.toObject(), emptyDefineMap, this);
QRegularExpression regexNameIncludesRegex("/\\(.+\\)/");
QRegularExpressionMatch match = regexNameIncludesRegex.match(newMetaData->name());
if (match.hasMatch()) {
QString regexParamName = newMetaData->name();
regexParamName.replace(QRegularExpression("/(\\(.+\\))/"), "\\1");
newMetaData->setName(regexParamName);
_regexNameMetaDataList.append(RegexFactMetaDataPair_t(newMetaData->name(), newMetaData));
} else {
_nameToMetaDataMap[newMetaData->name()] = newMetaData; _nameToMetaDataMap[newMetaData->name()] = newMetaData;
} }
}
} }
FactMetaData* CompInfoParam::factMetaDataForName(const QString& name, FactMetaData::ValueType_t type) FactMetaData* CompInfoParam::factMetaDataForName(const QString& name, FactMetaData::ValueType_t type)
{ {
FactMetaData* factMetaData = nullptr;
if (_opaqueParameterMetaData) { if (_opaqueParameterMetaData) {
return vehicle->firmwarePlugin()->_getMetaDataForFact(_opaqueParameterMetaData, name, type, vehicle->vehicleType()); factMetaData = vehicle->firmwarePlugin()->_getMetaDataForFact(_opaqueParameterMetaData, name, type, vehicle->vehicleType());
} else {
if (_nameToMetaDataMap.contains(name)) {
factMetaData = _nameToMetaDataMap[name];
} else { } else {
QString indexTagName = name; for (int i=0; i<_regexNameMetaDataList.count(); i++) {
if (!_nameToMetaDataMap.contains(name)) { const RegexFactMetaDataPair_t& pair = _regexNameMetaDataList[i];
// Checked for indexed parameter names: "FOO<#>_BAR" will match "FOO1_BAR" QString regexParamName = pair.first;
QRegularExpression regex("\\d+"); QRegularExpression regex(regexParamName);
indexTagName = indexTagName.replace(regex, _parameterIndexTag); QRegularExpressionMatch match = regex.match(name);
if (!_nameToMetaDataMap.contains(indexTagName)) { QStringList captured = match.capturedTexts();
indexTagName.clear(); if (captured.count() == 2) {
factMetaData = new FactMetaData(*pair.second, this);
factMetaData->setName(name);
QString shortDescription = factMetaData->shortDescription();
shortDescription.replace("/1", captured[1]);
factMetaData->setShortDescription(shortDescription);
QString longDescription = factMetaData->shortDescription();
longDescription.replace("/1", captured[1]);
factMetaData->setLongDescription(longDescription);
} }
} }
if (indexTagName.isEmpty()) {
indexTagName = name; if (!factMetaData) {
_nameToMetaDataMap[name] = new FactMetaData(type, this); factMetaData = new FactMetaData(type, this);
}
_nameToMetaDataMap[name] = factMetaData;
} }
return _nameToMetaDataMap[indexTagName];
} }
return factMetaData;
} }
bool CompInfoParam::_isParameterVolatile(const QString& name) bool CompInfoParam::_isParameterVolatile(const QString& name)
......
...@@ -44,8 +44,11 @@ private: ...@@ -44,8 +44,11 @@ private:
static FirmwarePlugin* _anyVehicleTypeFirmwarePlugin (MAV_AUTOPILOT firmwareType); static FirmwarePlugin* _anyVehicleTypeFirmwarePlugin (MAV_AUTOPILOT firmwareType);
static QString _parameterMetaDataFile (Vehicle* vehicle, MAV_AUTOPILOT firmwareType, int wantedMajorVersion, int& majorVersion, int& minorVersion); static QString _parameterMetaDataFile (Vehicle* vehicle, MAV_AUTOPILOT firmwareType, int wantedMajorVersion, int& majorVersion, int& minorVersion);
typedef QPair<QString /* regexName */, FactMetaData*> RegexFactMetaDataPair_t;
bool _noJsonMetadata = true; bool _noJsonMetadata = true;
FactMetaData::NameToMetaDataMap_t _nameToMetaDataMap; FactMetaData::NameToMetaDataMap_t _nameToMetaDataMap;
QList<RegexFactMetaDataPair_t> _regexNameMetaDataList;
QObject* _opaqueParameterMetaData = nullptr; QObject* _opaqueParameterMetaData = nullptr;
static const char* _cachedMetaDataFilePrefix; static const char* _cachedMetaDataFilePrefix;
......
This diff is collapsed.
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