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
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
#define OPTION_VALUE_UNSIGNED(x) { uint32_t(x) }
|
#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_BOOL(x) { bool(x) }
|
||||||
#define OPTION_VALUE_STRING(...) { *(ZoneOptionValue *)(const char *) #__VA_ARGS__ }
|
#define OPTION_VALUE_STRING(...) { *(ZoneOptionValue *)(const char *) #__VA_ARGS__ }
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -550,20 +550,24 @@ bool ModelMap::moveLabelTo(unsigned curind, unsigned newind)
|
|||||||
|
|
||||||
if (labels.at(curind) == "") return true;
|
if (labels.at(curind) == "") return true;
|
||||||
|
|
||||||
LabelsVector newOrder = labels;
|
std::swap(labels[curind], labels[newind]);
|
||||||
|
|
||||||
if (curind < newind) { // Move forward
|
ModelMap newmap;
|
||||||
std::rotate(newOrder.rend() - curind - 1, newOrder.rend() - curind,
|
newmap.labels = labels;
|
||||||
newOrder.rend() - newind);
|
|
||||||
} else { // Move back
|
for (auto &mm : modelslabels) {
|
||||||
std::rotate(newOrder.begin() + curind, newOrder.begin() + curind + 1,
|
uint16_t ind = mm.first;
|
||||||
newOrder.begin() + newind + 1);
|
if (ind == curind)
|
||||||
|
ind = newind;
|
||||||
|
else if (ind == newind)
|
||||||
|
ind = curind;
|
||||||
|
newmap.insert(std::make_pair(ind, mm.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reload the new labels order
|
modelslabels = newmap;
|
||||||
modelslist.save(newOrder);
|
|
||||||
modelslist.clear();
|
modelslist.save(labels);
|
||||||
modelslist.load();
|
setDirty();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user