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 @@ -67,6 +67,15 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
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:
if (index.data().toDouble() >= 0) {
QStyleOptionProgressBarV2 newopt;

3
src/gui/properties/proplistdelegate.h

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

2
src/gui/torrentcontentmodel.cpp

@ -56,7 +56,7 @@ namespace @@ -56,7 +56,7 @@ namespace
TorrentContentModel::TorrentContentModel(QObject *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) @@ -69,5 +69,6 @@ void TorrentContentModelFile::setPriority(int new_prio, bool update_parent)
void TorrentContentModelFile::setProgress(qreal progress)
{
m_progress = progress;
m_remaining = (qulonglong)(m_size * (1.0 - m_progress));
Q_ASSERT(m_progress <= 1.);
}

3
src/gui/torrentcontentmodelfolder.cpp

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

11
src/gui/torrentcontentmodelitem.cpp

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

4
src/gui/torrentcontentmodelitem.h

@ -42,7 +42,7 @@ class TorrentContentModelFolder; @@ -42,7 +42,7 @@ class TorrentContentModelFolder;
class TorrentContentModelItem {
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 };
TorrentContentModelItem(TorrentContentModelFolder* parent);
@ -57,6 +57,7 @@ public: @@ -57,6 +57,7 @@ public:
qulonglong size() const;
qreal progress() const;
qulonglong remaining() const;
int priority() const;
virtual void setPriority(int new_prio, bool update_parent = true) = 0;
@ -72,6 +73,7 @@ protected: @@ -72,6 +73,7 @@ protected:
// Non-root item members
QString m_name;
qulonglong m_size;
qulonglong m_remaining;
int m_priority;
qreal m_progress;
};

Loading…
Cancel
Save