diff --git a/src/torrentcontentmodel.cpp b/src/torrentcontentmodel.cpp index 03988d0e0..93b5aa58e 100644 --- a/src/torrentcontentmodel.cpp +++ b/src/torrentcontentmodel.cpp @@ -59,6 +59,8 @@ void TorrentContentModel::updateFilesProgress(const std::vectorsetProgress(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(); } diff --git a/src/torrentcontentmodelfile.cpp b/src/torrentcontentmodelfile.cpp index de6bcacd2..777e44d87 100644 --- a/src/torrentcontentmodelfile.cpp +++ b/src/torrentcontentmodelfile.cpp @@ -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(); } diff --git a/src/torrentcontentmodelfolder.cpp b/src/torrentcontentmodelfolder.cpp index 9d02174f7..4d89396ac 100644 --- a/src/torrentcontentmodelfolder.cpp +++ b/src/torrentcontentmodelfolder.cpp @@ -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(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); } } diff --git a/src/torrentcontentmodelfolder.h b/src/torrentcontentmodelfolder.h index 8adff1288..ead57acd7 100644 --- a/src/torrentcontentmodelfolder.h +++ b/src/torrentcontentmodelfolder.h @@ -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);