Browse Source

TorrentContentModel code clean up

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
38daa23be2
  1. 9
      src/torrentcontentmodel.cpp
  2. 4
      src/torrentcontentmodel.h
  3. 7
      src/torrentcontentmodelfile.cpp
  4. 1
      src/torrentcontentmodelfile.h
  5. 5
      src/torrentcontentmodelfolder.cpp
  6. 9
      src/torrentcontentmodelitem.cpp
  7. 1
      src/torrentcontentmodelitem.h

9
src/torrentcontentmodel.cpp

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

4
src/torrentcontentmodel.h

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

7
src/torrentcontentmodelfile.cpp

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

1
src/torrentcontentmodelfile.h

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

5
src/torrentcontentmodelfolder.cpp

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

9
src/torrentcontentmodelitem.cpp

@ -63,15 +63,6 @@ qulonglong TorrentContentModelItem::size() const
return m_size; 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 qulonglong TorrentContentModelItem::totalDone() const
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());

1
src/torrentcontentmodelitem.h

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

Loading…
Cancel
Save