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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user