From 052b0337d2231b9811bbdf95ce74d29ad2dfb00b Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 18 Aug 2016 14:33:52 +0200 Subject: 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 --- src/plugins/help/docsettingspage.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/plugins/help/docsettingspage.cpp') diff --git a/src/plugins/help/docsettingspage.cpp b/src/plugins/help/docsettingspage.cpp index fcfe96ac4b..cedf36ac1b 100644 --- a/src/plugins/help/docsettingspage.cpp +++ b/src/plugins/help/docsettingspage.cpp @@ -27,6 +27,7 @@ #include "helpconstants.h" #include +#include #include #include @@ -287,8 +288,12 @@ void DocSettingsPage::removeDocumentation(const QList &items) if (items.isEmpty()) return; - for (int i = items.size() - 1; i >= 0; --i) { - const int row = items.at(i).row(); + QList 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 &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); } -- cgit v1.2.1