Apply download priority immediately in torrent content view

Apply the new priority after picking it via drop-down menu.

Fixes #14667, #15238.
PR #15739.

Co-authored-by: a-sum-duma <68896601+a-sum-duma@users.noreply.github.com>
Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
Chocobo1 2021-11-16 13:50:53 +08:00 committed by GitHub
parent fa1d49add5
commit b063042988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -68,7 +68,8 @@ void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index)
QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
{ {
if (index.column() != PRIORITY) return nullptr; if (index.column() != PRIORITY)
return nullptr;
if (m_properties) if (m_properties)
{ {
@ -87,16 +88,21 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
editor->addItem(tr("Normal", "Normal (priority)")); editor->addItem(tr("Normal", "Normal (priority)"));
editor->addItem(tr("High", "High (priority)")); editor->addItem(tr("High", "High (priority)"));
editor->addItem(tr("Maximum", "Maximum (priority)")); editor->addItem(tr("Maximum", "Maximum (priority)"));
connect(editor, qOverload<int>(&QComboBox::currentIndexChanged), this, [this, editor]()
{
emit const_cast<PropListDelegate *>(this)->commitData(editor);
});
return editor; return editor;
} }
void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{ {
const auto *combobox = static_cast<QComboBox *>(editor); const auto *combobox = static_cast<QComboBox *>(editor);
const int value = combobox->currentIndex();
BitTorrent::DownloadPriority prio = BitTorrent::DownloadPriority::Normal; // NORMAL BitTorrent::DownloadPriority prio = BitTorrent::DownloadPriority::Normal; // NORMAL
switch (value) switch (combobox->currentIndex())
{ {
case 0: case 0:
prio = BitTorrent::DownloadPriority::Ignored; // IGNORED prio = BitTorrent::DownloadPriority::Ignored; // IGNORED
@ -109,8 +115,14 @@ void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
break; break;
} }
model->setData(index, static_cast<int>(prio)); const int newPriority = static_cast<int>(prio);
emit filteredFilesChanged(); const int previousPriority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
if (newPriority != previousPriority)
{
model->setData(index, newPriority);
emit filteredFilesChanged();
}
} }
void PropListDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const void PropListDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const