mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-17 04:27:45 -07: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
5 changed files with 57 additions and 53 deletions
|
|
@ -76,14 +76,14 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
deckView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
connect(deckView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
connect(deckView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||||
&DeckEditorDeckDockWidget::updateCard);
|
&DeckEditorDeckDockWidget::updateCard);
|
||||||
connect(deckView, &QTreeView::doubleClicked, this, &DeckEditorDeckDockWidget::actSwapCard);
|
connect(deckView, &QTreeView::doubleClicked, this, &DeckEditorDeckDockWidget::actSwapSelection);
|
||||||
deckView->setContextMenuPolicy(Qt::CustomContextMenu);
|
deckView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(deckView, &QTreeView::customContextMenuRequested, this, &DeckEditorDeckDockWidget::decklistCustomMenu);
|
connect(deckView, &QTreeView::customContextMenuRequested, this, &DeckEditorDeckDockWidget::decklistCustomMenu);
|
||||||
connect(&deckViewKeySignals, &KeySignals::onShiftS, this, &DeckEditorDeckDockWidget::actSwapCard);
|
connect(&deckViewKeySignals, &KeySignals::onShiftS, this, &DeckEditorDeckDockWidget::actSwapSelection);
|
||||||
connect(&deckViewKeySignals, &KeySignals::onEnter, this, &DeckEditorDeckDockWidget::actIncrement);
|
connect(&deckViewKeySignals, &KeySignals::onEnter, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||||
connect(&deckViewKeySignals, &KeySignals::onCtrlAltEqual, this, &DeckEditorDeckDockWidget::actIncrement);
|
connect(&deckViewKeySignals, &KeySignals::onCtrlAltEqual, this, &DeckEditorDeckDockWidget::actIncrementSelection);
|
||||||
connect(&deckViewKeySignals, &KeySignals::onCtrlAltMinus, this, &DeckEditorDeckDockWidget::actDecrementSelection);
|
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::onShiftLeft, this, &DeckEditorDeckDockWidget::actDecrementSelection);
|
||||||
connect(&deckViewKeySignals, &KeySignals::onDelete, this, &DeckEditorDeckDockWidget::actRemoveCard);
|
connect(&deckViewKeySignals, &KeySignals::onDelete, this, &DeckEditorDeckDockWidget::actRemoveCard);
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
|
|
||||||
aIncrement = new QAction(QString(), this);
|
aIncrement = new QAction(QString(), this);
|
||||||
aIncrement->setIcon(QPixmap("theme:icons/increment"));
|
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);
|
auto *tbIncrement = new QToolButton(this);
|
||||||
tbIncrement->setDefaultAction(aIncrement);
|
tbIncrement->setDefaultAction(aIncrement);
|
||||||
|
|
||||||
|
|
@ -199,7 +199,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
||||||
|
|
||||||
aSwapCard = new QAction(QString(), this);
|
aSwapCard = new QAction(QString(), this);
|
||||||
aSwapCard->setIcon(QPixmap("theme:icons/swap"));
|
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);
|
auto *tbSwapCard = new QToolButton(this);
|
||||||
tbSwapCard->setDefaultAction(aSwapCard);
|
tbSwapCard->setDefaultAction(aSwapCard);
|
||||||
|
|
||||||
|
|
@ -582,7 +582,32 @@ QModelIndexList DeckEditorDeckDockWidget::getSelectedCardNodes() const
|
||||||
return selectedRows;
|
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();
|
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();
|
auto selectedRows = getSelectedCardNodes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,13 @@ public slots:
|
||||||
void sortDeckModelToDeckView();
|
void sortDeckModelToDeckView();
|
||||||
DeckLoader *getDeckLoader();
|
DeckLoader *getDeckLoader();
|
||||||
const DeckList &getDeckList() const;
|
const DeckList &getDeckList() const;
|
||||||
void actIncrement();
|
void actAddCard(const ExactCard &card, const QString &zoneName);
|
||||||
bool swapCard(const QModelIndex &idx);
|
void actIncrementSelection();
|
||||||
void actDecrementCard(const ExactCard &card, QString zoneName);
|
void actDecrementCard(const ExactCard &card, QString zoneName);
|
||||||
void actDecrementSelection();
|
void actDecrementSelection();
|
||||||
void actSwapCard();
|
void actSwapCard(const ExactCard &card, const QString &zoneName);
|
||||||
|
void actSwapSelection();
|
||||||
void actRemoveCard();
|
void actRemoveCard();
|
||||||
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
|
||||||
void initializeFormats();
|
void initializeFormats();
|
||||||
void expandAll();
|
void expandAll();
|
||||||
|
|
||||||
|
|
@ -108,9 +108,11 @@ private:
|
||||||
|
|
||||||
void recursiveExpand(const QModelIndex &index);
|
void recursiveExpand(const QModelIndex &index);
|
||||||
[[nodiscard]] QModelIndexList getSelectedCardNodes() const;
|
[[nodiscard]] QModelIndexList getSelectedCardNodes() const;
|
||||||
|
void offsetCountAtIndex(const QModelIndex &idx, int offset);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void decklistCustomMenu(QPoint point);
|
void decklistCustomMenu(QPoint point);
|
||||||
|
bool swapCard(const QModelIndex ¤tIndex);
|
||||||
void updateCard(QModelIndex, const QModelIndex ¤t);
|
void updateCard(QModelIndex, const QModelIndex ¤t);
|
||||||
void updateName(const QString &name);
|
void updateName(const QString &name);
|
||||||
void updateComments();
|
void updateComments();
|
||||||
|
|
|
||||||
|
|
@ -140,23 +140,9 @@ void AbstractTabDeckEditor::onDeckHistoryClearRequested()
|
||||||
* @param card Card to add.
|
* @param card Card to add.
|
||||||
* @param zoneName Zone to add the card to.
|
* @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)
|
deckDockWidget->actAddCard(card, zoneName);
|
||||||
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);
|
|
||||||
|
|
||||||
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
|
databaseDisplayDockWidget->searchEdit->setSelection(0, databaseDisplayDockWidget->searchEdit->text().length());
|
||||||
}
|
}
|
||||||
|
|
@ -193,24 +179,6 @@ void AbstractTabDeckEditor::actDecrementCardFromSideboard(const ExactCard &card)
|
||||||
emit decrementCard(card, DECK_ZONE_SIDE);
|
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.
|
* @brief Opens a deck in this tab.
|
||||||
* @param deck The deck
|
* @param deck The deck
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,6 @@ class QAction;
|
||||||
*
|
*
|
||||||
* - actAddCard(const ExactCard &card) — Adds a card to the deck.
|
* - actAddCard(const ExactCard &card) — Adds a card to the deck.
|
||||||
* - actDecrementCard(const ExactCard &card) — Removes a single instance of a card from 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.
|
* - actRemoveCard() — Removes the currently selected card from the deck.
|
||||||
* - actSaveDeckAs() — Performs a "Save As" action for the deck.
|
* - actSaveDeckAs() — Performs a "Save As" action for the deck.
|
||||||
* - updateCard(const ExactCard &card) — Updates the currently displayed card info in the dock.
|
* - updateCard(const ExactCard &card) — Updates the currently displayed card info in the dock.
|
||||||
|
|
@ -320,10 +319,7 @@ protected:
|
||||||
bool isBlankNewDeck() const;
|
bool isBlankNewDeck() const;
|
||||||
|
|
||||||
/** @brief Helper function to add a card to a specific deck zone. */
|
/** @brief Helper function to add a card to a specific deck zone. */
|
||||||
void addCardHelper(const ExactCard &card, QString zoneName);
|
void addCardHelper(const ExactCard &card, const QString &zoneName);
|
||||||
|
|
||||||
/** @brief Swaps a card in the deck view. */
|
|
||||||
void actSwapCard(const ExactCard &card, const QString &zoneName);
|
|
||||||
|
|
||||||
/** @brief Opens a deck from a file. */
|
/** @brief Opens a deck from a file. */
|
||||||
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
virtual void openDeckFromFile(const QString &fileName, DeckOpenLocation deckOpenLocation);
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ void TabDeckEditorVisual::processMainboardCardClick(QMouseEvent *event,
|
||||||
|
|
||||||
// Double click = swap
|
// Double click = swap
|
||||||
if (event->type() == QEvent::MouseButtonDblClick && event->button() == Qt::LeftButton) {
|
if (event->type() == QEvent::MouseButtonDblClick && event->button() == Qt::LeftButton) {
|
||||||
actSwapCard(card, zoneName);
|
deckDockWidget->actSwapCard(card, zoneName);
|
||||||
idx = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
|
idx = deckDockWidget->deckModel->findCard(card.getName(), zoneName);
|
||||||
sel->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
|
sel->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue