forked from qt-creator/qt-creator
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: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
@@ -102,27 +102,29 @@ void AndroidExtraLibraryListModel::addEntries(const QStringList &list)
|
|||||||
endInsertRows();
|
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)
|
if (list.isEmpty() || m_project->rootQt4ProjectNode()->projectType() != Qt4ProjectManager::ApplicationTemplate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QStringList oldList = m_entries;
|
std::sort(list.begin(), list.end(), greaterModelIndexByRow);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < list.size()) {
|
while (i < list.size()) {
|
||||||
int firstRow = list.at(i++).row();
|
int lastRow = list.at(i++).row();
|
||||||
int lastRow = firstRow;
|
int firstRow = lastRow;
|
||||||
while (i < list.size() && list.at(i).row() - lastRow <= 1 && list.at(i).row() > firstRow)
|
while (i < list.size() && firstRow - list.at(i).row() <= 1)
|
||||||
lastRow = list.at(i++).row();
|
firstRow = list.at(i++).row();
|
||||||
|
|
||||||
int first = m_entries.indexOf(oldList.at(firstRow));
|
beginRemoveRows(QModelIndex(), firstRow, lastRow);
|
||||||
int count = lastRow - firstRow + 1;
|
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)
|
while (count-- > 0)
|
||||||
m_entries.removeAt(first);
|
m_entries.removeAt(firstRow);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
int columnCount(const QModelIndex &parent) const;
|
int columnCount(const QModelIndex &parent) const;
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
|
||||||
void removeEntries(const QModelIndexList &list);
|
void removeEntries(QModelIndexList list);
|
||||||
void addEntries(const QStringList &list);
|
void addEntries(const QStringList &list);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user