mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Made progress calculation more efficient in torrent content model
Stop to address issue #24.
This commit is contained in:
parent
f73f267997
commit
ca2a659970
@ -59,6 +59,8 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size
|
||||
for (uint i = 0; i < fp.size(); ++i) {
|
||||
m_filesIndex[i]->setProgress(fp[i]);
|
||||
}
|
||||
// Update folders progress in the tree
|
||||
m_rootItem->recalculateProgress();
|
||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||
}
|
||||
|
||||
@ -118,6 +120,8 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
||||
item->setPriority(prio::IGNORED);
|
||||
else
|
||||
item->setPriority(prio::NORMAL);
|
||||
// Update folders progress in the tree
|
||||
m_rootItem->recalculateProgress();
|
||||
emit dataChanged(this->index(0,0), this->index(rowCount()-1, columnCount()-1));
|
||||
emit filteredFilesChanged();
|
||||
}
|
||||
|
@ -69,15 +69,12 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
|
||||
m_priority = new_prio;
|
||||
|
||||
// Update parent
|
||||
if (update_parent) {
|
||||
m_parentItem->updateProgress();
|
||||
if (update_parent)
|
||||
m_parentItem->updatePriority();
|
||||
}
|
||||
}
|
||||
|
||||
void TorrentContentModelFile::setProgress(qulonglong done)
|
||||
{
|
||||
m_totalDone = done;
|
||||
Q_ASSERT(m_totalDone <= m_size);
|
||||
m_parentItem->updateProgress();
|
||||
}
|
||||
|
@ -131,25 +131,22 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent)
|
||||
foreach (TorrentContentModelItem* child, m_childItems)
|
||||
child->setPriority(m_priority, false);
|
||||
}
|
||||
|
||||
updateProgress();
|
||||
}
|
||||
|
||||
void TorrentContentModelFolder::updateProgress()
|
||||
void TorrentContentModelFolder::recalculateProgress()
|
||||
{
|
||||
if (isRootItem())
|
||||
return;
|
||||
|
||||
qulonglong total_done = 0;
|
||||
qulonglong totalDone = 0;
|
||||
foreach (TorrentContentModelItem* child, m_childItems) {
|
||||
if (child->priority() > 0)
|
||||
total_done += child->totalDone();
|
||||
if (child->priority() != prio::IGNORED) {
|
||||
if (child->itemType() == FolderType)
|
||||
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress();
|
||||
totalDone += child->totalDone();
|
||||
}
|
||||
}
|
||||
|
||||
Q_ASSERT(total_done <= m_size);
|
||||
if (total_done != m_totalDone) {
|
||||
m_totalDone = total_done;
|
||||
m_parentItem->updateProgress();
|
||||
if (!isRootItem()) {
|
||||
m_totalDone = totalDone;
|
||||
Q_ASSERT(m_totalDone <= m_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
ItemType itemType() const { return FolderType; }
|
||||
|
||||
void increaseSize(qulonglong delta);
|
||||
void updateProgress();
|
||||
void recalculateProgress();
|
||||
void updatePriority();
|
||||
|
||||
void setPriority(int new_prio, bool update_parent = true);
|
||||
|
Loading…
Reference in New Issue
Block a user