Commit b7e1d217 authored by DonLakeFlyer's avatar DonLakeFlyer

parent c5a69b3b
...@@ -23,7 +23,7 @@ QGC_LOGGING_CATEGORY(CompInfoParamLog, "CompInfoParamLog") ...@@ -23,7 +23,7 @@ QGC_LOGGING_CATEGORY(CompInfoParamLog, "CompInfoParamLog")
const char* CompInfoParam::_jsonScopeKey = "scope"; const char* CompInfoParam::_jsonScopeKey = "scope";
const char* CompInfoParam::_jsonParametersKey = "parameters"; const char* CompInfoParam::_jsonParametersKey = "parameters";
const char* CompInfoParam::_cachedMetaDataFilePrefix = "ParameterFactMetaData"; const char* CompInfoParam::_cachedMetaDataFilePrefix = "ParameterFactMetaData";
const char* CompInfoParam::_parameterIndexTag = "<#>"; const char* CompInfoParam::_indexedNameTag = "{n}";
CompInfoParam::CompInfoParam(uint8_t compId, Vehicle* vehicle, QObject* parent) CompInfoParam::CompInfoParam(uint8_t compId, Vehicle* vehicle, QObject* parent)
: CompInfo(COMP_METADATA_TYPE_PARAMETER, compId, vehicle, parent) : CompInfo(COMP_METADATA_TYPE_PARAMETER, compId, vehicle, parent)
...@@ -77,13 +77,8 @@ void CompInfoParam::setJson(const QString& metadataJsonFileName, const QString& ...@@ -77,13 +77,8 @@ 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("/\\(.+\\)/"); if (newMetaData->name().contains(_indexedNameTag)) {
QRegularExpressionMatch match = regexNameIncludesRegex.match(newMetaData->name()); _indexedNameMetaDataList.append(RegexFactMetaDataPair_t(newMetaData->name(), newMetaData));
if (match.hasMatch()) {
QString regexParamName = newMetaData->name();
regexParamName.replace(QRegularExpression("/(\\(.+\\))/"), "\\1");
newMetaData->setName(regexParamName);
_regexNameMetaDataList.append(RegexFactMetaDataPair_t(newMetaData->name(), newMetaData));
} else { } else {
_nameToMetaDataMap[newMetaData->name()] = newMetaData; _nameToMetaDataMap[newMetaData->name()] = newMetaData;
} }
...@@ -100,21 +95,27 @@ FactMetaData* CompInfoParam::factMetaDataForName(const QString& name, FactMetaDa ...@@ -100,21 +95,27 @@ FactMetaData* CompInfoParam::factMetaDataForName(const QString& name, FactMetaDa
if (_nameToMetaDataMap.contains(name)) { if (_nameToMetaDataMap.contains(name)) {
factMetaData = _nameToMetaDataMap[name]; factMetaData = _nameToMetaDataMap[name];
} else { } else {
for (int i=0; i<_regexNameMetaDataList.count(); i++) { // We didn't get any direct matches. Try an indexed name.
const RegexFactMetaDataPair_t& pair = _regexNameMetaDataList[i]; for (int i=0; i<_indexedNameMetaDataList.count(); i++) {
QString regexParamName = pair.first; const RegexFactMetaDataPair_t& pair = _indexedNameMetaDataList[i];
QRegularExpression regex(regexParamName);
QString indexedName = pair.first;
QString indexedRegex("(\\d+)");
indexedName.replace(_indexedNameTag, indexedRegex);
QRegularExpression regex(indexedName);
QRegularExpressionMatch match = regex.match(name); QRegularExpressionMatch match = regex.match(name);
QStringList captured = match.capturedTexts(); QStringList captured = match.capturedTexts();
if (captured.count() == 2) { if (captured.count() == 2) {
factMetaData = new FactMetaData(*pair.second, this); factMetaData = new FactMetaData(*pair.second, this);
factMetaData->setName(name); factMetaData->setName(name);
QString shortDescription = factMetaData->shortDescription(); QString shortDescription = factMetaData->shortDescription();
shortDescription.replace("/1", captured[1]); shortDescription.replace(_indexedNameTag, captured[1]);
factMetaData->setShortDescription(shortDescription); factMetaData->setShortDescription(shortDescription);
QString longDescription = factMetaData->shortDescription(); QString longDescription = factMetaData->shortDescription();
longDescription.replace("/1", captured[1]); longDescription.replace(_indexedNameTag, captured[1]);
factMetaData->setLongDescription(longDescription); factMetaData->setLongDescription(longDescription);
} }
} }
......
...@@ -44,15 +44,15 @@ private: ...@@ -44,15 +44,15 @@ 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; typedef QPair<QString /* indexed name */, FactMetaData*> RegexFactMetaDataPair_t;
bool _noJsonMetadata = true; bool _noJsonMetadata = true;
FactMetaData::NameToMetaDataMap_t _nameToMetaDataMap; FactMetaData::NameToMetaDataMap_t _nameToMetaDataMap;
QList<RegexFactMetaDataPair_t> _regexNameMetaDataList; QList<RegexFactMetaDataPair_t> _indexedNameMetaDataList;
QObject* _opaqueParameterMetaData = nullptr; QObject* _opaqueParameterMetaData = nullptr;
static const char* _cachedMetaDataFilePrefix; static const char* _cachedMetaDataFilePrefix;
static const char* _jsonScopeKey; static const char* _jsonScopeKey;
static const char* _jsonParametersKey; static const char* _jsonParametersKey;
static const char* _parameterIndexTag; static const char* _indexedNameTag;
}; };
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