qBittorrent
TorrentContentModelItem Class Referenceabstract

#include <torrentcontentmodelitem.h>

Inheritance diagram for TorrentContentModelItem:
Collaboration diagram for TorrentContentModelItem:

Public Types

enum  TreeItemColumns {
  COL_NAME , COL_SIZE , COL_PROGRESS , COL_PRIO ,
  COL_REMAINING , COL_AVAILABILITY , NB_COL
}
 
enum  ItemType { FileType , FolderType }
 

Public Member Functions

 TorrentContentModelItem (TorrentContentModelFolder *parent)
 
virtual ~TorrentContentModelItem ()
 
bool isRootItem () const
 
TorrentContentModelFolderparent () const
 
virtual ItemType itemType () const =0
 
QString name () const
 
void setName (const QString &name)
 
qulonglong size () const
 
qreal progress () const
 
qulonglong remaining () const
 
qreal availability () const
 
BitTorrent::DownloadPriority priority () const
 
virtual void setPriority (BitTorrent::DownloadPriority newPriority, bool updateParent=true)=0
 
int columnCount () const
 
QString displayData (int column) const
 
QVariant underlyingData (int column) const
 
int row () const
 

Protected Attributes

TorrentContentModelFolderm_parentItem
 
QVector< QString > m_itemData
 
QString m_name
 
qulonglong m_size
 
qulonglong m_remaining
 
BitTorrent::DownloadPriority m_priority
 
qreal m_progress
 
qreal m_availability
 

Detailed Description

Definition at line 40 of file torrentcontentmodelitem.h.

Member Enumeration Documentation

◆ ItemType

Enumerator
FileType 
FolderType 

Definition at line 56 of file torrentcontentmodelitem.h.

◆ TreeItemColumns

Constructor & Destructor Documentation

◆ TorrentContentModelItem()

TorrentContentModelItem::TorrentContentModelItem ( TorrentContentModelFolder parent)
explicit

◆ ~TorrentContentModelItem()

TorrentContentModelItem::~TorrentContentModelItem ( )
virtualdefault

Member Function Documentation

◆ availability()

qreal TorrentContentModelItem::availability ( ) const

Definition at line 87 of file torrentcontentmodelitem.cpp.

88 {
89  Q_ASSERT(!isRootItem());
90 
91  return (m_size > 0) ? m_availability : 0;
92 }

References isRootItem(), m_availability, and m_size.

Referenced by displayData(), TorrentContentModelFolder::recalculateAvailability(), TorrentContentModelFile::setAvailability(), and underlyingData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ columnCount()

int TorrentContentModelItem::columnCount ( ) const

Definition at line 100 of file torrentcontentmodelitem.cpp.

101 {
102  return NB_COL;
103 }

References NB_COL.

Referenced by TorrentContentModel::columnCount().

Here is the caller graph for this function:

◆ displayData()

QString TorrentContentModelItem::displayData ( int  column) const

Definition at line 105 of file torrentcontentmodelitem.cpp.

106 {
107  if (isRootItem())
108  return m_itemData.value(column);
109 
110  switch (column)
111  {
112  case COL_NAME:
113  return m_name;
114  case COL_PRIO:
115  switch (m_priority)
116  {
118  return tr("Mixed", "Mixed (priorities");
120  return tr("Not downloaded");
122  return tr("High", "High (priority)");
124  return tr("Maximum", "Maximum (priority)");
125  default:
126  return tr("Normal", "Normal (priority)");
127  }
128  case COL_PROGRESS:
129  return (m_progress >= 1)
130  ? QString::fromLatin1("100%")
131  : (Utils::String::fromDouble((m_progress * 100), 1) + QLatin1Char('%'));
132  case COL_SIZE:
134  case COL_REMAINING:
136  case COL_AVAILABILITY:
137  {
138  const qreal avail = availability();
139  if (avail < 0)
140  return tr("N/A");
141 
142  const QString value = (avail >= 1)
143  ? QString::fromLatin1("100")
144  : Utils::String::fromDouble((avail * 100), 1);
145  return (value + C_THIN_SPACE + QLatin1Char('%'));
146  }
147  default:
148  Q_ASSERT(false);
149  return {};
150  }
151 }
QString friendlyUnit(qint64 bytes, bool isSpeed=false)
Definition: misc.cpp:261
QString fromDouble(double n, int precision)
Definition: string.cpp:44
T value(const QString &key, const T &defaultValue={})
Definition: preferences.cpp:64
const char C_THIN_SPACE[]

References availability(), C_THIN_SPACE, COL_AVAILABILITY, COL_NAME, COL_PRIO, COL_PROGRESS, COL_REMAINING, COL_SIZE, Utils::Misc::friendlyUnit(), Utils::String::fromDouble(), BitTorrent::High, BitTorrent::Ignored, isRootItem(), m_itemData, m_name, m_priority, m_progress, m_size, BitTorrent::Maximum, BitTorrent::Mixed, remaining(), and anonymous_namespace{preferences.cpp}::value().

Referenced by TorrentContentModel::headerData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isRootItem()

◆ itemType()

◆ name()

QString TorrentContentModelItem::name ( ) const

Definition at line 55 of file torrentcontentmodelitem.cpp.

56 {
57  Q_ASSERT(!isRootItem());
58  return m_name;
59 }

References isRootItem(), and m_name.

Referenced by TorrentContentModelFolder::childFolderWithName(), setName(), and TorrentContentModelFolder::TorrentContentModelFolder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parent()

TorrentContentModelFolder * TorrentContentModelItem::parent ( ) const

Definition at line 185 of file torrentcontentmodelitem.cpp.

186 {
187  return m_parentItem;
188 }

References m_parentItem.

Referenced by TorrentContentModel::parent(), TorrentContentModelFile::TorrentContentModelFile(), and TorrentContentModelFolder::TorrentContentModelFolder().

Here is the caller graph for this function:

◆ priority()

BitTorrent::DownloadPriority TorrentContentModelItem::priority ( ) const

Definition at line 94 of file torrentcontentmodelitem.cpp.

95 {
96  Q_ASSERT(!isRootItem());
97  return m_priority;
98 }

References isRootItem(), and m_priority.

Referenced by TorrentContentModelFolder::recalculateAvailability(), TorrentContentModelFolder::recalculateProgress(), and TorrentContentModel::selectAll().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress()

qreal TorrentContentModelItem::progress ( ) const

Definition at line 74 of file torrentcontentmodelitem.cpp.

75 {
76  Q_ASSERT(!isRootItem());
77 
78  return (m_size > 0) ? m_progress : 1;
79 }

References isRootItem(), m_progress, and m_size.

Referenced by TorrentContentModelFolder::recalculateProgress(), TorrentContentModelFile::setProgress(), and underlyingData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remaining()

qulonglong TorrentContentModelItem::remaining ( ) const

Definition at line 81 of file torrentcontentmodelitem.cpp.

82 {
83  Q_ASSERT(!isRootItem());
85 }

References BitTorrent::Ignored, isRootItem(), m_priority, and m_remaining.

Referenced by displayData(), TorrentContentModelFolder::recalculateProgress(), and underlyingData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ row()

int TorrentContentModelItem::row ( ) const

Definition at line 178 of file torrentcontentmodelitem.cpp.

179 {
180  if (m_parentItem)
181  return m_parentItem->children().indexOf(const_cast<TorrentContentModelItem *>(this));
182  return 0;
183 }
const QVector< TorrentContentModelItem * > & children() const

References TorrentContentModelFolder::children(), and m_parentItem.

Referenced by TorrentContentModelFolder::child(), and TorrentContentModel::parent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setName()

void TorrentContentModelItem::setName ( const QString &  name)

Definition at line 61 of file torrentcontentmodelitem.cpp.

62 {
63  Q_ASSERT(!isRootItem());
64  m_name = name;
65 }

References isRootItem(), m_name, and name().

Here is the call graph for this function:

◆ setPriority()

virtual void TorrentContentModelItem::setPriority ( BitTorrent::DownloadPriority  newPriority,
bool  updateParent = true 
)
pure virtual

◆ size()

qulonglong TorrentContentModelItem::size ( ) const

Definition at line 67 of file torrentcontentmodelitem.cpp.

68 {
69  Q_ASSERT(!isRootItem());
70 
71  return m_size;
72 }

References isRootItem(), and m_size.

Referenced by TorrentContentModelFolder::appendChild(), TorrentContentModelFolder::recalculateAvailability(), and TorrentContentModelFolder::recalculateProgress().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ underlyingData()

QVariant TorrentContentModelItem::underlyingData ( int  column) const

Definition at line 153 of file torrentcontentmodelitem.cpp.

154 {
155  if (isRootItem())
156  return m_itemData.value(column);
157 
158  switch (column)
159  {
160  case COL_NAME:
161  return m_name;
162  case COL_PRIO:
163  return static_cast<int>(m_priority);
164  case COL_PROGRESS:
165  return progress() * 100;
166  case COL_SIZE:
167  return m_size;
168  case COL_REMAINING:
169  return remaining();
170  case COL_AVAILABILITY:
171  return availability();
172  default:
173  Q_ASSERT(false);
174  return {};
175  }
176 }

References availability(), COL_AVAILABILITY, COL_NAME, COL_PRIO, COL_PROGRESS, COL_REMAINING, COL_SIZE, isRootItem(), m_itemData, m_name, m_priority, m_size, progress(), and remaining().

Here is the call graph for this function:

Member Data Documentation

◆ m_availability

qreal TorrentContentModelItem::m_availability
protected

◆ m_itemData

QVector<QString> TorrentContentModelItem::m_itemData
protected

◆ m_name

◆ m_parentItem

◆ m_priority

◆ m_progress

qreal TorrentContentModelItem::m_progress
protected

◆ m_remaining

qulonglong TorrentContentModelItem::m_remaining
protected

◆ m_size


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