summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtreewidget.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2019-09-12 15:22:24 +0200
committerAndy Shaw <andy.shaw@qt.io>2019-10-03 12:51:53 +0200
commit5aa13ea144cff4dbadf12c08b7aa49646347e186 (patch)
tree9521b1db1a3ac867a63bb9def8e783ac55a2fa78 /src/widgets/itemviews/qtreewidget.cpp
parent7d73d4b9a93b3132c1a24aa3ae77f0a307e821fd (diff)
QTreeWidget: Don't assume the selected indexes include the first column
If the first column is hidden in a QTreeWidget then when doing a drag then the selected indexes will not include any that have a column of 0. Therefore it has to account for this use std::unique to ensure that there is only one instance of the selected items represented by the selected indexes. Fixes: QTBUG-35511 Change-Id: I39dff596959f30db7378ff946735ee2866778524 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/itemviews/qtreewidget.cpp')
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index d2dc91b18c..be7ddd8b30 100644
--- a/src/widgets/itemviews/qtreewidget.cpp
+++ b/src/widgets/itemviews/qtreewidget.cpp
@@ -748,11 +748,14 @@ QMimeData *QTreeModel::internalMimeData() const
QMimeData *QTreeModel::mimeData(const QModelIndexList &indexes) const
{
- QList<QTreeWidgetItem*> items;
- for (const auto &index : indexes) {
- if (index.column() == 0) // only one item per row
- items << item(index);
- }
+ QList<QTreeWidgetItem *> items;
+ std::transform(indexes.begin(), indexes.end(), std::back_inserter(items),
+ [this](const QModelIndex &idx) -> QTreeWidgetItem * { return item(idx); });
+
+ // Ensure we only have one item as an item may have more than
+ // one index selected if there is more than one column
+ std::sort(items.begin(), items.end());
+ items.erase(std::unique(items.begin(), items.end()), items.end());
// cachedIndexes is a little hack to avoid copying from QModelIndexList to
// QList<QTreeWidgetItem*> and back again in the view