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

4
src/torrentcontentmodel.h

@ -38,6 +38,8 @@ @@ -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: @@ -71,7 +73,7 @@ public slots:
private:
TorrentContentModelFolder* m_rootItem;
QVector<TorrentContentModelItem*> m_filesIndex;
QVector<TorrentContentModelFile*> m_filesIndex;
};
#endif // TORRENTCONTENTMODEL_H

7
src/torrentcontentmodelfile.cpp

@ -80,3 +80,10 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) @@ -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();
}

1
src/torrentcontentmodelfile.h

@ -43,6 +43,7 @@ public: @@ -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:

5
src/torrentcontentmodelfolder.cpp

@ -157,7 +157,10 @@ void TorrentContentModelFolder::updateProgress() @@ -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()

9
src/torrentcontentmodelitem.cpp

@ -63,15 +63,6 @@ qulonglong TorrentContentModelItem::size() const @@ -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());

1
src/torrentcontentmodelitem.h

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

Loading…
Cancel
Save