Browse Source

Made progress calculation more efficient in torrent content model

Stop to address issue #24.
adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
ca2a659970
  1. 4
      src/torrentcontentmodel.cpp
  2. 5
      src/torrentcontentmodelfile.cpp
  3. 23
      src/torrentcontentmodelfolder.cpp
  4. 2
      src/torrentcontentmodelfolder.h

4
src/torrentcontentmodel.cpp

@ -59,6 +59,8 @@ void TorrentContentModel::updateFilesProgress(const std::vector<libtorrent::size @@ -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 @@ -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();
}

5
src/torrentcontentmodelfile.cpp

@ -69,15 +69,12 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) @@ -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();
}

23
src/torrentcontentmodelfolder.cpp

@ -131,25 +131,22 @@ void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent) @@ -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);
}
}

2
src/torrentcontentmodelfolder.h

@ -47,7 +47,7 @@ public: @@ -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…
Cancel
Save