mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-03-12 21:22:55 -07: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()
|
void DlgSelectSetForCards::actOK()
|
||||||
{
|
{
|
||||||
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
|
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 modifiedSet : modifiedSetsAndCardsMap.keys()) {
|
||||||
for (QString card : modifiedSetsAndCardsMap.value(modifiedSet)) {
|
for (QString card : modifiedSetsAndCardsMap.value(modifiedSet)) {
|
||||||
QModelIndex find_card = model->findCard(card, DECK_ZONE_MAIN);
|
QModelIndex find_card = model->findCard(card, DECK_ZONE_MAIN);
|
||||||
if (!find_card.isValid()) {
|
if (!find_card.isValid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
int amount =
|
||||||
|
model->data(find_card.siblingAtColumn(DeckListModelColumns::CARD_AMOUNT), Qt::DisplayRole).toInt();
|
||||||
model->removeRow(find_card.row(), find_card.parent());
|
model->removeRow(find_card.row(), find_card.parent());
|
||||||
CardInfoPtr cardInfo = CardDatabaseManager::query()->getCardInfo(card);
|
CardInfoPtr cardInfo = CardDatabaseManager::query()->getCardInfo(card);
|
||||||
PrintingInfo printing = CardDatabaseManager::query()->getSpecificPrinting(card, modifiedSet, "");
|
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();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgSelectSetForCards::actClear()
|
void DlgSelectSetForCards::actClear()
|
||||||
{
|
{
|
||||||
|
emit deckAboutToBeModified(tr("Cleared all printing information."));
|
||||||
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
||||||
|
emit deckModified();
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DlgSelectSetForCards::actSetAllToPreferred()
|
void DlgSelectSetForCards::actSetAllToPreferred()
|
||||||
{
|
{
|
||||||
|
emit deckAboutToBeModified(tr("Set all printings to preferred."));
|
||||||
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
DeckLoader::clearSetNamesAndNumbers(model->getDeckList());
|
||||||
DeckLoader::setProviderIdToPreferredPrinting(model->getDeckList());
|
DeckLoader::setProviderIdToPreferredPrinting(model->getDeckList());
|
||||||
|
emit deckModified();
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void widgetOrderChanged();
|
void widgetOrderChanged();
|
||||||
void orderChanged();
|
void orderChanged();
|
||||||
|
void deckAboutToBeModified(const QString &reason);
|
||||||
|
void deckModified();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void actOK();
|
void actOK();
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ public:
|
|||||||
return deckModel;
|
return deckModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] AbstractTabDeckEditor *getDeckEditor() const
|
||||||
|
{
|
||||||
|
return deckEditor;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "printing_selector_card_selection_widget.h"
|
#include "printing_selector_card_selection_widget.h"
|
||||||
|
|
||||||
#include "../../../interface/widgets/dialogs/dlg_select_set_for_cards.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.
|
* @brief Constructs a PrintingSelectorCardSelectionWidget for navigating through cards in the deck.
|
||||||
@@ -48,6 +49,10 @@ void PrintingSelectorCardSelectionWidget::connectSignals()
|
|||||||
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
void PrintingSelectorCardSelectionWidget::selectSetForCards()
|
||||||
{
|
{
|
||||||
auto *setSelectionDialog = new DlgSelectSetForCards(nullptr, parent->getDeckModel());
|
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()) {
|
if (!setSelectionDialog->exec()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user