Browse Source

Follow project coding style. Issue #2192.

adaptive-webui-19844
Eugene Shalygin 9 years ago
parent
commit
114c9a8421
  1. 3
      src/gui/torrentcontentmodel.h
  2. 21
      src/gui/torrentcontentmodelfile.cpp
  3. 6
      src/gui/torrentcontentmodelfile.h
  4. 23
      src/gui/torrentcontentmodelfolder.cpp
  5. 4
      src/gui/torrentcontentmodelfolder.h
  6. 5
      src/gui/torrentcontentmodelitem.cpp
  7. 36
      src/gui/torrentcontentmodelitem.h

3
src/gui/torrentcontentmodel.h

@ -41,7 +41,8 @@
class TorrentContentModelFile; class TorrentContentModelFile;
class TorrentContentModel: public QAbstractItemModel { class TorrentContentModel: public QAbstractItemModel
{
Q_OBJECT Q_OBJECT
public: public:

21
src/gui/torrentcontentmodelfile.cpp

@ -32,9 +32,9 @@
#include "torrentcontentmodelfolder.h" #include "torrentcontentmodelfolder.h"
TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize, TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
TorrentContentModelFolder* parent, int file_index) TorrentContentModelFolder *parent, int fileIndex)
: TorrentContentModelItem(parent) : TorrentContentModelItem(parent)
, m_fileIndex(file_index) , m_fileIndex(fileIndex)
{ {
Q_ASSERT(parent); Q_ASSERT(parent);
@ -52,23 +52,28 @@ int TorrentContentModelFile::fileIndex() const
return m_fileIndex; return m_fileIndex;
} }
void TorrentContentModelFile::setPriority(int new_prio, bool update_parent) void TorrentContentModelFile::setPriority(int newPriority, bool updateParent)
{ {
Q_ASSERT(new_prio != prio::MIXED); Q_ASSERT(newPriority != prio::MIXED);
if (m_priority == new_prio) if (m_priority == newPriority)
return; return;
m_priority = new_prio; m_priority = newPriority;
// Update parent // Update parent
if (update_parent) if (updateParent)
m_parentItem->updatePriority(); m_parentItem->updatePriority();
} }
void TorrentContentModelFile::setProgress(qreal progress) void TorrentContentModelFile::setProgress(qreal progress)
{ {
m_progress = progress; m_progress = progress;
m_remaining = (qulonglong)(m_size * (1.0 - m_progress)); m_remaining = static_cast<qulonglong>(m_size * (1.0 - m_progress));
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);
} }
TorrentContentModelItem::ItemType TorrentContentModelFile::itemType() const
{
return FileType;
}

6
src/gui/torrentcontentmodelfile.h

@ -37,12 +37,12 @@ class TorrentContentModelFile : public TorrentContentModelItem
{ {
public: public:
TorrentContentModelFile(const QString &fileName, qulonglong fileSize, TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
TorrentContentModelFolder* parent, int file_index); TorrentContentModelFolder *parent, int fileIndex);
int fileIndex() const; int fileIndex() const;
void setPriority(int new_prio, bool update_parent = true); void setPriority(int newPriority, bool updateParent = true) override;
void setProgress(qreal progress); void setProgress(qreal progress);
ItemType itemType() const { return FileType; } ItemType itemType() const override;
private: private:
int m_fileIndex; int m_fileIndex;

23
src/gui/torrentcontentmodelfolder.cpp

@ -53,6 +53,11 @@ TorrentContentModelFolder::~TorrentContentModelFolder()
qDeleteAll(m_childItems); qDeleteAll(m_childItems);
} }
TorrentContentModelItem::ItemType TorrentContentModelFolder::itemType() const
{
return FolderType;
}
void TorrentContentModelFolder::deleteAllChildren() void TorrentContentModelFolder::deleteAllChildren()
{ {
Q_ASSERT(isRootItem()); Q_ASSERT(isRootItem());
@ -81,10 +86,9 @@ TorrentContentModelItem* TorrentContentModelFolder::child(int row) const
TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
{ {
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem *child, m_childItems)
if (child->itemType() == FolderType && child->name() == name) if ((child->itemType() == FolderType) && (child->name() == name))
return static_cast<TorrentContentModelFolder *>(child); return static_cast<TorrentContentModelFolder *>(child);
}
return 0; return 0;
} }
@ -116,23 +120,22 @@ void TorrentContentModelFolder::updatePriority()
setPriority(prio); setPriority(prio);
} }
void TorrentContentModelFolder::setPriority(int new_prio, bool update_parent) void TorrentContentModelFolder::setPriority(int newPriority, bool updateParent)
{ {
if (m_priority == new_prio) if (m_priority == newPriority)
return; return;
m_priority = new_prio; m_priority = newPriority;
// Update parent priority // Update parent priority
if (update_parent) if (updateParent)
m_parentItem->updatePriority(); m_parentItem->updatePriority();
// Update children // Update children
if (m_priority != prio::MIXED) { if (m_priority != prio::MIXED)
foreach (TorrentContentModelItem *child, m_childItems) foreach (TorrentContentModelItem *child, m_childItems)
child->setPriority(m_priority, false); child->setPriority(m_priority, false);
} }
}
void TorrentContentModelFolder::recalculateProgress() void TorrentContentModelFolder::recalculateProgress()
{ {
@ -149,7 +152,7 @@ void TorrentContentModelFolder::recalculateProgress()
} }
} }
if (!isRootItem() && tSize > 0) { if (!isRootItem() && (tSize > 0)) {
m_progress = tProgress / tSize; m_progress = tProgress / tSize;
m_remaining = tRemaining; m_remaining = tRemaining;
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);

4
src/gui/torrentcontentmodelfolder.h

@ -44,13 +44,13 @@ public:
~TorrentContentModelFolder(); ~TorrentContentModelFolder();
ItemType itemType() const { return FolderType; } ItemType itemType() const override;
void increaseSize(qulonglong delta); void increaseSize(qulonglong delta);
void recalculateProgress(); void recalculateProgress();
void updatePriority(); void updatePriority();
void setPriority(int new_prio, bool update_parent = true); void setPriority(int newPriority, bool updateParent = true) override;
void deleteAllChildren(); void deleteAllChildren();
const QList<TorrentContentModelItem*>& children() const; const QList<TorrentContentModelItem*>& children() const;

5
src/gui/torrentcontentmodelitem.cpp

@ -43,8 +43,11 @@ TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* pare
{ {
} }
TorrentContentModelItem::~TorrentContentModelItem() TorrentContentModelItem::~TorrentContentModelItem() = default;
bool TorrentContentModelItem::isRootItem() const
{ {
return !m_parentItem;
} }
QString TorrentContentModelItem::name() const QString TorrentContentModelItem::name() const

36
src/gui/torrentcontentmodelitem.h

@ -34,21 +34,43 @@
#include <QList> #include <QList>
#include <QVariant> #include <QVariant>
namespace prio { namespace prio
enum FilePriority {IGNORED=0, NORMAL=1, HIGH=6, MAXIMUM=7, MIXED=-1}; {
enum FilePriority
{
IGNORED=0,
NORMAL=1,
HIGH=6,
MAXIMUM=7,
MIXED=-1
};
} }
class TorrentContentModelFolder; class TorrentContentModelFolder;
class TorrentContentModelItem { class TorrentContentModelItem
{
public: public:
enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, COL_REMAINING, NB_COL}; enum TreeItemColumns
enum ItemType { FileType, FolderType }; {
COL_NAME,
COL_SIZE,
COL_PROGRESS,
COL_PRIO,
COL_REMAINING,
NB_COL
};
enum ItemType
{
FileType,
FolderType
};
TorrentContentModelItem(TorrentContentModelFolder *parent); TorrentContentModelItem(TorrentContentModelFolder *parent);
virtual ~TorrentContentModelItem(); virtual ~TorrentContentModelItem();
inline bool isRootItem() const { return !m_parentItem; } bool isRootItem() const;
TorrentContentModelFolder *parent() const; TorrentContentModelFolder *parent() const;
virtual ItemType itemType() const = 0; virtual ItemType itemType() const = 0;
@ -60,7 +82,7 @@ public:
qulonglong remaining() const; qulonglong remaining() const;
int priority() const; int priority() const;
virtual void setPriority(int new_prio, bool update_parent = true) = 0; virtual void setPriority(int newPriority, bool updateParent = true) = 0;
int columnCount() const; int columnCount() const;
QVariant data(int column) const; QVariant data(int column) const;

Loading…
Cancel
Save