Browse Source

Follow project coding style. Issue #2192.

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

9
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:
@ -52,7 +53,7 @@ public: @@ -52,7 +53,7 @@ public:
void updateFilesPriorities(const QVector<int> &fprio);
QVector<int> getFilePriorities() const;
bool allFiltered() const;
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
TorrentContentModelItem::ItemType itemType(const QModelIndex& index) const;
int getFileIndex(const QModelIndex& index);
@ -73,8 +74,8 @@ public slots: @@ -73,8 +74,8 @@ public slots:
void selectNone();
private:
TorrentContentModelFolder* m_rootItem;
QVector<TorrentContentModelFile*> m_filesIndex;
TorrentContentModelFolder *m_rootItem;
QVector<TorrentContentModelFile *> m_filesIndex;
};
#endif // TORRENTCONTENTMODEL_H

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;
}

8
src/gui/torrentcontentmodelfile.h

@ -33,16 +33,16 @@ @@ -33,16 +33,16 @@
#include "torrentcontentmodelitem.h"
class TorrentContentModelFile : public TorrentContentModelItem
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;

45
src/gui/torrentcontentmodelfolder.cpp

@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
#include <QDebug>
#include "torrentcontentmodelfolder.h"
TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, TorrentContentModelFolder* parent)
TorrentContentModelFolder::TorrentContentModelFolder(const QString &name, TorrentContentModelFolder *parent)
: TorrentContentModelItem(parent)
{
Q_ASSERT(parent);
@ -41,7 +41,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, Torren @@ -41,7 +41,7 @@ TorrentContentModelFolder::TorrentContentModelFolder(const QString& name, Torren
m_name.chop(4);
}
TorrentContentModelFolder::TorrentContentModelFolder(const QList<QVariant>& data)
TorrentContentModelFolder::TorrentContentModelFolder(const QList<QVariant> &data)
: TorrentContentModelItem(0)
{
Q_ASSERT(data.size() == NB_COL);
@ -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());
@ -60,12 +65,12 @@ void TorrentContentModelFolder::deleteAllChildren() @@ -60,12 +65,12 @@ void TorrentContentModelFolder::deleteAllChildren()
m_childItems.clear();
}
const QList<TorrentContentModelItem*>& TorrentContentModelFolder::children() const
const QList<TorrentContentModelItem *> &TorrentContentModelFolder::children() const
{
return m_childItems;
}
void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item)
void TorrentContentModelFolder::appendChild(TorrentContentModelItem *item)
{
Q_ASSERT(item);
m_childItems.append(item);
@ -74,17 +79,16 @@ void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item) @@ -74,17 +79,16 @@ void TorrentContentModelFolder::appendChild(TorrentContentModelItem* item)
increaseSize(item->size());
}
TorrentContentModelItem* TorrentContentModelFolder::child(int row) const
TorrentContentModelItem *TorrentContentModelFolder::child(int row) const
{
return m_childItems.value(row, 0);
}
TorrentContentModelFolder* TorrentContentModelFolder::childFolderWithName(const QString& name) const
TorrentContentModelFolder *TorrentContentModelFolder::childFolderWithName(const QString &name) const
{
foreach (TorrentContentModelItem* child, m_childItems) {
if (child->itemType() == FolderType && child->name() == name)
return static_cast<TorrentContentModelFolder*>(child);
}
foreach (TorrentContentModelItem *child, m_childItems)
if ((child->itemType() == FolderType) && (child->name() == name))
return static_cast<TorrentContentModelFolder *>(child);
return 0;
}
@ -105,7 +109,7 @@ void TorrentContentModelFolder::updatePriority() @@ -105,7 +109,7 @@ void TorrentContentModelFolder::updatePriority()
// then the folder should have the same
// priority
const int prio = m_childItems.first()->priority();
for (int i=1; i<m_childItems.size(); ++i) {
for (int i = 1; i < m_childItems.size(); ++i) {
if (m_childItems.at(i)->priority() != prio) {
setPriority(prio::MIXED);
return;
@ -116,22 +120,21 @@ void TorrentContentModelFolder::updatePriority() @@ -116,22 +120,21 @@ 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) {
foreach (TorrentContentModelItem* child, m_childItems)
if (m_priority != prio::MIXED)
foreach (TorrentContentModelItem *child, m_childItems)
child->setPriority(m_priority, false);
}
}
void TorrentContentModelFolder::recalculateProgress()
@ -139,17 +142,17 @@ void TorrentContentModelFolder::recalculateProgress() @@ -139,17 +142,17 @@ void TorrentContentModelFolder::recalculateProgress()
qreal tProgress = 0;
qulonglong tSize = 0;
qulonglong tRemaining = 0;
foreach (TorrentContentModelItem* child, m_childItems) {
foreach (TorrentContentModelItem *child, m_childItems) {
if (child->priority() != prio::IGNORED) {
if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress();
static_cast<TorrentContentModelFolder *>(child)->recalculateProgress();
tProgress += child->progress() * child->size();
tSize += child->size();
tRemaining += child->remaining();
}
}
if (!isRootItem() && tSize > 0) {
if (!isRootItem() && (tSize > 0)) {
m_progress = tProgress / tSize;
m_remaining = tRemaining;
Q_ASSERT(m_progress <= 1.);

6
src/gui/torrentcontentmodelfolder.h

@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
#include "torrentcontentmodelitem.h"
class TorrentContentModelFolder : public TorrentContentModelItem
class TorrentContentModelFolder: public TorrentContentModelItem
{
public:
// Folder constructor
@ -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;

15
src/gui/torrentcontentmodelitem.cpp

@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
#include "torrentcontentmodelfolder.h"
#include <QDebug>
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent)
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder *parent)
: m_parentItem(parent)
, m_size(0)
, m_remaining(0)
@ -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
@ -53,7 +56,7 @@ QString TorrentContentModelItem::name() const @@ -53,7 +56,7 @@ QString TorrentContentModelItem::name() const
return m_name;
}
void TorrentContentModelItem::setName(const QString& name)
void TorrentContentModelItem::setName(const QString &name)
{
Q_ASSERT(!isRootItem());
m_name = name;
@ -97,7 +100,7 @@ QVariant TorrentContentModelItem::data(int column) const @@ -97,7 +100,7 @@ QVariant TorrentContentModelItem::data(int column) const
if (isRootItem())
return m_itemData.value(column);
switch(column) {
switch (column) {
case COL_NAME:
return m_name;
case COL_PRIO:
@ -117,11 +120,11 @@ QVariant TorrentContentModelItem::data(int column) const @@ -117,11 +120,11 @@ QVariant TorrentContentModelItem::data(int column) const
int TorrentContentModelItem::row() const
{
if (m_parentItem)
return m_parentItem->children().indexOf(const_cast<TorrentContentModelItem*>(this));
return m_parentItem->children().indexOf(const_cast<TorrentContentModelItem *>(this));
return 0;
}
TorrentContentModelFolder* TorrentContentModelItem::parent() const
TorrentContentModelFolder *TorrentContentModelItem::parent() const
{
return m_parentItem;
}

44
src/gui/torrentcontentmodelitem.h

@ -34,40 +34,62 @@ @@ -34,40 +34,62 @@
#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
};
TorrentContentModelItem(TorrentContentModelFolder* parent);
enum ItemType
{
FileType,
FolderType
};
TorrentContentModelItem(TorrentContentModelFolder *parent);
virtual ~TorrentContentModelItem();
inline bool isRootItem() const { return !m_parentItem; }
TorrentContentModelFolder* parent() const;
bool isRootItem() const;
TorrentContentModelFolder *parent() const;
virtual ItemType itemType() const = 0;
QString name() const;
void setName(const QString& name);
void setName(const QString &name);
qulonglong size() const;
qreal progress() const;
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;
int row() const;
protected:
TorrentContentModelFolder* m_parentItem;
TorrentContentModelFolder *m_parentItem;
// Root item members
QList<QVariant> m_itemData;
// Non-root item members

Loading…
Cancel
Save