mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-12 07:40:30 -08:00
[PrintingSelector] Sync modified and history state on bulk selection (#6379)
* [PrintingSelector] Emit deckModified when using bulk selection * [PrintingSelector] Hook up history manager. * [PrintingSelector] Remember card amount. * Return early. Took 18 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
@@ -145,31 +145,49 @@ void DlgSelectSetForCards::retranslateUi()
|
||||
void DlgSelectSetForCards::actOK()
|
||||
{
|
||||
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
|
||||
|
||||
if (modifiedSetsAndCardsMap.isEmpty()) {
|
||||
accept(); // Nothing to do
|
||||
} else {
|
||||
emit deckAboutToBeModified(tr("Bulk modified printings."));
|
||||
}
|
||||
|
||||
for (QString modifiedSet : modifiedSetsAndCardsMap.keys()) {
|
||||
for (QString card : modifiedSetsAndCardsMap.value(modifiedSet)) {
|
||||
QModelIndex find_card = model->findCard(card, DECK_ZONE_MAIN);
|
||||
if (!find_card.isValid()) {
|
||||
continue;
|
||||
}
|
||||
int amount =
|
||||
model->data(find_card.siblingAtColumn(DeckListModelColumns::CARD_AMOUNT), Qt::DisplayRole).toInt();
|
||||
model->removeRow(find_card.row(), find_card.parent());
|
||||
CardInfoPtr cardInfo = CardDatabaseManager::query()->getCardInfo(card);
|
||||
PrintingInfo printing = CardDatabaseManager::query()->getSpecificPrinting(card, modifiedSet, "");
|
||||
model->addCard(ExactCard(cardInfo, printing), DECK_ZONE_MAIN);
|
||||
for (int i = 0; i < amount; i++) {
|
||||
model->addCard(ExactCard(cardInfo, printing), DECK_ZONE_MAIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!modifiedSetsAndCardsMap.isEmpty()) {
|
||||
emit deckModified();
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::actClear()
|
||||
{
|
||||
emit deckAboutToBeModified(tr("Cleared all printing information."));
|
||||
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
||||
emit deckModified();
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::actSetAllToPreferred()
|
||||
{
|
||||
emit deckAboutToBeModified(tr("Set all printings to preferred."));
|
||||
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
||||
DeckLoader::setProviderIdToPreferredPrinting(model->getDeckList());
|
||||
emit deckModified();
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
signals:
|
||||
void widgetOrderChanged();
|
||||
void orderChanged();
|
||||
void deckAboutToBeModified(const QString &reason);
|
||||
void deckModified();
|
||||
|
||||
public slots:
|
||||
void actOK();
|
||||
|
||||
@@ -40,6 +40,11 @@ public:
|
||||
return deckModel;
|
||||
}
|
||||
|
||||
[[nodiscard]] AbstractTabDeckEditor *getDeckEditor() const
|
||||
{
|
||||
return deckEditor;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void retranslateUi();
|
||||
void updateDisplay();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "printing_selector_card_selection_widget.h"
|
||||
|
||||
#include "../../../interface/widgets/dialogs/dlg_select_set_for_cards.h"
|
||||
#include "../tabs/abstract_tab_deck_editor.h"
|
||||
|
||||
/**
|
||||
* @brief Constructs a PrintingSelectorCardSelectionWidget for navigating through cards in the deck.
|
||||
@@ -48,6 +49,10 @@ void PrintingSelectorCardSelectionWidget::connectSignals()
|
||||
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
||||
{
|
||||
auto *setSelectionDialog = new DlgSelectSetForCards(nullptr, parent->getDeckModel());
|
||||
connect(setSelectionDialog, &DlgSelectSetForCards::deckAboutToBeModified, parent->getDeckEditor(),
|
||||
&AbstractTabDeckEditor::onDeckHistorySaveRequested);
|
||||
connect(setSelectionDialog, &DlgSelectSetForCards::deckModified, parent->getDeckEditor(),
|
||||
&AbstractTabDeckEditor::onDeckModified);
|
||||
if (!setSelectionDialog->exec()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user