From 229033f2d66cf52ce6c447bffd968f0bb8a17b64 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Wed, 30 Dec 2020 14:56:41 +0100 Subject: Remove debug for not-checkable row in grouping proxy (happens with backups for instance). --- src/qtgroupingproxy.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/qtgroupingproxy.cpp') diff --git a/src/qtgroupingproxy.cpp b/src/qtgroupingproxy.cpp index ff9539d7..2c997fe9 100644 --- a/src/qtgroupingproxy.cpp +++ b/src/qtgroupingproxy.cpp @@ -721,7 +721,6 @@ QtGroupingProxy::flags( const QModelIndex &idx ) const m_rootNode.parent() ); if ( (originalIdx.flags() & Qt::ItemIsUserCheckable) == 0 ) { - log::debug("row {} is not checkable", originalRow); checkable = false; } } -- cgit v1.3.1 From 85cd33715723f294abeeb8a0f3f77c0de27f6a37 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 4 Jan 2021 19:06:43 +0100 Subject: Disable proxies when they are not used. --- src/modlistbypriorityproxy.cpp | 9 +++-- src/modlistsortproxy.cpp | 6 ++-- src/modlistview.cpp | 53 ++++++++++++++++++------------ src/qtgroupingproxy.cpp | 74 +++++++++++++++++++++++++----------------- src/qtgroupingproxy.h | 7 ++-- 5 files changed, 90 insertions(+), 59 deletions(-) (limited to 'src/qtgroupingproxy.cpp') diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index 749991d0..bf3c2d09 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -18,12 +18,15 @@ ModListByPriorityProxy::~ModListByPriorityProxy() void ModListByPriorityProxy::setSourceModel(QAbstractItemModel* model) { + if (sourceModel()) { + disconnect(sourceModel(), nullptr, this, nullptr); + } + QAbstractProxyModel::setSourceModel(model); if (sourceModel()) { - m_CollapsedItems.clear(); - connect(sourceModel(), &QAbstractItemModel::layoutChanged, this, [this]() { buildTree(); }, Qt::UniqueConnection); - connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, [this]() { buildTree(); }, Qt::UniqueConnection); + connect(sourceModel(), &QAbstractItemModel::layoutChanged, this, &ModListByPriorityProxy::buildTree, Qt::UniqueConnection); + connect(sourceModel(), &QAbstractItemModel::rowsRemoved, this, &ModListByPriorityProxy::buildTree, Qt::UniqueConnection); connect(sourceModel(), &QAbstractItemModel::modelReset, this, &ModListByPriorityProxy::buildTree, Qt::UniqueConnection); connect(sourceModel(), &QAbstractItemModel::dataChanged, this, &ModListByPriorityProxy::modelDataChanged, Qt::UniqueConnection); refresh(); diff --git a/src/modlistsortproxy.cpp b/src/modlistsortproxy.cpp index 054b980c..9ae37a43 100644 --- a/src/modlistsortproxy.cpp +++ b/src/modlistsortproxy.cpp @@ -652,8 +652,10 @@ void ModListSortProxy::setSourceModel(QAbstractItemModel *sourceModel) if (proxy != nullptr) { sourceModel = proxy->sourceModel(); } - connect(sourceModel, SIGNAL(aboutToChangeData()), this, SLOT(aboutToChangeData()), Qt::UniqueConnection); - connect(sourceModel, SIGNAL(postDataChanged()), this, SLOT(postDataChanged()), Qt::UniqueConnection); + if (sourceModel) { + connect(sourceModel, SIGNAL(aboutToChangeData()), this, SLOT(aboutToChangeData()), Qt::UniqueConnection); + connect(sourceModel, SIGNAL(postDataChanged()), this, SLOT(postDataChanged()), Qt::UniqueConnection); + } } void ModListSortProxy::aboutToChangeData() diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 2edcf56e..6399e910 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -631,6 +631,18 @@ bool ModListView::toggleSelectionState() return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows())); } +// helper function because QtGroupingProxy and ModListByPriorityProxy +// have similar methods but do not share a common parent class +template +void setProxy(OrganizerCore* core, QTreeView* view, ModListSortProxy* sortProxy, Proxy* proxy) +{ + proxy->setSourceModel(core->modList()); + sortProxy->setSourceModel(proxy); + QObject::connect(view, &QTreeView::expanded, proxy, &Proxy::expanded); + QObject::connect(view, &QTreeView::collapsed, proxy, &Proxy::collapsed); + proxy->refreshExpandedItems(); +} + void ModListView::updateGroupByProxy(int groupIndex) { // if the index is -1, we do not refresh unless we are grouping @@ -642,18 +654,18 @@ void ModListView::updateGroupByProxy(int groupIndex) groupIndex = ui.groupBy->currentIndex(); } + auto* previousModel = m_sortProxy->sourceModel(); + if (groupIndex == GroupBy::CATEGORY) { - m_byCategoryProxy->setGroupedColumn(ModList::COL_CATEGORY); - m_sortProxy->setSourceModel(m_byCategoryProxy); + setProxy(m_core, this, m_sortProxy, m_byCategoryProxy); } else if (groupIndex == GroupBy::NEXUS_ID) { - m_byNexusIdProxy->setGroupedColumn(ModList::COL_MODID); - m_sortProxy->setSourceModel(m_byNexusIdProxy); + setProxy(m_core, this, m_sortProxy, m_byNexusIdProxy); } else if (m_core->settings().interface().collapsibleSeparators() && m_sortProxy->sortColumn() == ModList::COL_PRIORITY && m_sortProxy->sortOrder() == Qt::AscendingOrder) { - m_sortProxy->setSourceModel(m_byPriorityProxy); + setProxy(m_core, this, m_sortProxy, m_byPriorityProxy); } else { m_sortProxy->setSourceModel(m_core->modList()); @@ -661,12 +673,21 @@ void ModListView::updateGroupByProxy(int groupIndex) if (hasCollapsibleSeparators()) { ui.filterSeparators->setCurrentIndex(ModListSortProxy::SeparatorFilter); - m_byPriorityProxy->refresh(); ui.filterSeparators->setEnabled(false); } else { ui.filterSeparators->setEnabled(true); } + + // reset the source model of the old proxy because we do not want to + // react to signals + // + // also stop notifying the old proxy when items are expanded + // + if (auto* proxy = qobject_cast(previousModel)) { + proxy->setSourceModel(nullptr); + disconnect(this, nullptr, proxy, nullptr); + } } void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindow* mw, Ui::MainWindow* mwui) @@ -688,22 +709,12 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo connect(core.modList(), &ModList::modelReset, [=] { clearOverwriteMarkers(); }); m_byPriorityProxy = new ModListByPriorityProxy(core.currentProfile(), core, this); - m_byPriorityProxy->setSourceModel(core.modList()); - connect(this, &QTreeView::expanded, [=](auto&& name) { m_byPriorityProxy->expanded(name); }); - connect(this, &QTreeView::collapsed, [=](auto&& name) { m_byPriorityProxy->collapsed(name); }); connect(m_byPriorityProxy, &ModListByPriorityProxy::expandItem, [=](auto&& index) { expandItem(index); }); - - m_byCategoryProxy = new QtGroupingProxy(core.modList(), QModelIndex(), ModList::COL_CATEGORY, - ModList::GroupingRole, 0, ModList::AggrRole); - connect(this, &QTreeView::expanded, m_byCategoryProxy, &QtGroupingProxy::expanded); - connect(this, &QTreeView::collapsed, m_byCategoryProxy, &QtGroupingProxy::collapsed); - connect(m_byCategoryProxy, &QtGroupingProxy::expandItem, this, &ModListView::expandItem); - m_byNexusIdProxy = new QtGroupingProxy(core.modList(), QModelIndex(), ModList::COL_MODID, - ModList::GroupingRole, QtGroupingProxy::FLAG_NOGROUPNAME | QtGroupingProxy::FLAG_NOSINGLE, - ModList::AggrRole); - connect(this, &QTreeView::expanded, m_byNexusIdProxy, &QtGroupingProxy::expanded); - connect(this, &QTreeView::collapsed, m_byNexusIdProxy, &QtGroupingProxy::collapsed); - connect(m_byNexusIdProxy, &QtGroupingProxy::expandItem, this, &ModListView::expandItem); + m_byCategoryProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_CATEGORY, ModList::GroupingRole, 0, ModList::AggrRole); + connect(m_byCategoryProxy, &QtGroupingProxy::expandItem, [=](auto&& index) { expandItem(index); }); + m_byNexusIdProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_MODID, + ModList::GroupingRole, QtGroupingProxy::FLAG_NOGROUPNAME | QtGroupingProxy::FLAG_NOSINGLE, ModList::AggrRole); + connect(m_byNexusIdProxy, &QtGroupingProxy::expandItem, [=](auto&& index) { expandItem(index); }); m_sortProxy = new ModListSortProxy(core.currentProfile(), &core); setModel(m_sortProxy); diff --git a/src/qtgroupingproxy.cpp b/src/qtgroupingproxy.cpp index 2c997fe9..3daa66ba 100644 --- a/src/qtgroupingproxy.cpp +++ b/src/qtgroupingproxy.cpp @@ -34,42 +34,50 @@ using namespace MOBase; \ingroup model-view */ -QtGroupingProxy::QtGroupingProxy(QAbstractItemModel *model, QModelIndex rootNode, int groupedColumn, int groupedRole, unsigned int flags , int aggregateRole) +QtGroupingProxy::QtGroupingProxy(QModelIndex rootNode, int groupedColumn, int groupedRole, unsigned int flags, int aggregateRole) : QAbstractProxyModel() - , m_rootNode( rootNode ) - , m_groupedColumn( 0 ) - , m_groupedRole( groupedRole ) - , m_aggregateRole( aggregateRole ) - , m_flags( flags ) + , m_rootNode(rootNode) + , m_groupedColumn(0) + , m_groupedRole(groupedRole) + , m_aggregateRole(aggregateRole) + , m_flags(flags) { - setSourceModel( model ); - - // signal proxies - connect( sourceModel(), - SIGNAL( dataChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( modelDataChanged( const QModelIndex&, const QModelIndex& ) ) - ); - connect( sourceModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ), - SLOT( modelRowsInserted( const QModelIndex &, int, int ) ) ); - connect( sourceModel(), SIGNAL(rowsAboutToBeInserted( const QModelIndex &, int ,int )), - SLOT(modelRowsAboutToBeInserted( const QModelIndex &, int ,int ))); - connect( sourceModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ), - SLOT( modelRowsRemoved( const QModelIndex&, int, int ) ) ); - connect( sourceModel(), SIGNAL(rowsAboutToBeRemoved( const QModelIndex &, int ,int )), - SLOT(modelRowsAboutToBeRemoved(QModelIndex,int,int)) ); - connect( sourceModel(), SIGNAL(layoutChanged()), SLOT(buildTree()) ); - connect( sourceModel(), SIGNAL(dataChanged(QModelIndex,QModelIndex)), - SLOT(modelDataChanged(QModelIndex,QModelIndex)) ); - connect( sourceModel(), SIGNAL(modelReset()), this, SLOT(resetModel()) ); - - if( groupedColumn != -1 ) - setGroupedColumn( groupedColumn ); + if (groupedColumn != -1) { + setGroupedColumn(groupedColumn); + } } QtGroupingProxy::~QtGroupingProxy() { } +void QtGroupingProxy::setSourceModel(QAbstractItemModel* model) +{ + if (sourceModel()) { + disconnect(sourceModel(), nullptr, this, nullptr); + } + + QAbstractProxyModel::setSourceModel(model); + + if (sourceModel()) { + // signal proxies + connect(sourceModel(), SIGNAL(rowsInserted(const QModelIndex&, int, int)), + SLOT(modelRowsInserted(const QModelIndex&, int, int))); + connect(sourceModel(), SIGNAL(rowsAboutToBeInserted(const QModelIndex&, int, int)), + SLOT(modelRowsAboutToBeInserted(const QModelIndex&, int, int))); + connect(sourceModel(), SIGNAL(rowsRemoved(const QModelIndex&, int, int)), + SLOT(modelRowsRemoved(const QModelIndex&, int, int))); + connect(sourceModel(), SIGNAL(rowsAboutToBeRemoved(const QModelIndex&, int, int)), + SLOT(modelRowsAboutToBeRemoved(QModelIndex, int, int))); + connect(sourceModel(), SIGNAL(layoutChanged()), SLOT(buildTree())); + connect(sourceModel(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), + SLOT(modelDataChanged(QModelIndex, QModelIndex))); + connect(sourceModel(), SIGNAL(modelReset()), this, SLOT(resetModel())); + + buildTree(); + } +} + void QtGroupingProxy::setGroupedColumn( int groupedColumn ) { @@ -205,9 +213,15 @@ QtGroupingProxy::buildTree() } endResetModel(); + // restore expand-state - for( int row = 0; row < rowCount(); row++ ) { - QModelIndex idx = index( row, 0, QModelIndex() ); + refreshExpandedItems(); +} + +void QtGroupingProxy::refreshExpandedItems() const +{ + for (int row = 0; row < rowCount(); row++) { + QModelIndex idx = index(row, 0, QModelIndex()); if (m_expandedItems.contains(idx.data(Qt::UserRole).toString())) { emit expandItem(idx); } diff --git a/src/qtgroupingproxy.h b/src/qtgroupingproxy.h index 6567cb0e..131f33dc 100644 --- a/src/qtgroupingproxy.h +++ b/src/qtgroupingproxy.h @@ -47,12 +47,13 @@ public: }; public: - explicit QtGroupingProxy( QAbstractItemModel *model, QModelIndex rootNode = QModelIndex(), + explicit QtGroupingProxy( QModelIndex rootNode = QModelIndex(), int groupedColumn = -1, int groupedRole = Qt::DisplayRole, unsigned int flags = 0, int aggregateRole = Qt::DisplayRole); ~QtGroupingProxy(); + void setSourceModel(QAbstractItemModel* model) override; void setGroupedColumn( int groupedColumn ); /* QAbstractProxyModel methods */ @@ -79,10 +80,10 @@ public: virtual QModelIndex addEmptyGroup( const RowData &data ); virtual bool removeGroup( const QModelIndex &idx ); - QStringList expandedState(); + void refreshExpandedItems() const ; signals: - void expandItem(const QModelIndex &index); + void expandItem(const QModelIndex &index) const; public slots: /** -- cgit v1.3.1 From b242394c0f9c24ca8f9bbced44076abbcd274fee Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 4 Jan 2021 19:37:20 +0100 Subject: Keep track of expanded items in the view instead of the models. --- src/modlistbypriorityproxy.cpp | 32 --------------------- src/modlistbypriorityproxy.h | 13 +-------- src/modlistview.cpp | 63 +++++++++++++++++++++--------------------- src/modlistview.h | 11 ++++++-- src/qtgroupingproxy.cpp | 24 ---------------- src/qtgroupingproxy.h | 17 ------------ 6 files changed, 40 insertions(+), 120 deletions(-) (limited to 'src/qtgroupingproxy.cpp') diff --git a/src/modlistbypriorityproxy.cpp b/src/modlistbypriorityproxy.cpp index bf3c2d09..6f549d91 100644 --- a/src/modlistbypriorityproxy.cpp +++ b/src/modlistbypriorityproxy.cpp @@ -88,20 +88,6 @@ void ModListByPriorityProxy::buildTree() m_Root.children.push_back(std::move(overwrite)); endResetModel(); - - // restore expand-state - expandItems(QModelIndex()); -} - -void ModListByPriorityProxy::expandItems(const QModelIndex& index) const -{ - for (int row = 0; row < rowCount(index); row++) { - QModelIndex idx = this->index(row, 0, index); - if (!m_CollapsedItems.contains(idx.data(Qt::DisplayRole).toString())) { - emit expandItem(idx); - } - expandItems(idx); - } } void ModListByPriorityProxy::modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles) @@ -334,21 +320,3 @@ void ModListByPriorityProxy::onDropEnter(const QMimeData*, ModListView::DropPosi { m_dropPosition = dropPosition; } - -void ModListByPriorityProxy::refreshExpandedItems() const -{ - expandItems(QModelIndex()); -} - -void ModListByPriorityProxy::expanded(const QModelIndex& index) -{ - auto it = m_CollapsedItems.find(index.data(Qt::DisplayRole).toString()); - if (it != m_CollapsedItems.end()) { - m_CollapsedItems.erase(it); - } -} - -void ModListByPriorityProxy::collapsed(const QModelIndex& index) -{ - m_CollapsedItems.insert(index.data(Qt::DisplayRole).toString()); -} diff --git a/src/modlistbypriorityproxy.h b/src/modlistbypriorityproxy.h index e5a8adff..6b48678a 100644 --- a/src/modlistbypriorityproxy.h +++ b/src/modlistbypriorityproxy.h @@ -44,28 +44,17 @@ public: QModelIndex mapFromSource(const QModelIndex& sourceIndex) const override; QModelIndex mapToSource(const QModelIndex& proxyIndex) const override; - // check the internal state for expanded/collapse items and emit a expandItem - // signal for each of the expanded item, useful to refresh the tree state after - // layout modification - void refreshExpandedItems() const; - -signals: - void expandItem(const QModelIndex& index) const; - public slots: void onDropEnter(const QMimeData* data, ModListView::DropPosition dropPosition); - void expanded(const QModelIndex& index); - void collapsed(const QModelIndex& index); -protected: +protected slots: void modelDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector& roles = QVector()); private: void buildTree(); - void expandItems(const QModelIndex& index) const; struct TreeItem { ModInfo::Ptr mod; diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 6399e910..67dc1c02 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -360,15 +360,14 @@ void ModListView::setSelected(const QModelIndex& current, const QModelIndexList& } } -void ModListView::expandItem(const QModelIndex& index) +void ModListView::refreshExpandedItems() { - // the group proxy (QtGroupingProxy and ModListByPriorityProxy) emit - // those with their own index, so we need to do this manually - if (index.model() == m_sortProxy->sourceModel()) { - setExpanded(m_sortProxy->mapFromSource(index), true); - } - else if (index.model() == model()) { - setExpanded(index, true); + auto* model = m_sortProxy->sourceModel(); + for (auto i = 0; i < model->rowCount(); ++i) { + auto idx = model->index(i, 0); + if (!m_collapsed[model].contains(idx.data(Qt::DisplayRole).toString())) { + setExpanded(m_sortProxy->mapFromSource(idx), true); + } } } @@ -631,18 +630,6 @@ bool ModListView::toggleSelectionState() return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows())); } -// helper function because QtGroupingProxy and ModListByPriorityProxy -// have similar methods but do not share a common parent class -template -void setProxy(OrganizerCore* core, QTreeView* view, ModListSortProxy* sortProxy, Proxy* proxy) -{ - proxy->setSourceModel(core->modList()); - sortProxy->setSourceModel(proxy); - QObject::connect(view, &QTreeView::expanded, proxy, &Proxy::expanded); - QObject::connect(view, &QTreeView::collapsed, proxy, &Proxy::collapsed); - proxy->refreshExpandedItems(); -} - void ModListView::updateGroupByProxy(int groupIndex) { // if the index is -1, we do not refresh unless we are grouping @@ -655,21 +642,29 @@ void ModListView::updateGroupByProxy(int groupIndex) } auto* previousModel = m_sortProxy->sourceModel(); + QAbstractProxyModel* nextProxy = nullptr; if (groupIndex == GroupBy::CATEGORY) { - setProxy(m_core, this, m_sortProxy, m_byCategoryProxy); + nextProxy = m_byCategoryProxy; } else if (groupIndex == GroupBy::NEXUS_ID) { - setProxy(m_core, this, m_sortProxy, m_byNexusIdProxy); + nextProxy = m_byNexusIdProxy; } else if (m_core->settings().interface().collapsibleSeparators() && m_sortProxy->sortColumn() == ModList::COL_PRIORITY && m_sortProxy->sortOrder() == Qt::AscendingOrder) { - setProxy(m_core, this, m_sortProxy, m_byPriorityProxy); + nextProxy = m_byPriorityProxy; } - else { - m_sortProxy->setSourceModel(m_core->modList()); + + QAbstractItemModel* nextModel = m_core->modList(); + if (nextProxy) { + nextProxy->setSourceModel(m_core->modList()); + nextModel = nextProxy; } + m_sortProxy->setSourceModel(nextModel); + + // expand items previously expanded + refreshExpandedItems(); if (hasCollapsibleSeparators()) { ui.filterSeparators->setCurrentIndex(ModListSortProxy::SeparatorFilter); @@ -682,11 +677,8 @@ void ModListView::updateGroupByProxy(int groupIndex) // reset the source model of the old proxy because we do not want to // react to signals // - // also stop notifying the old proxy when items are expanded - // if (auto* proxy = qobject_cast(previousModel)) { proxy->setSourceModel(nullptr); - disconnect(this, nullptr, proxy, nullptr); } } @@ -709,12 +701,19 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo connect(core.modList(), &ModList::modelReset, [=] { clearOverwriteMarkers(); }); m_byPriorityProxy = new ModListByPriorityProxy(core.currentProfile(), core, this); - connect(m_byPriorityProxy, &ModListByPriorityProxy::expandItem, [=](auto&& index) { expandItem(index); }); m_byCategoryProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_CATEGORY, ModList::GroupingRole, 0, ModList::AggrRole); - connect(m_byCategoryProxy, &QtGroupingProxy::expandItem, [=](auto&& index) { expandItem(index); }); m_byNexusIdProxy = new QtGroupingProxy(QModelIndex(), ModList::COL_MODID, ModList::GroupingRole, QtGroupingProxy::FLAG_NOGROUPNAME | QtGroupingProxy::FLAG_NOSINGLE, ModList::AggrRole); - connect(m_byNexusIdProxy, &QtGroupingProxy::expandItem, [=](auto&& index) { expandItem(index); }); + + QObject::connect(this, &QTreeView::expanded, [=](const QModelIndex& index) { + auto it = m_collapsed[m_sortProxy->sourceModel()].find(index.data(Qt::DisplayRole).toString()); + if (it != m_collapsed[m_sortProxy->sourceModel()].end()) { + m_collapsed[m_sortProxy->sourceModel()].erase(it); + } + }); + QObject::connect(this, &QTreeView::collapsed, [=](const QModelIndex& index) { + m_collapsed[m_sortProxy->sourceModel()].insert(index.data(Qt::DisplayRole).toString()); + }); m_sortProxy = new ModListSortProxy(core.currentProfile(), &core); setModel(m_sortProxy); @@ -810,7 +809,7 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo }); connect(m_sortProxy, &ModListSortProxy::filterInvalidated, [=]() { if (hasCollapsibleSeparators()) { - m_byPriorityProxy->refreshExpandedItems(); + refreshExpandedItems(); } }); } diff --git a/src/modlistview.h b/src/modlistview.h index faa33b6a..ed4ad2d0 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -1,6 +1,8 @@ #ifndef MODLISTVIEW_H #define MODLISTVIEW_H +#include +#include #include #include @@ -203,10 +205,9 @@ private: std::pair selected() const; void setSelected(const QModelIndex& current, const QModelIndexList& selected); - // call expand() after fixing the index if it comes from the source - // of the proxy + // refresh stored expanded items for the current intermediate proxy // - void expandItem(const QModelIndex& index); + void refreshExpandedItems(); // refresh the group-by proxy, if the index is -1 will refresh the // current one (e.g. when changing the sort column) @@ -249,6 +250,10 @@ private: QtGroupingProxy* m_byCategoryProxy; QtGroupingProxy* m_byNexusIdProxy; + // maintain collapsed items for each proxy to avoid + // losing them on model reset + std::map> m_collapsed; + struct MarkerInfos { // conflicts std::set overwrite; diff --git a/src/qtgroupingproxy.cpp b/src/qtgroupingproxy.cpp index 3daa66ba..a8c7ce1d 100644 --- a/src/qtgroupingproxy.cpp +++ b/src/qtgroupingproxy.cpp @@ -213,19 +213,6 @@ QtGroupingProxy::buildTree() } endResetModel(); - - // restore expand-state - refreshExpandedItems(); -} - -void QtGroupingProxy::refreshExpandedItems() const -{ - for (int row = 0; row < rowCount(); row++) { - QModelIndex idx = index(row, 0, QModelIndex()); - if (m_expandedItems.contains(idx.data(Qt::UserRole).toString())) { - emit expandItem(idx); - } - } } QList @@ -1049,14 +1036,3 @@ QtGroupingProxy::dumpGroups() const log::debug("{}", s); } - - -void QtGroupingProxy::expanded(const QModelIndex &index) -{ - m_expandedItems.insert(index.data(Qt::UserRole).toString()); -} - -void QtGroupingProxy::collapsed(const QModelIndex &index) -{ - m_expandedItems.remove(index.data(Qt::UserRole).toString()); -} diff --git a/src/qtgroupingproxy.h b/src/qtgroupingproxy.h index 131f33dc..c4459297 100644 --- a/src/qtgroupingproxy.h +++ b/src/qtgroupingproxy.h @@ -80,22 +80,6 @@ public: virtual QModelIndex addEmptyGroup( const RowData &data ); virtual bool removeGroup( const QModelIndex &idx ); - void refreshExpandedItems() const ; - -signals: - void expandItem(const QModelIndex &index) const; - -public slots: - /** - * @brief update expanded state - * @param index index of the expanded/collapsed item (from the base model!) - */ - void expanded(const QModelIndex &index); - /** - * @brief update expanded state - * @param index index of the expanded/collapsed item (from the base model!) - */ - void collapsed(const QModelIndex &index); protected slots: virtual void buildTree(); @@ -159,7 +143,6 @@ protected: void dumpGroups() const; private: - QSet m_expandedItems; unsigned int m_flags; int m_groupedRole; -- cgit v1.3.1