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
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();
} }

5
src/torrentcontentmodelfile.cpp

@ -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();
} }

23
src/torrentcontentmodelfolder.cpp

@ -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();
} }
} }

2
src/torrentcontentmodelfolder.h

@ -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);

Loading…
Cancel
Save