1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 23:07:59 +00:00

Made progress calculation more efficient in torrent content model

Stop to address issue #24.
This commit is contained in:
Christophe Dumez 2012-08-27 22:01:35 +03:00
parent f73f267997
commit ca2a659970
4 changed files with 16 additions and 18 deletions

View File

@ -59,6 +59,8 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size
for (uint i = 0; i < fp.size(); ++i) { for (uint i = 0; i < fp.size(); ++i) {
m_filesIndex[i]->setProgress(fp[i]); m_filesIndex[i]->setProgress(fp[i]);
} }
// Update folders progress in the tree
m_rootItem->recalculateProgress();
emit dataChanged(index(0,0), index(rowCount(), columnCount())); 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); item->setPriority(prio::IGNORED);
else else
item->setPriority(prio::NORMAL); 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 dataChanged(this->index(0,0), this->index(rowCount()-1, columnCount()-1));
emit filteredFilesChanged(); emit filteredFilesChanged();
} }

View File

@ -69,15 +69,12 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
m_priority = new_prio; m_priority = new_prio;
// Update parent // Update parent
if (update_parent) { if (update_parent)
m_parentItem->updateProgress();
m_parentItem->updatePriority(); m_parentItem->updatePriority();
}
} }
void TorrentContentModelFile::setProgress(qulonglong done) void TorrentContentModelFile::setProgress(qulonglong done)
{ {
m_totalDone = done; m_totalDone = done;
Q_ASSERT(m_totalDone <= m_size); Q_ASSERT(m_totalDone <= m_size);
m_parentItem->updateProgress();
} }

View File

@ -131,25 +131,22 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent)
foreach (TorrentContentModelItem* child, m_childItems) foreach (TorrentContentModelItem* child, m_childItems)
child->setPriority(m_priority, false); child->setPriority(m_priority, false);
} }
updateProgress();
} }
void TorrentContentModelFolder::updateProgress() void TorrentContentModelFolder::recalculateProgress()
{ {
if (isRootItem()) qulonglong totalDone = 0;
return;
qulonglong total_done = 0;
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() > 0) if (child->priority() != prio::IGNORED) {
total_done += child->totalDone(); if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress();
totalDone += child->totalDone();
}
} }
Q_ASSERT(total_done <= m_size); if (!isRootItem()) {
if (total_done != m_totalDone) { m_totalDone = totalDone;
m_totalDone = total_done; Q_ASSERT(m_totalDone <= m_size);
m_parentItem->updateProgress();
} }
} }

View File

@ -47,7 +47,7 @@ public:
ItemType itemType() const { return FolderType; } ItemType itemType() const { return FolderType; }
void increaseSize(qulonglong delta); void increaseSize(qulonglong delta);
void updateProgress(); void recalculateProgress();
void updatePriority(); void updatePriority();
void setPriority(int new_prio, bool update_parent = true); void setPriority(int new_prio, bool update_parent = true);