Browse Source

Improve column updates granularity

PR #17806.
adaptive-webui-19844
Chocobo1 2 years ago committed by GitHub
parent
commit
9a81cbf4c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      src/gui/torrentcontentmodel.cpp
  2. 5
      src/gui/torrentcontentmodel.h

63
src/gui/torrentcontentmodel.cpp

@ -220,7 +220,12 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp) @@ -220,7 +220,12 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
// Update folders progress in the tree
m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability();
notifyModelUpdate(index(0, 0));
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_PROGRESS, TorrentContentModelItem::COL_PROGRESS}
};
notifySubtreeUpdated(index(0, 0), columns);
}
void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::DownloadPriority> &fprio)
@ -233,7 +238,13 @@ void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::Downlo @@ -233,7 +238,13 @@ void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::Downlo
emit layoutAboutToBeChanged();
for (int i = 0; i < fprio.size(); ++i)
m_filesIndex[i]->setPriority(static_cast<BitTorrent::DownloadPriority>(fprio[i]));
notifyModelUpdate(index(0, 0));
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME},
{TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO}
};
notifySubtreeUpdated(index(0, 0), columns);
}
void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
@ -247,7 +258,12 @@ void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa) @@ -247,7 +258,12 @@ void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
m_filesIndex[i]->setAvailability(fa[i]);
// Update folders progress in the tree
m_rootItem->recalculateProgress();
notifyModelUpdate(index(0, 0));
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_AVAILABILITY, TorrentContentModelItem::COL_AVAILABILITY}
};
notifySubtreeUpdated(index(0, 0), columns);
}
QVector<BitTorrent::DownloadPriority> TorrentContentModel::getFilePriorities() const
@ -297,7 +313,12 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu @@ -297,7 +313,12 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability();
notifyModelUpdate(index);
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME},
{TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO}
};
notifySubtreeUpdated(index, columns);
emit filteredFilesChanged();
return true;
@ -331,7 +352,13 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu @@ -331,7 +352,13 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
{
item->setPriority(newPrio);
notifyModelUpdate(index);
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME},
{TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO}
};
notifySubtreeUpdated(index, columns);
if ((newPrio == BitTorrent::DownloadPriority::Ignored)
|| (currentPrio == BitTorrent::DownloadPriority::Ignored))
{
@ -564,20 +591,22 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage & @@ -564,20 +591,22 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage &
emit layoutChanged();
}
void TorrentContentModel::notifyModelUpdate(const QModelIndex &index)
void TorrentContentModel::notifySubtreeUpdated(const QModelIndex &index, const QVector<ColumnInterval> &columns)
{
Q_ASSERT(index.isValid());
// For best performance, `columns` entries should be arranged from left to right
const int lastColumnIndex = columnCount(index) - 1;
Q_ASSERT(index.isValid());
// emit itself
emit dataChanged(index.siblingAtColumn(0), index.siblingAtColumn(lastColumnIndex));
for (const ColumnInterval &column : columns)
emit dataChanged(index.siblingAtColumn(column.first()), index.siblingAtColumn(column.last()));
// propagate up the model
QModelIndex parentIndex = parent(index);
while (parentIndex.isValid())
{
emit dataChanged(parentIndex.siblingAtColumn(0), parentIndex.siblingAtColumn(lastColumnIndex));
for (const ColumnInterval &column : columns)
emit dataChanged(parentIndex.siblingAtColumn(column.first()), parentIndex.siblingAtColumn(column.last()));
parentIndex = parent(parentIndex);
}
@ -592,19 +621,23 @@ void TorrentContentModel::notifyModelUpdate(const QModelIndex &index) @@ -592,19 +621,23 @@ void TorrentContentModel::notifyModelUpdate(const QModelIndex &index)
const QModelIndex parent = parentIndexes.takeLast();
const int childCount = rowCount(parent);
const QModelIndex childTopLeft = this->index(0, 0, parent);
const QModelIndex childBottomRight = this->index((childCount - 1), lastColumnIndex, parent);
const QModelIndex child = this->index(0, 0, parent);
// emit this generation
for (const ColumnInterval &column : columns)
{
const QModelIndex childTopLeft = child.siblingAtColumn(column.first());
const QModelIndex childBottomRight = child.sibling((childCount - 1), column.last());
emit dataChanged(childTopLeft, childBottomRight);
}
// check generations further down
parentIndexes.reserve(childCount);
for (int i = 0; i < childCount; ++i)
{
const QModelIndex child = childTopLeft.siblingAtRow(i);
if (hasChildren(child))
parentIndexes.push_back(child);
const QModelIndex sibling = child.siblingAtRow(i);
if (hasChildren(sibling))
parentIndexes.push_back(sibling);
}
}
}

5
src/gui/torrentcontentmodel.h

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#include <QAbstractItemModel>
#include <QVector>
#include "base/indexrange.h"
#include "torrentcontentmodelitem.h"
class QFileIconProvider;
@ -80,7 +81,9 @@ signals: @@ -80,7 +81,9 @@ signals:
void filteredFilesChanged();
private:
void notifyModelUpdate(const QModelIndex &index);
using ColumnInterval = IndexInterval<int>;
void notifySubtreeUpdated(const QModelIndex &index, const QVector<ColumnInterval> &columns);
TorrentContentModelFolder *m_rootItem = nullptr;
QVector<TorrentContentModelFile *> m_filesIndex;

Loading…
Cancel
Save