From 0f82c169362cd2e26c053725d3b8fae3889f1655 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 10 Nov 2022 13:23:54 +0300 Subject: [PATCH] Use another workaround to update files tree view --- src/gui/torrentcontentmodel.cpp | 87 +++------------------------------ src/gui/torrentcontentmodel.h | 4 -- 2 files changed, 7 insertions(+), 84 deletions(-) diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index de1042259..58d8c7b16 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -221,11 +221,7 @@ void TorrentContentModel::updateFilesProgress(const QVector &fp) m_rootItem->recalculateProgress(); m_rootItem->recalculateAvailability(); - const QVector columns = - { - {TorrentContentModelItem::COL_PROGRESS, TorrentContentModelItem::COL_PROGRESS} - }; - notifySubtreeUpdated(index(0, 0), columns); + emit layoutChanged(); } void TorrentContentModel::updateFilesPriorities(const QVector &fprio) @@ -239,12 +235,7 @@ void TorrentContentModel::updateFilesPriorities(const QVectorsetPriority(static_cast(fprio[i])); - const QVector columns = - { - {TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME}, - {TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO} - }; - notifySubtreeUpdated(index(0, 0), columns); + emit layoutChanged(); } void TorrentContentModel::updateFilesAvailability(const QVector &fa) @@ -259,11 +250,7 @@ void TorrentContentModel::updateFilesAvailability(const QVector &fa) // Update folders progress in the tree m_rootItem->recalculateProgress(); - const QVector columns = - { - {TorrentContentModelItem::COL_AVAILABILITY, TorrentContentModelItem::COL_AVAILABILITY} - }; - notifySubtreeUpdated(index(0, 0), columns); + emit layoutChanged(); } QVector TorrentContentModel::getFilePriorities() const @@ -308,17 +295,13 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu if (currentPrio != newPrio) { + emit layoutAboutToBeChanged(); item->setPriority(newPrio); // Update folders progress in the tree m_rootItem->recalculateProgress(); m_rootItem->recalculateAvailability(); - const QVector columns = - { - {TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME}, - {TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO} - }; - notifySubtreeUpdated(index, columns); + emit layoutChanged(); emit filteredFilesChanged(); return true; @@ -350,14 +333,9 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu const auto newPrio = static_cast(value.toInt()); if (currentPrio != newPrio) { + emit layoutAboutToBeChanged(); item->setPriority(newPrio); - - const QVector columns = - { - {TorrentContentModelItem::COL_NAME, TorrentContentModelItem::COL_NAME}, - {TorrentContentModelItem::COL_PRIO, TorrentContentModelItem::COL_PRIO} - }; - notifySubtreeUpdated(index, columns); + emit layoutChanged(); if ((newPrio == BitTorrent::DownloadPriority::Ignored) || (currentPrio == BitTorrent::DownloadPriority::Ignored)) @@ -590,54 +568,3 @@ void TorrentContentModel::setupModelData(const BitTorrent::AbstractFileStorage & } emit layoutChanged(); } - -void TorrentContentModel::notifySubtreeUpdated(const QModelIndex &index, const QVector &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 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); - } - } -} diff --git a/src/gui/torrentcontentmodel.h b/src/gui/torrentcontentmodel.h index 481cf2ead..84f00976a 100644 --- a/src/gui/torrentcontentmodel.h +++ b/src/gui/torrentcontentmodel.h @@ -81,10 +81,6 @@ signals: void filteredFilesChanged(); private: - using ColumnInterval = IndexInterval; - - void notifySubtreeUpdated(const QModelIndex &index, const QVector &columns); - TorrentContentModelFolder *m_rootItem = nullptr; QVector m_filesIndex; QFileIconProvider *m_fileIconProvider = nullptr;