From 5f4def2f9138dad35e6ec6383b28a123aa510f90 Mon Sep 17 00:00:00 2001 From: eshifri <46511024+eshifri@users.noreply.github.com> Date: Wed, 7 Sep 2022 01:29:59 -0700 Subject: [PATCH] fix: Changing label order for only two labels could trigger EM (#2273) * Fix definition for signed value * Support changing order of the labels for two labels * Swap labels when there is only two due to std::rotate limitation * Change the order with swap. * Map rebuid added --- radio/src/gui/colorlcd/zone.h | 2 +- radio/src/storage/modelslist.cpp | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/colorlcd/zone.h b/radio/src/gui/colorlcd/zone.h index 11554173d..6f184cba4 100644 --- a/radio/src/gui/colorlcd/zone.h +++ b/radio/src/gui/colorlcd/zone.h @@ -29,7 +29,7 @@ #if defined(_MSC_VER) #define OPTION_VALUE_UNSIGNED(x) { uint32_t(x) } - #define OPTION_VALUE_SIGNED(x) { uint32_t(x) } + #define OPTION_VALUE_SIGNED(x) { int32_t(x) } #define OPTION_VALUE_BOOL(x) { bool(x) } #define OPTION_VALUE_STRING(...) { *(ZoneOptionValue *)(const char *) #__VA_ARGS__ } #else diff --git a/radio/src/storage/modelslist.cpp b/radio/src/storage/modelslist.cpp index 231050ab9..ce7f94e3d 100644 --- a/radio/src/storage/modelslist.cpp +++ b/radio/src/storage/modelslist.cpp @@ -550,20 +550,24 @@ bool ModelMap::moveLabelTo(unsigned curind, unsigned newind) if (labels.at(curind) == "") return true; - LabelsVector newOrder = labels; + std::swap(labels[curind], labels[newind]); - if (curind < newind) { // Move forward - std::rotate(newOrder.rend() - curind - 1, newOrder.rend() - curind, - newOrder.rend() - newind); - } else { // Move back - std::rotate(newOrder.begin() + curind, newOrder.begin() + curind + 1, - newOrder.begin() + newind + 1); + ModelMap newmap; + newmap.labels = labels; + + for (auto &mm : modelslabels) { + uint16_t ind = mm.first; + if (ind == curind) + ind = newind; + else if (ind == newind) + ind = curind; + newmap.insert(std::make_pair(ind, mm.second)); } - // Reload the new labels order - modelslist.save(newOrder); - modelslist.clear(); - modelslist.load(); + modelslabels = newmap; + + modelslist.save(labels); + setDirty(); return false; }