Browse Source

Merge pull request #18038 from glassez/tree-update

Revert "Use another workaround to update files tree view"
adaptive-webui-19844
sledgehammer999 2 years ago committed by GitHub
parent
commit
17ce07230d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 87
      src/gui/torrentcontentmodel.cpp
  2. 4
      src/gui/torrentcontentmodel.h

87
src/gui/torrentcontentmodel.cpp

@ -221,7 +221,11 @@ void TorrentContentModel::updateFilesProgress(const QVector<qreal> &fp)
m_rootItem->recalculateProgress(); m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability(); m_rootItem->recalculateAvailability();
emit layoutChanged(); const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_PROGRESS, TorrentContentModelItem::COL_PROGRESS}
};
notifySubtreeUpdated(index(0, 0), columns);
} }
void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::DownloadPriority> &fprio) void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::DownloadPriority> &fprio)
@ -235,7 +239,12 @@ void TorrentContentModel::updateFilesPriorities(const QVector<BitTorrent::Downlo
for (int i = 0; i < fprio.size(); ++i) for (int i = 0; i < fprio.size(); ++i)
m_filesIndex[i]->setPriority(static_cast<BitTorrent::DownloadPriority>(fprio[i])); m_filesIndex[i]->setPriority(static_cast<BitTorrent::DownloadPriority>(fprio[i]));
emit layoutChanged(); 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) void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
@ -250,7 +259,11 @@ void TorrentContentModel::updateFilesAvailability(const QVector<qreal> &fa)
// Update folders progress in the tree // Update folders progress in the tree
m_rootItem->recalculateProgress(); m_rootItem->recalculateProgress();
emit layoutChanged(); const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_AVAILABILITY, TorrentContentModelItem::COL_AVAILABILITY}
};
notifySubtreeUpdated(index(0, 0), columns);
} }
QVector<BitTorrent::DownloadPriority> TorrentContentModel::getFilePriorities() const QVector<BitTorrent::DownloadPriority> TorrentContentModel::getFilePriorities() const
@ -295,13 +308,17 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
if (currentPrio != newPrio) if (currentPrio != newPrio)
{ {
emit layoutAboutToBeChanged();
item->setPriority(newPrio); item->setPriority(newPrio);
// Update folders progress in the tree // Update folders progress in the tree
m_rootItem->recalculateProgress(); m_rootItem->recalculateProgress();
m_rootItem->recalculateAvailability(); m_rootItem->recalculateAvailability();
emit layoutChanged(); const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME},
{TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO}
};
notifySubtreeUpdated(index, columns);
emit filteredFilesChanged(); emit filteredFilesChanged();
return true; return true;
@ -333,9 +350,14 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
const auto newPrio = static_cast<BitTorrent::DownloadPriority>(value.toInt()); const auto newPrio = static_cast<BitTorrent::DownloadPriority>(value.toInt());
if (currentPrio != newPrio) if (currentPrio != newPrio)
{ {
emit layoutAboutToBeChanged();
item->setPriority(newPrio); item->setPriority(newPrio);
emit layoutChanged();
const QVector<ColumnInterval> columns =
{
{TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME},
{TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO}
};
notifySubtreeUpdated(index, columns);
if ((newPrio == BitTorrent::DownloadPriority::Ignored) if ((newPrio == BitTorrent::DownloadPriority::Ignored)
|| (currentPrio == BitTorrent::DownloadPriority::Ignored)) || (currentPrio == BitTorrent::DownloadPriority::Ignored))
@ -570,3 +592,54 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage &
endResetModel(); endResetModel();
} }
void TorrentContentModel::notifySubtreeUpdated(const QModelIndex &index, const QVector<ColumnInterval> &columns)
{
// For best performance, `columns` entries should be arranged from left to right
Q_ASSERT(index.isValid());
// emit itself
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())
{
for (const ColumnInterval &column : columns)
emit dataChanged(parentIndex.siblingAtColumn(column.first()), parentIndex.siblingAtColumn(column.last()));
parentIndex = parent(parentIndex);
}
// propagate down the model
QVector<QModelIndex> parentIndexes;
if (hasChildren(index))
parentIndexes.push_back(index);
while (!parentIndexes.isEmpty())
{
const QModelIndex parent = parentIndexes.takeLast();
const int childCount = rowCount(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 sibling = child.siblingAtRow(i);
if (hasChildren(sibling))
parentIndexes.push_back(sibling);
}
}
}

4
src/gui/torrentcontentmodel.h

@ -81,6 +81,10 @@ signals:
void filteredFilesChanged(); void filteredFilesChanged();
private: private:
using ColumnInterval = IndexInterval<int>;
void notifySubtreeUpdated(const QModelIndex &index, const QVector<ColumnInterval> &columns);
TorrentContentModelFolder *m_rootItem = nullptr; TorrentContentModelFolder *m_rootItem = nullptr;
QVector<TorrentContentModelFile *> m_filesIndex; QVector<TorrentContentModelFile *> m_filesIndex;
QFileIconProvider *m_fileIconProvider = nullptr; QFileIconProvider *m_fileIconProvider = nullptr;

Loading…
Cancel
Save