mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-24 15:25:21 -05:00
[DeckDockWidget] Refactor to move down some methods in AbstractTabDeckEditor (#6444)
* move actSwapCard down * rename method * move actAddCard down
This commit is contained in:
parent
c12f4e9d2a
commit
e80f13b78e
|
|
@ -76,14 +76,14 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
|||
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
connect(deckView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&DeckEditorDeckDockWidget::updateCard);
|
||||
connect(deckView, &QTreeView::doubleClicked, this, &DeckEditorDeckDockWidget::actSwapCard);
|
||||
connect(deckView, &QTreeView::doubleClicked, this, &DeckEditorDeckDockWidget::actSwapSelection);
|
||||
deckView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(deckView, &QTreeView::customContextMenuRequested, this, &DeckEditorDeckDockWidget::decklistCustomMenu);
|
||||
connect(&deckViewKeySignals, &KeySignals::onShiftS, this, &DeckEditorDeckDockWidget::actSwapCard);
|
||||
connect(&deckViewKeySignals, &KeySignals::onEnter, this, &DeckEditorDeckDockWidget::actIncrement);
|
||||
connect(&deckViewKeySignals, &KeySignals::onCtrlAltEqual, this, &DeckEditorDeckDockWidget::actIncrement);
|
||||
connect(&deckViewKeySignals, &KeySignals::onShiftS, this, &DeckEditorDeckDockWidget::actSwapSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onEnter, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onCtrlAltEqual, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onCtrlAltMinus, this, &DeckEditorDeckDockWidget::actDecrementSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onShiftRight, this, &DeckEditorDeckDockWidget::actIncrement);
|
||||
connect(&deckViewKeySignals, &KeySignals::onShiftRight, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onShiftLeft, this, &DeckEditorDeckDockWidget::actDecrementSelection);
|
||||
connect(&deckViewKeySignals, &KeySignals::onDelete, this, &DeckEditorDeckDockWidget::actRemoveCard);
|
||||
|
||||
|
|
@ -181,7 +181,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
|||
|
||||
aIncrement = new QAction(QString(), this);
|
||||
aIncrement->setIcon(QPixmap("theme:icons/increment"));
|
||||
connect(aIncrement, &QAction::triggered, this, &DeckEditorDeckDockWidget::actIncrement);
|
||||
connect(aIncrement, &QAction::triggered, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||
auto *tbIncrement = new QToolButton(this);
|
||||
tbIncrement->setDefaultAction(aIncrement);
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
|||
|
||||
aSwapCard = new QAction(QString(), this);
|
||||
aSwapCard->setIcon(QPixmap("theme:icons/swap"));
|
||||
connect(aSwapCard, &QAction::triggered, this, &DeckEditorDeckDockWidget::actSwapCard);
|
||||
connect(aSwapCard, &QAction::triggered, this, &DeckEditorDeckDockWidget::actSwapSelection);
|
||||
auto *tbSwapCard = new QToolButton(this);
|
||||
tbSwapCard->setDefaultAction(aSwapCard);
|
||||
|
||||
|
|
@ -582,7 +582,32 @@ QModelIndexList DeckEditorDeckDockWidget::getSelectedCardNodes() const
|
|||
return selectedRows;
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::actIncrement()
|
||||
void DeckEditorDeckDockWidget::actAddCard(const ExactCard &card, const QString &_zoneName)
|
||||
{
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString zoneName = card.getInfo().getIsToken() ? DECK_ZONE_TOKENS : _zoneName;
|
||||
|
||||
emit requestDeckHistorySave(tr("Added (%1): %2 (%3) %4")
|
||||
.arg(zoneName, card.getName(), card.getPrinting().getSet()->getCorrectedShortName(),
|
||||
card.getPrinting().getProperty("num")));
|
||||
|
||||
QModelIndex newCardIndex = deckModel->addCard(card, zoneName);
|
||||
|
||||
if (!newCardIndex.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
expandAll();
|
||||
deckView->clearSelection();
|
||||
deckView->setCurrentIndex(newCardIndex);
|
||||
|
||||
emit deckModified();
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::actIncrementSelection()
|
||||
{
|
||||
auto selectedRows = getSelectedCardNodes();
|
||||
|
||||
|
|
@ -591,7 +616,20 @@ void DeckEditorDeckDockWidget::actIncrement()
|
|||
}
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::actSwapCard()
|
||||
void DeckEditorDeckDockWidget::actSwapCard(const ExactCard &card, const QString &zoneName)
|
||||
{
|
||||
QString providerId = card.getPrinting().getUuid();
|
||||
QString collectorNumber = card.getPrinting().getProperty("num");
|
||||
|
||||
QModelIndex foundCard = deckModel->findCard(card.getName(), zoneName, providerId, collectorNumber);
|
||||
if (!foundCard.isValid()) {
|
||||
foundCard = deckModel->findCard(card.getName(), zoneName);
|
||||
}
|
||||
|
||||
swapCard(foundCard);
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::actSwapSelection()
|
||||
{
|
||||
auto selectedRows = getSelectedCardNodes();
|
||||
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ public slots:
|
|||
void sortDeckModelToDeckView();
|
||||
DeckLoader *getDeckLoader();
|
||||
const DeckList &getDeckList() const;
|
||||
void actIncrement();
|
||||
bool swapCard(const QModelIndex &idx);
|
||||
void actAddCard(const ExactCard &card, const QString &zoneName);
|
||||
void actIncrementSelection();
|
||||
void actDecrementCard(const ExactCard &card, QString zoneName);
|
||||
void actDecrementSelection();
|
||||
void actSwapCard();
|
||||
void actSwapCard(const ExactCard &card, const QString &zoneName);
|
||||
void actSwapSelection();
|
||||
void actRemoveCard();
|
||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||
void initializeFormats();
|
||||
void expandAll();
|
||||
|
||||
|
|
@ -108,9 +108,11 @@ private:
|
|||
|
||||
void recursiveExpand(const QModelIndex &index);
|
||||
[[nodiscard]] QModelIndexList getSelectedCardNodes() const;
|
||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||
|
||||
private slots:
|
||||
void decklistCustomMenu(QPoint point);
|
||||
bool swapCard(const QModelIndex ¤tIndex);
|
||||
void updateCard(QModelIndex, const QModelIndex ¤t);
|
||||
void updateName(const QString &name);
|
||||
void updateComments();
|
||||
|
|
|
|||
|
|
@ -140,23 +140,9 @@ void AbstractTabDeckEditor::onDeckHistoryClearRequested()
|
|||
* @param card Card to add.
|
||||
* @param zoneName Zone to add the card to.
|
||||
*/
|
||||
void AbstractTabDeckEditor::addCardHelper(const ExactCard &card, QString zoneName)
|
||||
void AbstractTabDeckEditor::addCardHelper(const ExactCard &card, const QString &zoneName)
|
||||
{
|
||||
if (!card)
|
||||
return;
|
||||
|
||||
if (card.getInfo().getIsToken())
|
||||
zoneName = DECK_ZONE_TOKENS;
|
||||
|
||||
onDeckHistorySaveRequested(QString(tr("Added (%1): %2 (%3) %4"))
|
||||
.arg(zoneName, card.getName(), card.getPrinting().getSet()->getCorrectedShortName(),
|
||||
card.getPrinting().getProperty("num")));
|
||||
|
||||
QModelIndex newCardIndex = deckDockWidget->deckModel->addCard(card, zoneName);
|
||||
deckDockWidget->expandAll();
|
||||
deckDockWidget->deckView->clearSelection();
|
||||
deckDockWidget->deckView->setCurrentIndex(newCardIndex);
|
||||
setModified(true);
|
||||
deckDockWidget->actAddCard(card, zoneName);
|
||||
|
||||
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
|
||||
}
|
||||
|
|
@ -193,24 +179,6 @@ void AbstractTabDeckEditor::actDecrementCardFromSideboard(const ExactCard &card)
|
|||
emit decrementCard(card, DECK_ZONE_SIDE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Swaps a card in a deck zone.
|
||||
* @param card Card to swap.
|
||||
* @param zoneName Zone to swap in.
|
||||
*/
|
||||
void AbstractTabDeckEditor::actSwapCard(const ExactCard &card, const QString &zoneName)
|
||||
{
|
||||
QString providerId = card.getPrinting().getUuid();
|
||||
QString collectorNumber = card.getPrinting().getProperty("num");
|
||||
|
||||
QModelIndex foundCard = deckDockWidget->deckModel->findCard(card.getName(), zoneName, providerId, collectorNumber);
|
||||
if (!foundCard.isValid()) {
|
||||
foundCard = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
|
||||
}
|
||||
|
||||
deckDockWidget->swapCard(foundCard);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Opens a deck in this tab.
|
||||
* @param deck The deck
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ class QAction;
|
|||
*
|
||||
* - actAddCard(const ExactCard &card) — Adds a card to the deck.
|
||||
* - actDecrementCard(const ExactCard &card) — Removes a single instance of a card from the deck.
|
||||
* - actSwapCard(const ExactCard &card, const QString &zone) — Swaps a card between zones.
|
||||
* - actRemoveCard() — Removes the currently selected card from the deck.
|
||||
* - actSaveDeckAs() — Performs a "Save As" action for the deck.
|
||||
* - updateCard(const ExactCard &card) — Updates the currently displayed card info in the dock.
|
||||
|
|
@ -320,10 +319,7 @@ protected:
|
|||
bool isBlankNewDeck() const;
|
||||
|
||||
/** @brief Helper function to add a card to a specific deck zone. */
|
||||
void addCardHelper(const ExactCard &card, QString zoneName);
|
||||
|
||||
/** @brief Swaps a card in the deck view. */
|
||||
void actSwapCard(const ExactCard &card, const QString &zoneName);
|
||||
void addCardHelper(const ExactCard &card, const QString &zoneName);
|
||||
|
||||
/** @brief Opens a deck from a file. */
|
||||
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ void TabDeckEditorVisual::processMainboardCardClick(QMouseEvent *event,
|
|||
|
||||
// Double click = swap
|
||||
if (event->type() == QEvent::MouseButtonDblClick && event->button() == Qt::LeftButton) {
|
||||
actSwapCard(card, zoneName);
|
||||
deckDockWidget->actSwapCard(card, zoneName);
|
||||
idx = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
|
||||
sel->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user