Merge pull request #4451 from netjunki/master

add a remaining column to the torrent content model
This commit is contained in:
sledgehammer999 2016-03-05 10:42:14 -06:00
commit 89b334d71c
7 changed files with 30 additions and 3 deletions

View file

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

View file

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

View file

@ -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") })))
{
}

View file

@ -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.);
}

View file

@ -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.);
}
}

View file

@ -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
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
return progress();
case COL_SIZE:
return m_size;
case COL_REMAINING:
return remaining();
default:
Q_ASSERT(false);
return QVariant();

View file

@ -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:
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:
// Non-root item members
QString m_name;
qulonglong m_size;
qulonglong m_remaining;
int m_priority;
qreal m_progress;
};