mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 10:46:04 +03:00
Apply bulk changes to correct content widget items
PR #21006. Closes #21001.
This commit is contained in:
parent
bd01b7c4df
commit
418edc7471
1 changed files with 21 additions and 8 deletions
|
@ -56,6 +56,19 @@
|
||||||
#include "gui/macutilities.h"
|
#include "gui/macutilities.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
QList<QPersistentModelIndex> toPersistentIndexes(const QModelIndexList &indexes)
|
||||||
|
{
|
||||||
|
QList<QPersistentModelIndex> persistentIndexes;
|
||||||
|
persistentIndexes.reserve(indexes.size());
|
||||||
|
for (const QModelIndex &index : indexes)
|
||||||
|
persistentIndexes.emplaceBack(index);
|
||||||
|
|
||||||
|
return persistentIndexes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TorrentContentWidget::TorrentContentWidget(QWidget *parent)
|
TorrentContentWidget::TorrentContentWidget(QWidget *parent)
|
||||||
: QTreeView(parent)
|
: QTreeView(parent)
|
||||||
{
|
{
|
||||||
|
@ -229,9 +242,9 @@ void TorrentContentWidget::keyPressEvent(QKeyEvent *event)
|
||||||
|
|
||||||
const Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked)
|
const Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked)
|
||||||
? Qt::Unchecked : Qt::Checked;
|
? Qt::Unchecked : Qt::Checked;
|
||||||
const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);
|
const QList<QPersistentModelIndex> selection = toPersistentIndexes(selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME));
|
||||||
|
|
||||||
for (const QModelIndex &index : selection)
|
for (const QPersistentModelIndex &index : selection)
|
||||||
model()->setData(index, state, Qt::CheckStateRole);
|
model()->setData(index, state, Qt::CheckStateRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,10 +271,10 @@ void TorrentContentWidget::renameSelectedFile()
|
||||||
|
|
||||||
void TorrentContentWidget::applyPriorities(const BitTorrent::DownloadPriority priority)
|
void TorrentContentWidget::applyPriorities(const BitTorrent::DownloadPriority priority)
|
||||||
{
|
{
|
||||||
const QModelIndexList selectedRows = selectionModel()->selectedRows(0);
|
const QList<QPersistentModelIndex> selectedRows = toPersistentIndexes(selectionModel()->selectedRows(Priority));
|
||||||
for (const QModelIndex &index : selectedRows)
|
for (const QPersistentModelIndex &index : selectedRows)
|
||||||
{
|
{
|
||||||
model()->setData(index.sibling(index.row(), Priority), static_cast<int>(priority));
|
model()->setData(index, static_cast<int>(priority));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +284,7 @@ void TorrentContentWidget::applyPrioritiesByOrder()
|
||||||
// a download priority that will apply to each item. The number of groups depends on how
|
// a download priority that will apply to each item. The number of groups depends on how
|
||||||
// many "download priority" are available to be assigned
|
// many "download priority" are available to be assigned
|
||||||
|
|
||||||
const QModelIndexList selectedRows = selectionModel()->selectedRows(0);
|
const QList<QPersistentModelIndex> selectedRows = toPersistentIndexes(selectionModel()->selectedRows(Priority));
|
||||||
|
|
||||||
const qsizetype priorityGroups = 3;
|
const qsizetype priorityGroups = 3;
|
||||||
const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length() / priorityGroups), 1);
|
const auto priorityGroupSize = std::max<qsizetype>((selectedRows.length() / priorityGroups), 1);
|
||||||
|
@ -293,8 +306,8 @@ void TorrentContentWidget::applyPrioritiesByOrder()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QModelIndex &index = selectedRows[i];
|
const QPersistentModelIndex &index = selectedRows[i];
|
||||||
model()->setData(index.sibling(index.row(), Priority), static_cast<int>(priority));
|
model()->setData(index, static_cast<int>(priority));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue