From a2af648e00ee8519429e550ea3f2f9c3afbb999c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Br=C3=BCbach=2C=20Lukas?= Date: Fri, 5 Dec 2025 04:13:59 +0100 Subject: [PATCH] [VDE] Be saner about proxy indices --- .../deck_editor/deck_editor_deck_dock_widget.cpp | 16 +++++++++++++--- .../deck_editor/deck_editor_deck_dock_widget.h | 2 ++ .../printing_selector/card_amount_widget.cpp | 4 ++-- .../printing_selector/printing_selector.cpp | 2 +- .../widgets/tabs/abstract_tab_deck_editor.cpp | 2 +- .../tab_deck_editor_visual.cpp | 4 ++-- 6 files changed, 21 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 7e4287ac5..6c1fbf996 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 @@ -588,7 +588,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(proxy->mapToSource(newCardIndex)); + recursiveExpand(proxy->mapFromSource(newCardIndex)); return true; } @@ -609,8 +609,18 @@ void DeckEditorDeckDockWidget::actDecrementCard(const ExactCard &card, QString z } deckView->clearSelection(); - deckView->setCurrentIndex(proxy->mapToSource(idx)); - offsetCountAtIndex(idx, -1); + setCurrentProxyIndex(idx); + offsetCountAtIndex(proxy->mapFromSource(idx), -1); +} + +void DeckEditorDeckDockWidget::setCurrentProxyIndex(const QModelIndex &index) +{ + deckView->setCurrentIndex(proxy->mapFromSource(index)); +} + +void DeckEditorDeckDockWidget::scrollToProxyIndex(const QModelIndex &index) +{ + deckView->setCurrentIndex(proxy->mapFromSource(index)); } void DeckEditorDeckDockWidget::actDecrementSelection() 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 d1f1da300..b6f8f114b 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 @@ -70,6 +70,8 @@ public slots: void actRemoveCard(); void offsetCountAtIndex(const QModelIndex &idx, int offset); void expandAll(); + void setCurrentProxyIndex(const QModelIndex &index); + void scrollToProxyIndex(const QModelIndex &index); signals: void nameChanged(); diff --git a/cockatrice/src/interface/widgets/printing_selector/card_amount_widget.cpp b/cockatrice/src/interface/widgets/printing_selector/card_amount_widget.cpp index 80258be61..3a815eaca 100644 --- a/cockatrice/src/interface/widgets/printing_selector/card_amount_widget.cpp +++ b/cockatrice/src/interface/widgets/printing_selector/card_amount_widget.cpp @@ -190,7 +190,7 @@ void CardAmountWidget::addPrinting(const QString &zone) newCardIndex = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(), rootCard.getPrinting().getProperty("num")); - deckView->setCurrentIndex(newCardIndex); + deckEditor->deckDockWidget->setCurrentProxyIndex(newCardIndex); deckView->setFocus(Qt::FocusReason::MouseFocusReason); deckEditor->setModified(true); } @@ -256,7 +256,7 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset) const int count = deckModel->data(numberIndex, Qt::EditRole).toInt(); const int new_count = count + offset; - deckView->setCurrentIndex(numberIndex); + deckEditor->deckDockWidget->setCurrentProxyIndex(numberIndex); if (new_count <= 0) { deckModel->removeRow(idx.row(), idx.parent()); diff --git a/cockatrice/src/interface/widgets/printing_selector/printing_selector.cpp b/cockatrice/src/interface/widgets/printing_selector/printing_selector.cpp index f27101b93..7079b6839 100644 --- a/cockatrice/src/interface/widgets/printing_selector/printing_selector.cpp +++ b/cockatrice/src/interface/widgets/printing_selector/printing_selector.cpp @@ -185,7 +185,7 @@ void PrintingSelector::selectCard(const int changeBy) } if (nextIndex.isValid()) { - deckView->setCurrentIndex(nextIndex); + deckEditor->deckDockWidget->setCurrentProxyIndex(nextIndex); deckView->setFocus(Qt::FocusReason::MouseFocusReason); } } diff --git a/cockatrice/src/interface/widgets/tabs/abstract_tab_deck_editor.cpp b/cockatrice/src/interface/widgets/tabs/abstract_tab_deck_editor.cpp index a03b79e3f..15637c4cc 100644 --- a/cockatrice/src/interface/widgets/tabs/abstract_tab_deck_editor.cpp +++ b/cockatrice/src/interface/widgets/tabs/abstract_tab_deck_editor.cpp @@ -155,7 +155,7 @@ void AbstractTabDeckEditor::addCardHelper(const ExactCard &card, QString zoneNam QModelIndex newCardIndex = deckDockWidget->deckModel->addCard(card, zoneName); deckDockWidget->expandAll(); deckDockWidget->deckView->clearSelection(); - deckDockWidget->deckView->setCurrentIndex(newCardIndex); + deckDockWidget->setCurrentProxyIndex(newCardIndex); setModified(true); databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length()); diff --git a/cockatrice/src/interface/widgets/tabs/visual_deck_editor/tab_deck_editor_visual.cpp b/cockatrice/src/interface/widgets/tabs/visual_deck_editor/tab_deck_editor_visual.cpp index 6dd55d545..7c7c87716 100644 --- a/cockatrice/src/interface/widgets/tabs/visual_deck_editor/tab_deck_editor_visual.cpp +++ b/cockatrice/src/interface/widgets/tabs/visual_deck_editor/tab_deck_editor_visual.cpp @@ -232,8 +232,8 @@ void TabDeckEditorVisual::processMainboardCardClick(QMouseEvent *event, return; } else { // Normal click = clear selection, select this, set current - deckDockWidget->deckView->setCurrentIndex(idx); - deckDockWidget->deckView->scrollTo(idx); + deckDockWidget->setCurrentProxyIndex(idx); + deckDockWidget->scrollToProxyIndex(idx); return; }