qBittorrent
PropListDelegate Class Referencefinal

#include <proplistdelegate.h>

Inheritance diagram for PropListDelegate:
Collaboration diagram for PropListDelegate:

Public Slots

void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
 
void updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 

Signals

void filteredFilesChanged () const
 

Public Member Functions

 PropListDelegate (PropertiesWidget *properties)
 
void setEditorData (QWidget *editor, const QModelIndex &index) const override
 
QWidget * createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 

Private Attributes

PropertiesWidgetm_properties
 
ProgressBarPainter m_progressBarPainter
 

Detailed Description

Definition at line 52 of file proplistdelegate.h.

Constructor & Destructor Documentation

◆ PropListDelegate()

PropListDelegate::PropListDelegate ( PropertiesWidget properties)
explicit

Definition at line 41 of file proplistdelegate.cpp.

42  : QStyledItemDelegate {properties}
43  , m_properties {properties}
44 {
45 }
PropertiesWidget * m_properties

Member Function Documentation

◆ createEditor()

QWidget * PropListDelegate::createEditor ( QWidget *  parent,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 69 of file proplistdelegate.cpp.

70 {
71  if (index.column() != PRIORITY)
72  return nullptr;
73 
74  if (m_properties)
75  {
77  if (!torrent || !torrent->hasMetadata() || torrent->isSeed())
78  return nullptr;
79  }
80 
81  const int priority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
83  return nullptr;
84 
85  auto *editor = new QComboBox(parent);
86  editor->setFocusPolicy(Qt::StrongFocus);
87  editor->addItem(tr("Do not download", "Do not download (priority)"));
88  editor->addItem(tr("Normal", "Normal (priority)"));
89  editor->addItem(tr("High", "High (priority)"));
90  editor->addItem(tr("Maximum", "Maximum (priority)"));
91 
92  connect(editor, qOverload<int>(&QComboBox::currentIndexChanged), this, [this, editor]()
93  {
94  emit const_cast<PropListDelegate *>(this)->commitData(editor);
95  });
96 
97  return editor;
98 }
virtual bool isSeed() const =0
virtual bool hasMetadata() const =0
BitTorrent::Torrent * getCurrentTorrent() const
@ PRIORITY

References PropertiesWidget::getCurrentTorrent(), BitTorrent::Torrent::hasMetadata(), BitTorrent::Torrent::isSeed(), m_properties, BitTorrent::Mixed, PRIORITY, and TorrentContentModel::UnderlyingDataRole.

Here is the call graph for this function:

◆ filteredFilesChanged

void PropListDelegate::filteredFilesChanged ( ) const
signal

Referenced by PropertiesWidget::PropertiesWidget(), and setModelData().

Here is the caller graph for this function:

◆ paint()

void PropListDelegate::paint ( QPainter *  painter,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
override

Definition at line 133 of file proplistdelegate.cpp.

134 {
135  switch (index.column())
136  {
138  {
139  const int progress = static_cast<int>(index.data(TorrentContentModel::UnderlyingDataRole).toReal());
140  const int priority = index.sibling(index.row(), PropColumn::PRIORITY).data(TorrentContentModel::UnderlyingDataRole).toInt();
141  const bool isEnabled = static_cast<BitTorrent::DownloadPriority>(priority) != BitTorrent::DownloadPriority::Ignored;
142 
143  QStyleOptionViewItem customOption {option};
144  customOption.state.setFlag(QStyle::State_Enabled, isEnabled);
145 
146  m_progressBarPainter.paint(painter, customOption, index.data().toString(), progress);
147  }
148  break;
149  default:
150  QStyledItemDelegate::paint(painter, option, index);
151  break;
152  }
153 }
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QString &text, int progress) const
ProgressBarPainter m_progressBarPainter
@ PROGRESS

References BitTorrent::Ignored, m_progressBarPainter, ProgressBarPainter::paint(), PRIORITY, PROGRESS, and TorrentContentModel::UnderlyingDataRole.

Here is the call graph for this function:

◆ setEditorData()

void PropListDelegate::setEditorData ( QWidget *  editor,
const QModelIndex &  index 
) const
override

Definition at line 47 of file proplistdelegate.cpp.

48 {
49  auto *combobox = static_cast<QComboBox *>(editor);
50  // Set combobox index
51  const int priority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
52  switch (static_cast<BitTorrent::DownloadPriority>(priority))
53  {
55  combobox->setCurrentIndex(0);
56  break;
58  combobox->setCurrentIndex(2);
59  break;
61  combobox->setCurrentIndex(3);
62  break;
63  default:
64  combobox->setCurrentIndex(1);
65  break;
66  }
67 }

References BitTorrent::High, BitTorrent::Ignored, BitTorrent::Maximum, and TorrentContentModel::UnderlyingDataRole.

◆ setModelData

void PropListDelegate::setModelData ( QWidget *  editor,
QAbstractItemModel *  model,
const QModelIndex &  index 
) const
overrideslot

Definition at line 100 of file proplistdelegate.cpp.

101 {
102  const auto *combobox = static_cast<QComboBox *>(editor);
103 
105  switch (combobox->currentIndex())
106  {
107  case 0:
108  prio = BitTorrent::DownloadPriority::Ignored; // IGNORED
109  break;
110  case 2:
111  prio = BitTorrent::DownloadPriority::High; // HIGH
112  break;
113  case 3:
115  break;
116  }
117 
118  const int newPriority = static_cast<int>(prio);
119  const int previousPriority = index.data(TorrentContentModel::UnderlyingDataRole).toInt();
120 
121  if (newPriority != previousPriority)
122  {
123  model->setData(index, newPriority);
124  emit filteredFilesChanged();
125  }
126 }
void filteredFilesChanged() const

References filteredFilesChanged(), BitTorrent::High, BitTorrent::Ignored, BitTorrent::Maximum, BitTorrent::Normal, and TorrentContentModel::UnderlyingDataRole.

◆ updateEditorGeometry

void PropListDelegate::updateEditorGeometry ( QWidget *  editor,
const QStyleOptionViewItem &  option,
const QModelIndex &  index 
) const
overrideslot

Definition at line 128 of file proplistdelegate.cpp.

129 {
130  editor->setGeometry(option.rect);
131 }

Member Data Documentation

◆ m_progressBarPainter

ProgressBarPainter PropListDelegate::m_progressBarPainter
private

Definition at line 73 of file proplistdelegate.h.

Referenced by paint().

◆ m_properties

PropertiesWidget* PropListDelegate::m_properties
private

Definition at line 72 of file proplistdelegate.h.

Referenced by createEditor().


The documentation for this class was generated from the following files: