mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
Follow project coding style. Issue #2192.
This commit is contained in:
parent
50881b9972
commit
145180c2a1
1 changed files with 197 additions and 199 deletions
|
@ -39,21 +39,24 @@
|
||||||
#include "torrentcontentmodelfolder.h"
|
#include "torrentcontentmodelfolder.h"
|
||||||
#include "torrentcontentmodelfile.h"
|
#include "torrentcontentmodelfile.h"
|
||||||
|
|
||||||
namespace {
|
namespace
|
||||||
QIcon get_directory_icon() {
|
{
|
||||||
|
QIcon get_directory_icon()
|
||||||
|
{
|
||||||
static QIcon cached = GuiIconProvider::instance()->getIcon("inode-directory");
|
static QIcon cached = GuiIconProvider::instance()->getIcon("inode-directory");
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon get_file_icon() {
|
QIcon get_file_icon()
|
||||||
|
{
|
||||||
static QIcon cached = GuiIconProvider::instance()->getIcon("text-plain");
|
static QIcon cached = GuiIconProvider::instance()->getIcon("text-plain");
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentContentModel::TorrentContentModel(QObject *parent):
|
TorrentContentModel::TorrentContentModel(QObject *parent)
|
||||||
QAbstractItemModel(parent),
|
: QAbstractItemModel(parent)
|
||||||
m_rootItem(new TorrentContentModelFolder(QList<QVariant>() << tr("Name") << tr("Size")
|
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>() << tr("Name") << tr("Size")
|
||||||
<< tr("Progress") << tr("Download Priority")))
|
<< tr("Progress") << tr("Download Priority")))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -70,12 +73,11 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
|
||||||
if (m_filesIndex.size() != fp.size()) return;
|
if (m_filesIndex.size() != fp.size()) return;
|
||||||
|
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
for (int i = 0; i < fp.size(); ++i) {
|
for (int i = 0; i < fp.size(); ++i)
|
||||||
m_filesIndex[i]->setProgress(fp[i]);
|
m_filesIndex[i]->setProgress(fp[i]);
|
||||||
}
|
|
||||||
// Update folders progress in the tree
|
// Update folders progress in the tree
|
||||||
m_rootItem->recalculateProgress();
|
m_rootItem->recalculateProgress();
|
||||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
||||||
|
@ -86,9 +88,8 @@ void TorrentContentModel::updateFilesPriorities(const QVector<int> &fprio)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
emit layoutAboutToBeChanged();
|
emit layoutAboutToBeChanged();
|
||||||
for (int i = 0; i < fprio.size(); ++i) {
|
for (int i = 0; i < fprio.size(); ++i)
|
||||||
m_filesIndex[i]->setPriority(fprio[i]);
|
m_filesIndex[i]->setPriority(fprio[i]);
|
||||||
}
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,18 +97,16 @@ QVector<int> TorrentContentModel::getFilePriorities() const
|
||||||
{
|
{
|
||||||
QVector<int> prio;
|
QVector<int> prio;
|
||||||
prio.reserve(m_filesIndex.size());
|
prio.reserve(m_filesIndex.size());
|
||||||
foreach (const TorrentContentModelFile* file, m_filesIndex) {
|
foreach (const TorrentContentModelFile* file, m_filesIndex)
|
||||||
prio.push_back(file->priority());
|
prio.push_back(file->priority());
|
||||||
}
|
|
||||||
return prio;
|
return prio;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentContentModel::allFiltered() const
|
bool TorrentContentModel::allFiltered() const
|
||||||
{
|
{
|
||||||
foreach (const TorrentContentModelFile* fileItem, m_filesIndex) {
|
foreach (const TorrentContentModelFile* fileItem, m_filesIndex)
|
||||||
if (fileItem->priority() != prio::IGNORED)
|
if (fileItem->priority() != prio::IGNORED)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (index.column() == 0 && role == Qt::CheckStateRole) {
|
if ((index.column() == 0) && (role == Qt::CheckStateRole)) {
|
||||||
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
TorrentContentModelItem *item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
||||||
qDebug("setData(%s, %d", qPrintable(item->name()), value.toInt());
|
qDebug("setData(%s, %d", qPrintable(item->name()), value.toInt());
|
||||||
if (item->priority() != value.toInt()) {
|
if (item->priority() != value.toInt()) {
|
||||||
|
@ -136,7 +135,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
||||||
item->setPriority(prio::NORMAL);
|
item->setPriority(prio::NORMAL);
|
||||||
// Update folders progress in the tree
|
// Update folders progress in the tree
|
||||||
m_rootItem->recalculateProgress();
|
m_rootItem->recalculateProgress();
|
||||||
emit dataChanged(this->index(0,0), this->index(rowCount()-1, columnCount()-1));
|
emit dataChanged(this->index(0, 0), this->index(rowCount() - 1, columnCount() - 1));
|
||||||
emit filteredFilesChanged();
|
emit filteredFilesChanged();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -145,7 +144,7 @@ bool TorrentContentModel::setData(const QModelIndex& index, const QVariant& valu
|
||||||
if (role == Qt::EditRole) {
|
if (role == Qt::EditRole) {
|
||||||
Q_ASSERT(index.isValid());
|
Q_ASSERT(index.isValid());
|
||||||
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
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());
|
||||||
break;
|
break;
|
||||||
|
@ -180,13 +179,13 @@ QVariant TorrentContentModel::data(const QModelIndex& index, int role) const
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
TorrentContentModelItem* item = static_cast<TorrentContentModelItem*>(index.internalPointer());
|
||||||
if (index.column() == 0 && role == Qt::DecorationRole) {
|
if ((index.column() == 0) && (role == Qt::DecorationRole)) {
|
||||||
if (item->itemType() == TorrentContentModelItem::FolderType)
|
if (item->itemType() == TorrentContentModelItem::FolderType)
|
||||||
return get_directory_icon();
|
return get_directory_icon();
|
||||||
else
|
else
|
||||||
return get_file_icon();
|
return get_file_icon();
|
||||||
}
|
}
|
||||||
if (index.column() == 0 && role == Qt::CheckStateRole) {
|
if ((index.column() == 0) && (role == Qt::CheckStateRole)) {
|
||||||
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
|
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::IGNORED)
|
||||||
return Qt::Unchecked;
|
return Qt::Unchecked;
|
||||||
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED)
|
if (item->data(TorrentContentModelItem::COL_PRIO).toInt() == prio::MIXED)
|
||||||
|
@ -212,7 +211,7 @@ Qt::ItemFlags TorrentContentModel::flags(const QModelIndex& index) const
|
||||||
|
|
||||||
QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole))
|
||||||
return m_rootItem->data(section);
|
return m_rootItem->data(section);
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
@ -220,7 +219,7 @@ QVariant TorrentContentModel::headerData(int section, Qt::Orientation orientatio
|
||||||
|
|
||||||
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& parent) const
|
QModelIndex TorrentContentModel::index(int row, int column, const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid() && parent.column() != 0)
|
if (parent.isValid() && (parent.column() != 0))
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
|
|
||||||
if (column >= TorrentContentModelItem::NB_COL)
|
if (column >= TorrentContentModelItem::NB_COL)
|
||||||
|
@ -320,7 +319,7 @@ void TorrentContentModel::setupModelData(const BitTorrent::TorrentInfo &info)
|
||||||
|
|
||||||
void TorrentContentModel::selectAll()
|
void TorrentContentModel::selectAll()
|
||||||
{
|
{
|
||||||
for (int i=0; i<m_rootItem->childCount(); ++i) {
|
for (int i = 0; i < m_rootItem->childCount(); ++i) {
|
||||||
TorrentContentModelItem* child = m_rootItem->child(i);
|
TorrentContentModelItem* child = m_rootItem->child(i);
|
||||||
if (child->priority() == prio::IGNORED)
|
if (child->priority() == prio::IGNORED)
|
||||||
child->setPriority(prio::NORMAL);
|
child->setPriority(prio::NORMAL);
|
||||||
|
@ -330,8 +329,7 @@ void TorrentContentModel::selectAll()
|
||||||
|
|
||||||
void TorrentContentModel::selectNone()
|
void TorrentContentModel::selectNone()
|
||||||
{
|
{
|
||||||
for (int i=0; i<m_rootItem->childCount(); ++i) {
|
for (int i = 0; i < m_rootItem->childCount(); ++i)
|
||||||
m_rootItem->child(i)->setPriority(prio::IGNORED);
|
m_rootItem->child(i)->setPriority(prio::IGNORED);
|
||||||
}
|
|
||||||
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
emit dataChanged(index(0, 0), index(rowCount(), columnCount()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue