Browse Source

add a remaining column to the torrent content model

adaptive-webui-19844
Ben Lau 9 years ago
parent
commit
cd9cae4121
  1. 9
      src/gui/properties/proplistdelegate.cpp
  2. 3
      src/gui/properties/proplistdelegate.h
  3. 2
      src/gui/torrentcontentmodel.cpp
  4. 1
      src/gui/torrentcontentmodelfile.cpp
  5. 3
      src/gui/torrentcontentmodelfolder.cpp
  6. 11
      src/gui/torrentcontentmodelitem.cpp
  7. 4
      src/gui/torrentcontentmodelitem.h

9
src/gui/properties/proplistdelegate.cpp

@ -67,6 +67,15 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break; break;
case REMAINING:
QItemDelegate::drawBackground(painter, opt, index);
if (index.sibling(index.row(), PRIORITY).data().toInt() == prio::IGNORED) {
QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A"));
}
else {
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
}
break;
case PROGRESS: case PROGRESS:
if (index.data().toDouble() >= 0) { if (index.data().toDouble() >= 0) {
QStyleOptionProgressBarV2 newopt; QStyleOptionProgressBarV2 newopt;

3
src/gui/properties/proplistdelegate.h

@ -45,7 +45,8 @@ enum PropColumn
NAME, NAME,
PCSIZE, PCSIZE,
PROGRESS, PROGRESS,
PRIORITY PRIORITY,
REMAINING
}; };
class PropListDelegate : public QItemDelegate class PropListDelegate : public QItemDelegate

2
src/gui/torrentcontentmodel.cpp

@ -56,7 +56,7 @@ namespace
TorrentContentModel::TorrentContentModel(QObject *parent) TorrentContentModel::TorrentContentModel(QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority") }))) , m_rootItem(new TorrentContentModelFolder(QList<QVariant>({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining") })))
{ {
} }

1
src/gui/torrentcontentmodelfile.cpp

@ -69,5 +69,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
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));
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);
} }

3
src/gui/torrentcontentmodelfolder.cpp

@ -138,17 +138,20 @@ void TorrentContentModelFolder::recalculateProgress()
{ {
qreal tProgress = 0; qreal tProgress = 0;
qulonglong tSize = 0; qulonglong tSize = 0;
qulonglong tRemaining = 0;
foreach (TorrentContentModelItem* child, m_childItems) { foreach (TorrentContentModelItem* child, m_childItems) {
if (child->priority() != prio::IGNORED) { if (child->priority() != prio::IGNORED) {
if (child->itemType() == FolderType) if (child->itemType() == FolderType)
static_cast<TorrentContentModelFolder*>(child)->recalculateProgress(); static_cast<TorrentContentModelFolder*>(child)->recalculateProgress();
tProgress += child->progress() * child->size(); tProgress += child->progress() * child->size();
tSize += child->size(); tSize += child->size();
tRemaining += child->remaining();
} }
} }
if (!isRootItem() && tSize > 0) { if (!isRootItem() && tSize > 0) {
m_progress = tProgress / tSize; m_progress = tProgress / tSize;
m_remaining = tRemaining;
Q_ASSERT(m_progress <= 1.); Q_ASSERT(m_progress <= 1.);
} }
} }

11
src/gui/torrentcontentmodelitem.cpp

@ -37,6 +37,7 @@
TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent) TorrentContentModelItem::TorrentContentModelItem(TorrentContentModelFolder* parent)
: m_parentItem(parent) : m_parentItem(parent)
, m_size(0) , m_size(0)
, m_remaining(0)
, m_priority(prio::NORMAL) , m_priority(prio::NORMAL)
, m_progress(0) , m_progress(0)
{ {
@ -75,6 +76,14 @@ qreal TorrentContentModelItem::progress() const
return 1; return 1;
} }
qulonglong TorrentContentModelItem::remaining() const
{
Q_ASSERT(!isRootItem());
if (m_priority == prio::IGNORED) return 0;
return m_remaining;
}
int TorrentContentModelItem::priority() const int TorrentContentModelItem::priority() const
{ {
Q_ASSERT(!isRootItem()); Q_ASSERT(!isRootItem());
@ -100,6 +109,8 @@ QVariant TorrentContentModelItem::data(int column) const
return progress(); return progress();
case COL_SIZE: case COL_SIZE:
return m_size; return m_size;
case COL_REMAINING:
return remaining();
default: default:
Q_ASSERT(false); Q_ASSERT(false);
return QVariant(); return QVariant();

4
src/gui/torrentcontentmodelitem.h

@ -42,7 +42,7 @@ class TorrentContentModelFolder;
class TorrentContentModelItem { class TorrentContentModelItem {
public: public:
enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, NB_COL}; enum TreeItemColumns {COL_NAME, COL_SIZE, COL_PROGRESS, COL_PRIO, COL_REMAINING, NB_COL};
enum ItemType { FileType, FolderType }; enum ItemType { FileType, FolderType };
TorrentContentModelItem(TorrentContentModelFolder* parent); TorrentContentModelItem(TorrentContentModelFolder* parent);
@ -57,6 +57,7 @@ public:
qulonglong size() const; qulonglong size() const;
qreal progress() const; qreal progress() 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 new_prio, bool update_parent = true) = 0;
@ -72,6 +73,7 @@ protected:
// Non-root item members // Non-root item members
QString m_name; QString m_name;
qulonglong m_size; qulonglong m_size;
qulonglong m_remaining;
int m_priority; int m_priority;
qreal m_progress; qreal m_progress;
}; };

Loading…
Cancel
Save