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 @@ @@ -41,7 +41,8 @@
class TorrentContentModelFile;
class TorrentContentModel: public QAbstractItemModel {
class TorrentContentModel: public QAbstractItemModel
{
Q_OBJECT
public:

21
src/gui/torrentcontentmodelfile.cpp

@ -32,9 +32,9 @@ @@ -32,9 +32,9 @@
#include "torrentcontentmodelfolder.h"
TorrentContentModelFile::TorrentContentModelFile(const QString &fileName, qulonglong fileSize,
TorrentContentModelFolder* parent, int file_index)
TorrentContentModelFolder *parent, int fileIndex)
: TorrentContentModelItem(parent)
, m_fileIndex(file_index)
, m_fileIndex(fileIndex)
{
Q_ASSERT(parent);
@ -52,23 +52,28 @@ int TorrentContentModelFile::fileIndex() const @@ -52,23 +52,28 @@ int TorrentContentModelFile::fileIndex() const
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;
m_priority = new_prio;
m_priority = newPriority;
// Update parent
if (update_parent)
if (updateParent)
m_parentItem->updatePriority();
}
void TorrentContentModelFile::setProgress(qreal 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.);
}
TorrentContentModelItem::ItemType TorrentContentModelFile::itemType() const
{
return FileType;
}

6
src/gui/torrentcontentmodelfile.h

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

23
src/gui/torrentcontentmodelfolder.cpp

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

4
src/gui/torrentcontentmodelfolder.h

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

5
src/gui/torrentcontentmodelitem.cpp

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

36
src/gui/torrentcontentmodelitem.h

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

Loading…
Cancel
Save