Add default category on-the-fly
This commit is contained in:
@@ -110,18 +110,23 @@ bool writeModelsListToYaml(const std::vector<CategoryData>& categories,
|
|||||||
QByteArray& data)
|
QByteArray& data)
|
||||||
{
|
{
|
||||||
YAML::Node node;
|
YAML::Node node;
|
||||||
|
std::vector<CategoryData> cats = categories;
|
||||||
for (const auto& modelFile: modelFiles) {
|
for (const auto& modelFile: modelFiles) {
|
||||||
|
|
||||||
YAML::Node cat_attrs;
|
YAML::Node cat_attrs;
|
||||||
cat_attrs["filename"] = modelFile.filename;
|
cat_attrs["filename"] = modelFile.filename;
|
||||||
cat_attrs["name"] = modelFile.name;
|
cat_attrs["name"] = modelFile.name;
|
||||||
|
|
||||||
if (modelFile.category >= (int)categories.size()) {
|
auto catIdx = modelFile.category;
|
||||||
return false;
|
if (catIdx >= (int)cats.size()) {
|
||||||
|
catIdx = 0;
|
||||||
|
if (cats.size() == 0) {
|
||||||
|
cats.push_back("Models");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string cat_name = categories[modelFile.category].name;
|
const std::string cat_name = cats[catIdx].name;
|
||||||
node[modelFile.category][cat_name].push_back(cat_attrs);
|
node[catIdx][cat_name].push_back(cat_attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
writeYamlToByteArray(node, data);
|
writeYamlToByteArray(node, data);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ bool readSettingsSDCard(const QString & filename, ProgressWidget * progress)
|
|||||||
}
|
}
|
||||||
Storage outputStorage(filename);
|
Storage outputStorage(filename);
|
||||||
if (!outputStorage.write(radioData)) {
|
if (!outputStorage.write(radioData)) {
|
||||||
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QCoreApplication::translate("RadioInterface", "Failed to write Models and Setting file") % filename);
|
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QCoreApplication::translate("RadioInterface", "Failed to write Models and Setting file") % " " % filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user