[Refactor] Move prev/next card logic out of PrintingSelector (#6450)

This commit is contained in:
RickyRister 2025-12-26 04:29:35 -08:00 committed by GitHub
parent 70f9982c29
commit ca3f6bba02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 65 additions and 57 deletions

View file

@ -548,6 +548,52 @@ void DeckEditorDeckDockWidget::cleanDeck()
deckTagsDisplayWidget->setTags(deckModel->getDeckList()->getTags());
}
void DeckEditorDeckDockWidget::selectPrevCard()
{
changeSelectedCard(-1);
}
void DeckEditorDeckDockWidget::selectNextCard()
{
changeSelectedCard(1);
}
/**
* @brief Selects a card based on the change direction.
*
* @param changeBy The direction to change, -1 for previous, 1 for next.
*/
void DeckEditorDeckDockWidget::changeSelectedCard(int changeBy)
{
if (changeBy == 0) {
return;
}
// Get the current index of the selected item
auto deckViewCurrentIndex = deckView->currentIndex();
auto nextIndex = deckViewCurrentIndex.siblingAtRow(deckViewCurrentIndex.row() + changeBy);
if (!nextIndex.isValid()) {
nextIndex = deckViewCurrentIndex;
// Increment to the next valid index, skipping header rows
AbstractDecklistNode *node;
do {
if (changeBy > 0) {
nextIndex = deckView->indexBelow(nextIndex);
} else {
nextIndex = deckView->indexAbove(nextIndex);
}
node = static_cast<AbstractDecklistNode *>(nextIndex.internalPointer());
} while (node && node->isDeckHeader());
}
if (nextIndex.isValid()) {
deckView->setCurrentIndex(nextIndex);
deckView->setFocus(Qt::FocusReason::MouseFocusReason);
}
}
/**
* @brief Expands all parents of the given index.
* @param sourceIndex The index to expand (model source index)

View file

@ -56,6 +56,8 @@ public:
public slots:
void cleanDeck();
void selectPrevCard();
void selectNextCard();
void updateBannerCardComboBox();
void setDeck(const LoadedDeck &_deck);
void syncDisplayWidgetsToModel();
@ -122,6 +124,7 @@ private slots:
void updateShowBannerCardComboBox(bool visible);
void updateShowTagsWidget(bool visible);
void syncBannerCardComboBoxSelectionWithDeck();
void changeSelectedCard(int changeBy);
void recursiveExpand(const QModelIndex &parent);
void expandAll();
};

View file

@ -33,6 +33,10 @@ void DeckEditorPrintingSelectorDockWidget::createPrintingSelectorDock()
installEventFilter(deckEditor);
connect(this, &QDockWidget::topLevelChanged, deckEditor, &AbstractTabDeckEditor::dockTopLevelChanged);
connect(printingSelector, &PrintingSelector::prevCardRequested, deckEditor->getDeckDockWidget(),
&DeckEditorDeckDockWidget::selectPrevCard);
connect(printingSelector, &PrintingSelector::nextCardRequested, deckEditor->getDeckDockWidget(),
&DeckEditorDeckDockWidget::selectNextCard);
}
void DeckEditorPrintingSelectorDockWidget::retranslateUi()