mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
get swap cards button to work with multi-selections (#5421)
This commit is contained in:
parent
6078dd092a
commit
b7f05a12a3
2 changed files with 38 additions and 7 deletions
|
|
@ -1368,18 +1368,50 @@ void TabDeckEditor::addCardHelper(QString zoneName)
|
||||||
|
|
||||||
void TabDeckEditor::actSwapCard()
|
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 ¤tIndex : 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 ¤tIndex)
|
||||||
|
{
|
||||||
if (!currentIndex.isValid())
|
if (!currentIndex.isValid())
|
||||||
return;
|
return false;
|
||||||
const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString();
|
const QString cardName = currentIndex.sibling(currentIndex.row(), 1).data().toString();
|
||||||
const QString cardProviderID = currentIndex.sibling(currentIndex.row(), 4).data().toString();
|
const QString cardProviderID = currentIndex.sibling(currentIndex.row(), 4).data().toString();
|
||||||
const QModelIndex gparent = currentIndex.parent().parent();
|
const QModelIndex gparent = currentIndex.parent().parent();
|
||||||
|
|
||||||
if (!gparent.isValid())
|
if (!gparent.isValid())
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
const QString zoneName = gparent.sibling(gparent.row(), 1).data(Qt::EditRole).toString();
|
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;
|
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
|
// Third argument (true) says create the card no matter what, even if not in DB
|
||||||
|
|
@ -1388,9 +1420,7 @@ void TabDeckEditor::actSwapCard()
|
||||||
true);
|
true);
|
||||||
recursiveExpand(newCardIndex);
|
recursiveExpand(newCardIndex);
|
||||||
|
|
||||||
setModified(true);
|
return true;
|
||||||
setSaveStatus(true);
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::actAddCard()
|
void TabDeckEditor::actAddCard()
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,7 @@ private:
|
||||||
void addCardHelper(QString zoneName);
|
void addCardHelper(QString zoneName);
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
void decrementCardHelper(QString zoneName);
|
void decrementCardHelper(QString zoneName);
|
||||||
|
bool swapCard(const QModelIndex &idx);
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue