diff options
author | Eike Ziller <eike.ziller@qt.io> | 2016-08-18 14:33:52 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2016-08-18 13:10:56 +0000 |
commit | 052b0337d2231b9811bbdf95ce74d29ad2dfb00b (patch) | |
tree | d5cae8dc408cb5826ddbd3a31f459f5ec36d374e /src/plugins/help/docsettingspage.cpp | |
parent | 5fcfe97e2370a4bb167e36c838f9fd8bc04730b9 (diff) | |
download | qt-creator-052b0337d2231b9811bbdf95ce74d29ad2dfb00b.tar.gz |
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 <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/plugins/help/docsettingspage.cpp')
-rw-r--r-- | src/plugins/help/docsettingspage.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
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 <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); } |