mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-26 19:26:59 +03:00
Add availability column to torrent content model
This commit is contained in:
parent
114c9a8421
commit
d5af8722a6
8 changed files with 68 additions and 0 deletions
|
@ -76,6 +76,7 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
|
|||
m_filesIndex[i]->setProgress(fp[i]);
|
||||
// Update folders progress in the tree
|
||||
m_rootItem->recalculateProgress();
|
||||
m_rootItem->recalculateAvailability();
|
||||
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||
}
|
||||
|
||||
|
@ -92,6 +93,20 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
|||
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||
}
|
||||
|
||||
void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
|
||||
{
|
||||
Q_ASSERT(m_filesIndex.size() == fa.size());
|
||||
// XXX: Why is this necessary?
|
||||
if (m_filesIndex.size() != fa.size()) return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
for (int i = 0; i < fa.size(); ++i)
|
||||
m_filesIndex[i]->setAvailability(fa[i]);
|
||||
// Update folders progress in the tree
|
||||
m_rootItem->recalculateProgress();
|
||||
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||
}
|
||||
|
||||
QVector<int> TorrentContentModel::getFilePriorities() const
|
||||
{
|
||||
QVector<int> prio;
|
||||
|
@ -134,6 +149,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
|||
item->setPriority(prio::NORMAL);
|
||||
// Update folders progress in the tree
|
||||
m_rootItem->recalculateProgress();
|
||||
m_rootItem->recalculateAvailability();
|
||||
emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1));
|
||||
emit filteredFilesChanged();
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ public:
|
|||
|
||||
void updateFilesProgress(const QVector<qreal> &fp);
|
||||
void updateFilesPriorities(const QVector<int> &fprio);
|
||||
void updateFilesAvailability(const QVector<qreal> &fa);
|
||||
QVector<int> getFilePriorities() const;
|
||||
bool allFiltered() const;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
|
|
|
@ -73,6 +73,12 @@ void TorrentContentModelFile::setProgress(qreal progress)
|
|||
Q_ASSERT(m_progress <= 1.);
|
||||
}
|
||||
|
||||
void TorrentContentModelFile::setAvailability(qreal availability)
|
||||
{
|
||||
m_availability = availability;
|
||||
Q_ASSERT(m_availability <= 1.);
|
||||
}
|
||||
|
||||
TorrentContentModelItem::ItemType TorrentContentModelFile::itemType() const
|
||||
{
|
||||
return FileType;
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
int fileIndex() const;
|
||||
void setPriority(int newPriority, bool updateParent = true) override;
|
||||
void setProgress(qreal progress);
|
||||
void setAvailability(qreal availability);
|
||||
ItemType itemType() const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -159,6 +159,34 @@ void TorrentContentModelFolder::recalculateProgress()
|
|||
}
|
||||
}
|
||||
|
||||
void TorrentContentModelFolder::recalculateAvailability()
|
||||
{
|
||||
qreal tAvailability = 0;
|
||||
qulonglong tSize = 0;
|
||||
bool foundAnyData = false;
|
||||
foreach (TorrentContentModelItem* child, m_childItems) {
|
||||
if (child->priority() == prio::IGNORED)
|
||||
continue;
|
||||
|
||||
if (child->itemType() == FolderType)
|
||||
static_cast<TorrentContentModelFolder*>(child)->recalculateAvailability();
|
||||
const qreal childAvailability = child->availability();
|
||||
if (childAvailability >= 0) { // -1 means "no data"
|
||||
tAvailability += childAvailability * child->size();
|
||||
foundAnyData = true;
|
||||
}
|
||||
tSize += child->size();
|
||||
}
|
||||
|
||||
if (!isRootItem() && (tSize > 0) && foundAnyData) {
|
||||
m_availability = tAvailability / tSize;
|
||||
Q_ASSERT(m_availability <= 1.);
|
||||
}
|
||||
else {
|
||||
m_availability = -1.;
|
||||
}
|
||||
}
|
||||
|
||||
void TorrentContentModelFolder::increaseSize(qulonglong delta)
|
||||
{
|
||||
if (isRootItem())
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
|
||||
void increaseSize(qulonglong delta);
|
||||
void recalculateProgress();
|
||||
void recalculateAvailability();
|
||||
void updatePriority();
|
||||
|
||||
void setPriority(int newPriority, bool updateParent = true) override;
|
||||
|
|
|
@ -40,6 +40,7 @@ TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder *pare
|
|||
, m_remaining(0)
|
||||
, m_priority(prio::NORMAL)
|
||||
, m_progress(0)
|
||||
, m_availability(-1.)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -84,6 +85,13 @@ qulonglong TorrentContentModelItem::remaining() const
|
|||
return m_remaining;
|
||||
}
|
||||
|
||||
qreal TorrentContentModelItem::availability() const
|
||||
{
|
||||
Q_ASSERT(!isRootItem());
|
||||
|
||||
return m_size > 0 ? m_availability : 0.;
|
||||
}
|
||||
|
||||
int TorrentContentModelItem::priority() const
|
||||
{
|
||||
Q_ASSERT(!isRootItem());
|
||||
|
@ -111,6 +119,8 @@ QVariant TorrentContentModelItem::data(int column) const
|
|||
return m_size;
|
||||
case COL_REMAINING:
|
||||
return remaining();
|
||||
case COL_AVAILABILITY:
|
||||
return availability();
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return QVariant();
|
||||
|
@ -128,3 +138,4 @@ TorrentContentModelFolder *TorrentContentModelItem::parent() const
|
|||
{
|
||||
return m_parentItem;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
COL_PROGRESS,
|
||||
COL_PRIO,
|
||||
COL_REMAINING,
|
||||
COL_AVAILABILITY,
|
||||
NB_COL
|
||||
};
|
||||
|
||||
|
@ -81,6 +82,8 @@ public:
|
|||
qreal progress() const;
|
||||
qulonglong remaining() const;
|
||||
|
||||
qreal availability() const;
|
||||
|
||||
int priority() const;
|
||||
virtual void setPriority(int newPriority, bool updateParent = true) = 0;
|
||||
|
||||
|
@ -98,6 +101,7 @@ protected:
|
|||
qulonglong m_remaining;
|
||||
int m_priority;
|
||||
qreal m_progress;
|
||||
qreal m_availability;
|
||||
};
|
||||
|
||||
#endif // TORRENTCONTENTMODELITEM_H
|
||||
|
|
Loading…
Reference in a new issue