1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 14:57:52 +00:00

TorrentContentModel code clean up

This commit is contained in:
Christophe Dumez 2012-08-26 20:15:55 +03:00
parent 45ba858022
commit 38daa23be2
7 changed files with 20 additions and 16 deletions

View File

@ -80,7 +80,7 @@ std::vector<int> TorrentContentModel::getFilesPriorities() const
{
std::vector<int> prio;
prio.reserve(m_filesIndex.size());
foreach (const TorrentContentModelItem* file, m_filesIndex) {
foreach (const TorrentContentModelFile* file, m_filesIndex) {
prio.push_back(file->priority());
}
return prio;
@ -88,7 +88,7 @@ std::vector<int> TorrentContentModel::getFilesPriorities() const
bool TorrentContentModel::allFiltered() const
{
foreach (const TorrentContentModelItem* fileItem, m_filesIndex) {
foreach (const TorrentContentModelFile* fileItem, m_filesIndex) {
if (fileItem->priority() != prio::IGNORED)
return false;
}
@ -125,7 +125,8 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
}
if (role == Qt::EditRole) {
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
Q_ASSERT(index.isValid());
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
switch(index.column()) {
case TorrentContentModelItem::COL_NAME:
item->setName(value.toString());
@ -155,7 +156,7 @@ int TorrentContentModel::getFileIndex(const QModelIndex& index)
return item->fileIndex();
}
QVariant TorrentContentModel::data(const QModelIndex &index, int role) const
QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();

View File

@ -38,6 +38,8 @@
#include <libtorrent/torrent_info.hpp>
#include "torrentcontentmodelitem.h"
class TorrentContentModelFile;
class TorrentContentModel: public QAbstractItemModel {
Q_OBJECT
@ -71,7 +73,7 @@ public slots:
private:
TorrentContentModelFolder* m_rootItem;
QVector<TorrentContentModelItem*> m_filesIndex;
QVector<TorrentContentModelFile*> m_filesIndex;
};
#endif // TORRENTCONTENTMODEL_H

View File

@ -80,3 +80,10 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
m_parentItem->updatePriority();
}
}
void TorrentContentModelFile::setProgress(qulonglong done)
{
m_totalDone = done;
Q_ASSERT(m_totalDone <= m_size);
m_parentItem->updateProgress();
}

View File

@ -43,6 +43,7 @@ public:
int fileIndex() const;
void setPriority(int new_prio, bool update_parent = true);
void setProgress(qulonglong done);
ItemType itemType() const { return FileType; }
private:

View File

@ -157,7 +157,10 @@ void TorrentContentModelFolder::updateProgress()
}
Q_ASSERT(total_done <= m_size);
setProgress(total_done);
if (total_done != m_totalDone) {
m_totalDone = total_done;
m_parentItem->updateProgress();
}
}
void TorrentContentModelFolder::updateSize()

View File

@ -63,15 +63,6 @@ qulonglong TorrentContentModelItem::size() const
return m_size;
}
void TorrentContentModelItem::setProgress(qulonglong done)
{
Q_ASSERT(!isRootItem());
m_totalDone = done;
Q_ASSERT(m_totalDone <= m_size);
m_parentItem->updateProgress();
}
qulonglong TorrentContentModelItem::totalDone() const
{
Q_ASSERT(!isRootItem());

View File

@ -59,7 +59,6 @@ public:
qulonglong size() const;
qulonglong totalDone() const;
void setProgress(qulonglong done);
float progress() const;
int priority() const;