mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Merge pull request #4451 from netjunki/master
add a remaining column to the torrent content model
This commit is contained in:
commit
89b334d71c
@ -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;
|
||||||
|
@ -45,7 +45,8 @@ enum PropColumn
|
|||||||
NAME,
|
NAME,
|
||||||
PCSIZE,
|
PCSIZE,
|
||||||
PROGRESS,
|
PROGRESS,
|
||||||
PRIORITY
|
PRIORITY,
|
||||||
|
REMAINING
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropListDelegate : public QItemDelegate
|
class PropListDelegate : public QItemDelegate
|
||||||
|
@ -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") })))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.);
|
||||||
}
|
}
|
||||||
|
@ -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.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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…
Reference in New Issue
Block a user