Commit 052b0337 authored by Eike Ziller's avatar Eike Ziller

Help settings: Fix crash when removing multiple documentation sets

If they were not selected in the order they appear in the list.
The order of the items in the selection are basically in arbitrary
order, so we need to sort them by row to make sure that we remove them
from bottom to top.

Task-number: QTCREATORBUG-16747
Change-Id: If9be9bb4cd1da71e03946bdd2096034093e3cf14
Reviewed-by: Friedemann Kleint's avatarFriedemann Kleint <Friedemann.Kleint@qt.io>
parent 5fcfe97e
......@@ -27,6 +27,7 @@
#include "helpconstants.h"
#include <coreplugin/helpmanager.h>
#include <utils/algorithm.h>
#include <QFileDialog>
#include <QKeyEvent>
......@@ -287,8 +288,12 @@ void DocSettingsPage::removeDocumentation(const QList<QModelIndex> &items)
if (items.isEmpty())
return;
for (int i = items.size() - 1; i >= 0; --i) {
const int row = items.at(i).row();
QList<QModelIndex> itemsByDecreasingRow = items;
Utils::sort(itemsByDecreasingRow, [](const QModelIndex &i1, const QModelIndex &i2) {
return i1.row() > i2.row();
});
foreach (const QModelIndex &item, itemsByDecreasingRow) {
const int row = item.row();
const QString nameSpace = m_model->entryAt(row).nameSpace;
m_filesToRegister.remove(nameSpace);
......@@ -298,7 +303,7 @@ void DocSettingsPage::removeDocumentation(const QList<QModelIndex> &items)
m_model->removeAt(row);
}
const int newlySelectedRow = qMax(items.first().row() - 1, 0);
const int newlySelectedRow = qMax(itemsByDecreasingRow.last().row() - 1, 0);
const QModelIndex index = m_proxyModel->mapFromSource(m_model->index(newlySelectedRow));
m_ui.docsListView->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
}
......
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