From 2e08ae82b1903e07c4f630e2033b09a806670e11 Mon Sep 17 00:00:00 2001 From: Aleksandr Cupacenko Date: Sat, 26 Feb 2022 06:53:41 +0200 Subject: [PATCH] Enable Combobox editor for the "Mixed" file download priority Fixes #1544. PR #16522. --- src/gui/properties/proplistdelegate.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index 41e4adc8f..f96efdccd 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -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(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(index.data(TorrentContentModel::UnderlyingDataRole).toInt()); + if (priority == BitTorrent::DownloadPriority::Mixed) + { + editor->addItem(tr("Mixed", "Mixed (priorities)")); + } + connect(editor, qOverload(&QComboBox::currentIndexChanged), this, [this, editor]() { emit const_cast(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(prio);