GUI index config: trying to delete a custom subtree could delete the whole list (depending on qt version)... Closes issue #77

This commit is contained in:
Jean-Francois Dockes 2012-02-03 18:22:27 +01:00
parent 773a232f22
commit e96579568a

View File

@ -45,7 +45,9 @@
#include "guiutils.h" #include "guiutils.h"
#include <list> #include <list>
#include <vector>
using std::list; using std::list;
using std::vector;
namespace confgui { namespace confgui {
@ -380,19 +382,30 @@ void ConfParamSLW::listToConf()
void ConfParamSLW::deleteSelected() void ConfParamSLW::deleteSelected()
{ {
bool didone; // We used to repeatedly go through the list and delete the first
do { // found selected item (then restart from the beginning). But it
didone = false; // seems (probably depends on the qt version), that, when deleting
for (int i = 0; i < m_lb->count(); i++) { // a selected item, qt will keep the selection active at the same
if (m_lb->item(i)->isSelected()) { // index (now containing the next item), so that we'd end up
emit entryDeleted(m_lb->item(i)->text()); // deleting the whole list.
QListWidgetItem *item = m_lb->takeItem(i); //
delete item; // Instead, we now build a list of indices, and delete it starting
didone = true; // from the top so as not to invalidate lower indices
break;
} vector<int> idxes;
for (int i = 0; i < m_lb->count(); i++) {
if (m_lb->item(i)->isSelected()) {
idxes.push_back(i);
} }
} while (didone); }
for (vector<int>::reverse_iterator it = idxes.rbegin();
it != idxes.rend(); it++) {
LOGDEB0(("deleteSelected: %d was selected\n", *it));
QListWidgetItem *item = m_lb->takeItem(*it);
emit entryDeleted(item->text());
delete item;
}
listToConf(); listToConf();
} }