From ff1e5cedc5b4bacc80c2ce4ff82061aab2385a1d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sun, 9 Jan 2022 10:07:27 +0100 Subject: [PATCH] Add default category on-the-fly --- companion/src/firmwares/edgetx/edgetxinterface.cpp | 13 +++++++++---- companion/src/radiointerface.cpp | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/companion/src/firmwares/edgetx/edgetxinterface.cpp b/companion/src/firmwares/edgetx/edgetxinterface.cpp index 4b86a17d7..eaca13e8c 100644 --- a/companion/src/firmwares/edgetx/edgetxinterface.cpp +++ b/companion/src/firmwares/edgetx/edgetxinterface.cpp @@ -110,18 +110,23 @@ bool writeModelsListToYaml(const std::vector& categories, QByteArray& data) { YAML::Node node; + std::vector cats = categories; for (const auto& modelFile: modelFiles) { YAML::Node cat_attrs; cat_attrs["filename"] = modelFile.filename; cat_attrs["name"] = modelFile.name; - if (modelFile.category >= (int)categories.size()) { - return false; + auto catIdx = modelFile.category; + if (catIdx >= (int)cats.size()) { + catIdx = 0; + if (cats.size() == 0) { + cats.push_back("Models"); + } } - const std::string cat_name = categories[modelFile.category].name; - node[modelFile.category][cat_name].push_back(cat_attrs); + const std::string cat_name = cats[catIdx].name; + node[catIdx][cat_name].push_back(cat_attrs); } writeYamlToByteArray(node, data); diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index 40379f474..9e508cfda 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -220,7 +220,7 @@ bool readSettingsSDCard(const QString & filename, ProgressWidget * progress) } Storage outputStorage(filename); 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; }