56
56
#include " gui/macutilities.h"
57
57
#endif
58
58
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
+
59
72
TorrentContentWidget::TorrentContentWidget (QWidget *parent)
60
73
: QTreeView(parent)
61
74
{
@@ -229,9 +242,9 @@ void TorrentContentWidget::keyPressEvent(QKeyEvent *event)
229
242
230
243
const Qt::CheckState state = (static_cast <Qt::CheckState>(value.toInt ()) == Qt::Checked)
231
244
? Qt::Unchecked : Qt::Checked;
232
- const QModelIndexList selection = selectionModel ()->selectedRows (TorrentContentModelItem::COL_NAME);
245
+ const QList<QPersistentModelIndex> selection = toPersistentIndexes ( selectionModel ()->selectedRows (TorrentContentModelItem::COL_NAME) );
233
246
234
- for (const QModelIndex &index : selection)
247
+ for (const QPersistentModelIndex &index : selection)
235
248
model ()->setData (index , state, Qt::CheckStateRole);
236
249
}
237
250
@@ -258,10 +271,10 @@ void TorrentContentWidget::renameSelectedFile()
258
271
259
272
void TorrentContentWidget::applyPriorities (const BitTorrent::DownloadPriority priority)
260
273
{
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)
263
276
{
264
- model ()->setData (index . sibling ( index . row (), Priority) , static_cast <int >(priority));
277
+ model ()->setData (index , static_cast <int >(priority));
265
278
}
266
279
}
267
280
@@ -271,7 +284,7 @@ void TorrentContentWidget::applyPrioritiesByOrder()
271
284
// a download priority that will apply to each item. The number of groups depends on how
272
285
// many "download priority" are available to be assigned
273
286
274
- const QModelIndexList selectedRows = selectionModel ()->selectedRows (0 );
287
+ const QList<QPersistentModelIndex> selectedRows = toPersistentIndexes ( selectionModel ()->selectedRows (Priority) );
275
288
276
289
const qsizetype priorityGroups = 3 ;
277
290
const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length () / priorityGroups), 1 );
@@ -293,8 +306,8 @@ void TorrentContentWidget::applyPrioritiesByOrder()
293
306
break ;
294
307
}
295
308
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));
298
311
}
299
312
}
300
313
0 commit comments