From 27708d5964d8ac2e058e525f77f72d37d96a08b9 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Sun, 16 Nov 2025 01:37:07 +0100 Subject: [PATCH] Adjust to proxy model indices (#6324) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Took 12 minutes Co-authored-by: Lukas BrĂ¼bach --- .../deck_editor_deck_dock_widget.cpp | 25 ++++++++++++------- .../deck_editor_deck_dock_widget.h | 2 ++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp index 77086cccc..525699e6d 100644 --- a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp +++ b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.cpp @@ -34,7 +34,7 @@ void DeckEditorDeckDockWidget::createDeckDock() deckLoader = new DeckLoader(this, deckModel->getDeckList()); - DeckListStyleProxy *proxy = new DeckListStyleProxy(this); + proxy = new DeckListStyleProxy(this); proxy->setSourceModel(deckModel); deckView = new QTreeView(); @@ -434,7 +434,9 @@ QModelIndexList DeckEditorDeckDockWidget::getSelectedCardNodes() const { auto selectedRows = deckView->selectionModel()->selectedRows(); - const auto notLeafNode = [this](const auto &index) { return deckModel->hasChildren(index); }; + const auto notLeafNode = [this](const QModelIndex &index) { + return deckModel->hasChildren(proxy->mapToSource(index)); + }; selectedRows.erase(std::remove_if(selectedRows.begin(), selectedRows.end(), notLeafNode), selectedRows.end()); std::reverse(selectedRows.begin(), selectedRows.end()); @@ -501,7 +503,7 @@ bool DeckEditorDeckDockWidget::swapCard(const QModelIndex ¤tIndex) QModelIndex newCardIndex = card ? deckModel->addCard(card, otherZoneName) // Third argument (true) says create the card no matter what, even if not in DB : deckModel->addPreferredPrintingCard(cardName, otherZoneName, true); - recursiveExpand(newCardIndex); + recursiveExpand(proxy->mapToSource(newCardIndex)); return true; } @@ -522,7 +524,7 @@ void DeckEditorDeckDockWidget::actDecrementCard(const ExactCard &card, QString z } deckView->clearSelection(); - deckView->setCurrentIndex(idx); + deckView->setCurrentIndex(proxy->mapToSource(idx)); offsetCountAtIndex(idx, -1); } @@ -558,7 +560,8 @@ void DeckEditorDeckDockWidget::actRemoveCard() if (!index.isValid() || deckModel->hasChildren(index)) { continue; } - deckModel->removeRow(index.row(), index.parent()); + QModelIndex sourceIndex = proxy->mapToSource(index); + deckModel->removeRow(sourceIndex.row(), sourceIndex.parent()); isModified = true; } @@ -575,13 +578,17 @@ void DeckEditorDeckDockWidget::offsetCountAtIndex(const QModelIndex &idx, int of return; } - const QModelIndex numberIndex = idx.sibling(idx.row(), 0); + QModelIndex sourceIndex = proxy->mapToSource(idx); + + const QModelIndex numberIndex = sourceIndex.sibling(sourceIndex.row(), 0); const int count = deckModel->data(numberIndex, Qt::EditRole).toInt(); const int new_count = count + offset; - if (new_count <= 0) - deckModel->removeRow(idx.row(), idx.parent()); - else + + if (new_count <= 0) { + deckModel->removeRow(sourceIndex.row(), sourceIndex.parent()); + } else { deckModel->setData(numberIndex, new_count, Qt::EditRole); + } emit deckModified(); } diff --git a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h index 90b6f9797..d4703a5dc 100644 --- a/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h +++ b/cockatrice/src/interface/widgets/deck_editor/deck_editor_deck_dock_widget.h @@ -12,6 +12,7 @@ #include "../../key_signals.h" #include "../utility/custom_line_edit.h" #include "../visual_deck_storage/deck_preview/deck_preview_deck_tags_display_widget.h" +#include "deck_list_style_proxy.h" #include #include @@ -28,6 +29,7 @@ class DeckEditorDeckDockWidget : public QDockWidget public: explicit DeckEditorDeckDockWidget(AbstractTabDeckEditor *parent); DeckLoader *deckLoader; + DeckListStyleProxy *proxy; DeckListModel *deckModel; QTreeView *deckView; QComboBox *bannerCardComboBox;