get swap cards button to work with multi-selections (#5421)

This commit is contained in:
RickyRister 2025-01-05 19:44:40 -08:00 committed by GitHub
parent 6078dd092a
commit b7f05a12a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 7 deletions

View file

@ -1368,18 +1368,50 @@ void TabDeckEditor::addCardHelper(QString zoneName)
void TabDeckEditor::actSwapCard()
{
const QModelIndex currentIndex = deckView->selectionModel()->currentIndex();
auto selectedRows = getSelectedCardNodes();
// hack to maintain the old reselection behavior when currently selected row of a single-selection gets deleted
// TODO: remove the hack and also handle reselection when all rows of a multi-selection gets deleted
if (selectedRows.length() == 1) {
deckView->setSelectionMode(QAbstractItemView::SingleSelection);
}
bool modified = false;
for (const auto &currentIndex : selectedRows) {
if (swapCard(currentIndex)) {
modified = true;
}
}
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
if (modified) {
setModified(true);
setSaveStatus(true);
}
update();
}
/**
* Swaps the card at the index between the maindeck and sideboard
*
* @param currentIndex The index to swap.
* @return True if the swap was successful
*/
bool TabDeckEditor::swapCard(const QModelIndex &currentIndex)
{
if (!currentIndex.isValid())
return;
return false;
const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString();
const QString cardProviderID = currentIndex.sibling(currentIndex.row(), 4).data().toString();
const QModelIndex gparent = currentIndex.parent().parent();
if (!gparent.isValid())
return;
return false;
const QString zoneName = gparent.sibling(gparent.row(), 1).data(Qt::EditRole).toString();
actDecrement();
offsetCountAtIndex(currentIndex, -1);
const QString otherZoneName = zoneName == DECK_ZONE_MAIN ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
// Third argument (true) says create the card no matter what, even if not in DB
@ -1388,9 +1420,7 @@ void TabDeckEditor::actSwapCard()
true);
recursiveExpand(newCardIndex);
setModified(true);
setSaveStatus(true);
update();
return true;
}
void TabDeckEditor::actAddCard()

View file

@ -111,6 +111,7 @@ private:
void addCardHelper(QString zoneName);
void offsetCountAtIndex(const QModelIndex &idx, int offset);
void decrementCardHelper(QString zoneName);
bool swapCard(const QModelIndex &idx);
void recursiveExpand(const QModelIndex &index);
void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);