Fixed metadata in models.yml
This commit is contained in:
@@ -65,7 +65,9 @@ bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||
for (const auto& model : models) {
|
||||
std::string filename;
|
||||
model["filename"] >> filename;
|
||||
modelFiles.push_back({ filename, categories.size()-1 });
|
||||
std::string name;
|
||||
model["name"] >> name;
|
||||
modelFiles.push_back({filename, name, (int)categories.size() - 1});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,14 +126,15 @@ bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
||||
for (const auto& modelFile: modelFiles) {
|
||||
|
||||
YAML::Node cat_attrs;
|
||||
cat_attrs["filename"] = modelFile.first;
|
||||
cat_attrs["filename"] = modelFile.filename;
|
||||
cat_attrs["name"] = modelFile.name;
|
||||
|
||||
if (modelFile.second >= (int)categories.size()) {
|
||||
if (modelFile.category >= (int)categories.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string cat_name = categories[modelFile.second].name;
|
||||
node[modelFile.second][cat_name].push_back(cat_attrs);
|
||||
const std::string cat_name = categories[modelFile.category].name;
|
||||
node[modelFile.category][cat_name].push_back(cat_attrs);
|
||||
}
|
||||
|
||||
writeYamlToByteArray(node, data);
|
||||
|
||||
@@ -29,8 +29,13 @@
|
||||
|
||||
constexpr unsigned int CPN_CURRENT_SETTINGS_VERSION = { 221 };
|
||||
|
||||
typedef std::pair<std::string, int> EtxModelfileCategoryPair;
|
||||
typedef std::list<EtxModelfileCategoryPair> EtxModelfiles;
|
||||
struct EtxModelMetadata {
|
||||
std::string filename;
|
||||
std::string name;
|
||||
int category;
|
||||
};
|
||||
|
||||
typedef std::list<EtxModelMetadata> EtxModelfiles;
|
||||
|
||||
bool loadModelsListFromYaml(std::vector<CategoryData>& categories,
|
||||
EtxModelfiles& modelFiles,
|
||||
|
||||
@@ -258,10 +258,10 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
|
||||
int modelIdx = 0;
|
||||
for (const auto& mc : modelFiles) {
|
||||
qDebug() << "Filename: " << mc.first.c_str() << " / Category: " << mc.second;
|
||||
qDebug() << "Filename: " << mc.filename.c_str() << " / Category: " << mc.category;
|
||||
|
||||
QByteArray modelBuffer;
|
||||
QString filename = "MODELS/" + QString::fromStdString(mc.first);
|
||||
QString filename = "MODELS/" + QString::fromStdString(mc.filename);
|
||||
if (!loadFile(modelBuffer, filename)) {
|
||||
setError(tr("Can't extract ") + filename);
|
||||
return false;
|
||||
@@ -277,9 +277,9 @@ bool CategorizedStorageFormat::loadYaml(RadioData & radioData)
|
||||
return false;
|
||||
}
|
||||
|
||||
model.category = mc.second;
|
||||
model.category = mc.category;
|
||||
model.modelIndex = modelIdx;
|
||||
strncpy(model.filename, mc.first.c_str(), sizeof(model.filename)-1);
|
||||
strncpy(model.filename, mc.filename.c_str(), sizeof(model.filename)-1);
|
||||
|
||||
model.used = true;
|
||||
modelIdx++;
|
||||
@@ -317,7 +317,8 @@ bool CategorizedStorageFormat::writeYaml(const RadioData & radioData)
|
||||
QString modelFilename;
|
||||
if (hasCategories) {
|
||||
modelFilename = QString("MODELS/%1").arg(model.filename);
|
||||
modelFiles.push_back({ std::string(model.filename), model.category });
|
||||
modelFiles.push_back({std::string(model.filename),
|
||||
std::string(model.name), model.category});
|
||||
} else {
|
||||
modelFilename = QString("MODELS/model%1.yml")
|
||||
.arg(model.modelIndex, 2, 10, QLatin1Char('0'));
|
||||
|
||||
Reference in New Issue
Block a user