Skip to content

Commit 418edc7

Browse files
committed
Apply bulk changes to correct content widget items
PR qbittorrent#21006. Closes qbittorrent#21001.
1 parent bd01b7c commit 418edc7

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/gui/torrentcontentwidget.cpp

+21-8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@
5656
#include "gui/macutilities.h"
5757
#endif
5858

59+
namespace
60+
{
61+
QList<QPersistentModelIndex> toPersistentIndexes(const QModelIndexList &indexes)
62+
{
63+
QList<QPersistentModelIndex> persistentIndexes;
64+
persistentIndexes.reserve(indexes.size());
65+
for (const QModelIndex &index : indexes)
66+
persistentIndexes.emplaceBack(index);
67+
68+
return persistentIndexes;
69+
}
70+
}
71+
5972
TorrentContentWidget::TorrentContentWidget(QWidget *parent)
6073
: QTreeView(parent)
6174
{
@@ -229,9 +242,9 @@ void TorrentContentWidget::keyPressEvent(QKeyEvent *event)
229242

230243
const Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked)
231244
? Qt::Unchecked : Qt::Checked;
232-
const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);
245+
const QList<QPersistentModelIndex> selection = toPersistentIndexes(selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME));
233246

234-
for (const QModelIndex &index : selection)
247+
for (const QPersistentModelIndex &index : selection)
235248
model()->setData(index, state, Qt::CheckStateRole);
236249
}
237250

@@ -258,10 +271,10 @@ void TorrentContentWidget::renameSelectedFile()
258271

259272
void TorrentContentWidget::applyPriorities(const BitTorrent::DownloadPriority priority)
260273
{
261-
const QModelIndexList selectedRows = selectionModel()->selectedRows(0);
262-
for (const QModelIndex &index : selectedRows)
274+
const QList<QPersistentModelIndex> selectedRows = toPersistentIndexes(selectionModel()->selectedRows(Priority));
275+
for (const QPersistentModelIndex &index : selectedRows)
263276
{
264-
model()->setData(index.sibling(index.row(), Priority), static_cast<int>(priority));
277+
model()->setData(index, static_cast<int>(priority));
265278
}
266279
}
267280

@@ -271,7 +284,7 @@ void TorrentContentWidget::applyPrioritiesByOrder()
271284
// a download priority that will apply to each item. The number of groups depends on how
272285
// many "download priority" are available to be assigned
273286

274-
const QModelIndexList selectedRows = selectionModel()->selectedRows(0);
287+
const QList<QPersistentModelIndex> selectedRows = toPersistentIndexes(selectionModel()->selectedRows(Priority));
275288

276289
const qsizetype priorityGroups = 3;
277290
const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length() / priorityGroups), 1);
@@ -293,8 +306,8 @@ void TorrentContentWidget::applyPrioritiesByOrder()
293306
break;
294307
}
295308

296-
const QModelIndex &index = selectedRows[i];
297-
model()->setData(index.sibling(index.row(), Priority), static_cast<int>(priority));
309+
const QPersistentModelIndex &index = selectedRows[i];
310+
model()->setData(index, static_cast<int>(priority));
298311
}
299312
}
300313

0 commit comments

Comments
 (0)