Enable Combobox editor for the "Mixed" file download priority

Fixes #1544.
PR #16522.
This commit is contained in:
Aleksandr Cupacenko 2022-02-26 06:53:41 +02:00 committed by GitHub
parent 2652c73a4f
commit 2e08ae82b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -60,6 +60,9 @@ void PropListDelegate::setEditorData(QWidget *editor, const QModelIndex &index)
case BitTorrent::DownloadPriority::Maximum:
combobox->setCurrentIndex(3);
break;
case BitTorrent::DownloadPriority::Mixed:
combobox->setCurrentIndex(4);
break;
default:
combobox->setCurrentIndex(1);
break;
@ -78,10 +81,6 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
return nullptr;
}
const int priority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
if (static_cast<BitTorrent::DownloadPriority>(priority) == BitTorrent::DownloadPriority::Mixed)
return nullptr;
auto *editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("Do not download", "Do not download (priority)"));
@ -89,6 +88,13 @@ QWidget *PropListDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
editor->addItem(tr("High", "High (priority)"));
editor->addItem(tr("Maximum", "Maximum (priority)"));
// add Mixed priority item to the new combobox only for those items with Mixed priority
const auto priority = static_cast<BitTorrent::DownloadPriority>(index.data(TorrentContentModel::UnderlyingDataRole).toInt());
if (priority == BitTorrent::DownloadPriority::Mixed)
{
editor->addItem(tr("Mixed", "Mixed (priorities)"));
}
connect(editor, qOverload<int>(&QComboBox::currentIndexChanged), this, [this, editor]()
{
emit const_cast<PropListDelegate *>(this)->commitData(editor);
@ -113,6 +119,9 @@ void PropListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
case 3:
prio = BitTorrent::DownloadPriority::Maximum; // MAX
break;
case 4:
prio = BitTorrent::DownloadPriority::Mixed; // MIXED
break;
}
const int newPriority = static_cast<int>(prio);