diff options
| author | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-05 13:14:06 +0100 |
|---|---|---|
| committer | Mikaël Capelle <capelle.mikael@gmail.com> | 2021-01-05 13:14:06 +0100 |
| commit | bcdf38f5cf24347829d3692997b56ab8a9ba3669 (patch) | |
| tree | a8de256e3c5e2b5cb2ba0c0ba017ef530d007f0b /src | |
| parent | 8685fcda318f2fc18f544ce491bb36e6132840b0 (diff) | |
Avoid switching proxy model when not necessary.
Diffstat (limited to 'src')
| -rw-r--r-- | src/modlistview.cpp | 39 | ||||
| -rw-r--r-- | src/modlistview.h | 2 |
2 files changed, 18 insertions, 23 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 57afedf6..4b285733 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -155,7 +155,7 @@ ModListView::ModListView(QWidget* parent) void ModListView::refresh()
{
- updateGroupByProxy(-1);
+ updateGroupByProxy();
}
void ModListView::setProfile(Profile* profile)
@@ -630,17 +630,9 @@ bool ModListView::toggleSelectionState() return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows()));
}
-void ModListView::updateGroupByProxy(int groupIndex)
+void ModListView::updateGroupByProxy()
{
- // if the index is -1, we do not refresh unless we are grouping
- // by separator
- if (groupIndex == -1) {
- if (ui.groupBy->currentIndex() != GroupBy::NONE) {
- return;
- }
- groupIndex = ui.groupBy->currentIndex();
- }
-
+ int groupIndex = ui.groupBy->currentIndex();
auto* previousModel = m_sortProxy->sourceModel();
QAbstractProxyModel* nextProxy = nullptr;
@@ -661,7 +653,17 @@ void ModListView::updateGroupByProxy(int groupIndex) nextProxy->setSourceModel(m_core->modList());
nextModel = nextProxy;
}
- m_sortProxy->setSourceModel(nextModel);
+
+ if (nextModel != previousModel) {
+ m_sortProxy->setSourceModel(nextModel);
+
+ // reset the source model of the old proxy because we do not want to
+ // react to signals
+ //
+ if (auto* proxy = qobject_cast<QAbstractProxyModel*>(previousModel)) {
+ proxy->setSourceModel(nullptr);
+ }
+ }
// expand items previously expanded
refreshExpandedItems();
@@ -673,13 +675,6 @@ void ModListView::updateGroupByProxy(int groupIndex) else {
ui.filterSeparators->setEnabled(true);
}
-
- // reset the source model of the old proxy because we do not want to
- // react to signals
- //
- if (auto* proxy = qobject_cast<QAbstractProxyModel*>(previousModel)) {
- proxy->setSourceModel(nullptr);
- }
}
void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindow* mw, Ui::MainWindow* mwui)
@@ -717,20 +712,20 @@ void ModListView::setup(OrganizerCore& core, CategoryFactory& factory, MainWindo connect(this, &QTreeView::collapsed, [=](const QModelIndex& index) {
m_collapsed[m_sortProxy->sourceModel()].insert(index.data(Qt::DisplayRole).toString());
});
- connect(core.modList(), &ModList::modelReset, [=] { refreshExpandedItems(); });
// the top-level proxy
m_sortProxy = new ModListSortProxy(core.currentProfile(), &core);
setModel(m_sortProxy);
+ connect(m_sortProxy, &ModList::modelReset, [=] { refreshExpandedItems(); });
// update the proxy when changing the sort column/direction and the group
connect(m_sortProxy, &QAbstractItemModel::layoutAboutToBeChanged, [this](auto&& parents, auto&& hint) {
if (hint == QAbstractItemModel::VerticalSortHint) {
- updateGroupByProxy(-1);
+ updateGroupByProxy();
}
});
connect(ui.groupBy, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index) {
- updateGroupByProxy(index);
+ updateGroupByProxy();
onModFilterActive(m_sortProxy->isFilterActive());
});
sortByColumn(ModList::COL_PRIORITY, Qt::AscendingOrder);
diff --git a/src/modlistview.h b/src/modlistview.h index ed4ad2d0..2fed4969 100644 --- a/src/modlistview.h +++ b/src/modlistview.h @@ -212,7 +212,7 @@ private: // refresh the group-by proxy, if the index is -1 will refresh the
// current one (e.g. when changing the sort column)
//
- void updateGroupByProxy(int groupIndex);
+ void updateGroupByProxy();
// index in the groupby combo
//
|
