Commit 03e76337 authored by Daniel Teske's avatar Daniel Teske

AndroidExtraLibraryListModel: Fix crash on removing libs

Steps to reproduce the crash, start with the list a b a c, select the
second a and the c. Click on remove. The removeEntries will find that it
can remove two consecutive entries in one beginRemoveRows/endRemoveRows,
but will wrongly remove them starting at the first a.

The fix is too simply order the modelindexes in descendeding order such
that removing entries does not modify the rows.

Change-Id: I4be349f4bab8137075da0d8dfcef24f10dc25f92
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent 872bfb70
......@@ -102,27 +102,29 @@ void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
endInsertRows();
}
void AndroidExtraLibraryListModel::removeEntries(const QModelIndexList &list)
bool greaterModelIndexByRow(const QModelIndex &a, const QModelIndex &b)
{
return a.row() > b.row();
}
void AndroidExtraLibraryListModel::removeEntries(QModelIndexList list)
{
if (list.isEmpty() || m_project->rootQt4ProjectNode()->projectType() != Qt4ProjectManager::ApplicationTemplate)
return;
QStringList oldList = m_entries;
std::sort(list.begin(), list.end(), greaterModelIndexByRow);
int i = 0;
while (i < list.size()) {
int firstRow = list.at(i++).row();
int lastRow = firstRow;
while (i < list.size() && list.at(i).row() - lastRow <= 1 && list.at(i).row() > firstRow)
lastRow = list.at(i++).row();
int lastRow = list.at(i++).row();
int firstRow = lastRow;
while (i < list.size() && firstRow - list.at(i).row() <= 1)
firstRow = list.at(i++).row();
int first = m_entries.indexOf(oldList.at(firstRow));
beginRemoveRows(QModelIndex(), firstRow, lastRow);
int count = lastRow - firstRow + 1;
Q_ASSERT(count > 0);
Q_ASSERT(oldList.at(lastRow) == m_entries.at(first + count - 1));
beginRemoveRows(QModelIndex(), first, first + count - 1);
while (count-- > 0)
m_entries.removeAt(first);
m_entries.removeAt(firstRow);
endRemoveRows();
}
......
......@@ -51,7 +51,7 @@ public:
int columnCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
void removeEntries(const QModelIndexList &list);
void removeEntries(QModelIndexList list);
void addEntries(const QStringList &list);
private slots:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment