From a19bfaa489507827dea1449991f1f5398a28beb1 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 18 Jan 2021 19:44:29 +0100 Subject: Better handling of layoutChanged in by-priority proxy to avoid resetting. --- src/modlistview.cpp | 48 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'src/modlistview.cpp') diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 763e852a..8e599e59 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -657,10 +657,6 @@ bool ModListView::moveSelection(int key) } m_core->modList()->shiftModsPriority(sourceRows, offset); - - // reset the selection and the index - setSelected(cindex, sourceRows); - return true; } @@ -682,27 +678,25 @@ void ModListView::updateGroupByProxy() { int groupIndex = ui.groupBy->currentIndex(); auto* previousModel = m_sortProxy->sourceModel(); - QAbstractProxyModel* nextProxy = nullptr; + QAbstractItemModel* nextModel = m_core->modList(); if (groupIndex == GroupBy::CATEGORY) { - nextProxy = m_byCategoryProxy; + nextModel = m_byCategoryProxy; } else if (groupIndex == GroupBy::NEXUS_ID) { - nextProxy = m_byNexusIdProxy; + nextModel = m_byNexusIdProxy; } else if (m_core->settings().interface().collapsibleSeparators(m_sortProxy->sortOrder()) && m_sortProxy->sortColumn() == ModList::COL_PRIORITY) { m_byPriorityProxy->setSortOrder(m_sortProxy->sortOrder()); - nextProxy = m_byPriorityProxy; - } - - QAbstractItemModel* nextModel = m_core->modList(); - if (nextProxy) { - nextProxy->setSourceModel(m_core->modList()); - nextModel = nextProxy; + nextModel = m_byPriorityProxy; } if (nextModel != previousModel) { + + if (auto* proxy = dynamic_cast(nextModel)) { + proxy->setSourceModel(m_core->modList()); + } m_sortProxy->setSourceModel(nextModel); // reset the source model of the old proxy because we do not want to @@ -711,17 +705,18 @@ void ModListView::updateGroupByProxy() if (auto* proxy = qobject_cast(previousModel)) { proxy->setSourceModel(nullptr); } - } - // expand items previously expanded - refreshExpandedItems(); + // expand items previously expanded + refreshExpandedItems(); + + if (hasCollapsibleSeparators()) { + ui.filterSeparators->setCurrentIndex(ModListSortProxy::SeparatorFilter); + ui.filterSeparators->setEnabled(false); + } + else { + ui.filterSeparators->setEnabled(true); + } - if (hasCollapsibleSeparators()) { - ui.filterSeparators->setCurrentIndex(ModListSortProxy::SeparatorFilter); - ui.filterSeparators->setEnabled(false); - } - else { - ui.filterSeparators->setEnabled(true); } } @@ -1356,17 +1351,10 @@ void ModListView::dropEvent(QDropEvent* event) // is no way to deduce this except using dropIndicatorPosition()) emit dropEntered(event->mimeData(), isExpanded(index), static_cast(dropIndicatorPosition())); - ModListDropInfo dropInfo(event->mimeData(), *m_core); - // see selectedIndexes() - auto [current, selected] = this->selected(); m_inDragMoveEvent = true; QTreeView::dropEvent(event); m_inDragMoveEvent = false; - - if (dropInfo.isModDrop()) { - setSelected(current, selected); - } } void ModListView::timerEvent(QTimerEvent* event) -- cgit v1.3.1 From 08110553d4b964f6977107c37e300e6fb35ecf60 Mon Sep 17 00:00:00 2001 From: Mikaël Capelle Date: Mon, 18 Jan 2021 19:50:39 +0100 Subject: Fix scrolling when moving mods with keyboard. --- src/modlistview.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/modlistview.cpp') diff --git a/src/modlistview.cpp b/src/modlistview.cpp index 8e599e59..3b0050da 100644 --- a/src/modlistview.cpp +++ b/src/modlistview.cpp @@ -657,6 +657,11 @@ bool ModListView::moveSelection(int key) } m_core->modList()->shiftModsPriority(sourceRows, offset); + + auto current = indexModelToView(key == Qt::Key_Up ? sourceRows.first() : sourceRows.last()); + selectionModel()->setCurrentIndex(current, QItemSelectionModel::NoUpdate); + scrollTo(current); + return true; } -- cgit v1.3.1