[Printing Selector] Notify deck editor about history changes. (#6364)

Took 44 minutes

Took 2 minutes

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL
2025-11-29 18:56:06 +01:00
committed by GitHub
parent c5fde071e7
commit 8ee7163014
2 changed files with 54 additions and 5 deletions

View File

@@ -61,6 +61,10 @@ CardAmountWidget::CardAmountWidget(QWidget *parent,
// Connect slider for dynamic font size adjustment // Connect slider for dynamic font size adjustment
connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize); connect(cardSizeSlider, &QSlider::valueChanged, this, &CardAmountWidget::adjustFontSize);
if (deckEditor) {
connect(this, &CardAmountWidget::deckModified, deckEditor, &AbstractTabDeckEditor::onDeckHistorySaveRequested);
}
} }
/** /**
@@ -140,24 +144,52 @@ void CardAmountWidget::updateCardCount()
*/ */
void CardAmountWidget::addPrinting(const QString &zone) void CardAmountWidget::addPrinting(const QString &zone)
{ {
int addedCount = 1;
// Check if we will need to add extra copies due to replacing copies without providerIds
QModelIndex existing = deckModel->findCard(rootCard.getName(), zone);
int extraCopies = 0;
bool replacingProviderless = false;
if (existing.isValid()) {
QString providerId = deckModel->data(existing.sibling(existing.row(), 4), Qt::DisplayRole).toString();
if (providerId.isEmpty()) {
int amount = deckModel->data(existing, Qt::DisplayRole).toInt();
extraCopies = amount - 1; // One less because we *always* add one
replacingProviderless = true;
}
}
addedCount += extraCopies;
QString reason = QString("Added %1 copies of '%2 (%3) %4' to %5 [ProviderID: %6]%7")
.arg(addedCount)
.arg(rootCard.getName())
.arg(rootCard.getPrinting().getSet()->getShortName())
.arg(rootCard.getPrinting().getProperty("num"))
.arg(zone == DECK_ZONE_MAIN ? "mainboard" : "sideboard")
.arg(rootCard.getPrinting().getUuid())
.arg(replacingProviderless ? " (replaced providerless printings)" : "");
emit deckModified(reason);
// Add the card and expand the list UI // Add the card and expand the list UI
auto newCardIndex = deckModel->addCard(rootCard, zone); auto newCardIndex = deckModel->addCard(rootCard, zone);
recursiveExpand(newCardIndex); recursiveExpand(newCardIndex);
// Check if a card without a providerId already exists in the deckModel and replace it, if so. // Check if a card without a providerId already exists in the deckModel and replace it, if so.
QModelIndex find_card = deckModel->findCard(rootCard.getName(), zone); QString foundProviderId = deckModel->data(existing.sibling(existing.row(), 4), Qt::DisplayRole).toString();
QString foundProviderId = deckModel->data(find_card.sibling(find_card.row(), 4), Qt::DisplayRole).toString(); if (existing.isValid() && existing != newCardIndex && foundProviderId == "") {
if (find_card.isValid() && find_card != newCardIndex && foundProviderId == "") { auto amount = deckModel->data(existing, Qt::DisplayRole);
auto amount = deckModel->data(find_card, Qt::DisplayRole);
for (int i = 0; i < amount.toInt() - 1; i++) { for (int i = 0; i < amount.toInt() - 1; i++) {
deckModel->addCard(rootCard, zone); deckModel->addCard(rootCard, zone);
} }
deckModel->removeRow(find_card.row(), find_card.parent()); deckModel->removeRow(existing.row(), existing.parent());
} }
// Set Index and Focus as if the user had just clicked the new card and modify the deckEditor saveState // Set Index and Focus as if the user had just clicked the new card and modify the deckEditor saveState
newCardIndex = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(), newCardIndex = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(),
rootCard.getPrinting().getProperty("num")); rootCard.getPrinting().getProperty("num"));
deckView->setCurrentIndex(newCardIndex); deckView->setCurrentIndex(newCardIndex);
deckView->setFocus(Qt::FocusReason::MouseFocusReason); deckView->setFocus(Qt::FocusReason::MouseFocusReason);
deckEditor->setModified(true); deckEditor->setModified(true);
@@ -223,12 +255,15 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
const QModelIndex numberIndex = idx.sibling(idx.row(), 0); const QModelIndex numberIndex = idx.sibling(idx.row(), 0);
const int count = deckModel->data(numberIndex, Qt::EditRole).toInt(); const int count = deckModel->data(numberIndex, Qt::EditRole).toInt();
const int new_count = count + offset; const int new_count = count + offset;
deckView->setCurrentIndex(numberIndex); deckView->setCurrentIndex(numberIndex);
if (new_count <= 0) { if (new_count <= 0) {
deckModel->removeRow(idx.row(), idx.parent()); deckModel->removeRow(idx.row(), idx.parent());
} else { } else {
deckModel->setData(numberIndex, new_count, Qt::EditRole); deckModel->setData(numberIndex, new_count, Qt::EditRole);
} }
deckEditor->setModified(true); deckEditor->setModified(true);
} }
@@ -239,8 +274,18 @@ void CardAmountWidget::offsetCountAtIndex(const QModelIndex &idx, int offset)
*/ */
void CardAmountWidget::decrementCardHelper(const QString &zone) void CardAmountWidget::decrementCardHelper(const QString &zone)
{ {
QString reason = QString("Removed 1 copy of '%1 (%2) %3' from %4 [ProviderID: %5]")
.arg(rootCard.getName())
.arg(rootCard.getPrinting().getSet()->getShortName())
.arg(rootCard.getPrinting().getProperty("num"))
.arg(zone == DECK_ZONE_MAIN ? "mainboard" : "sideboard")
.arg(rootCard.getPrinting().getUuid());
emit deckModified(reason);
QModelIndex idx = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(), QModelIndex idx = deckModel->findCard(rootCard.getName(), zone, rootCard.getPrinting().getUuid(),
rootCard.getPrinting().getProperty("num")); rootCard.getPrinting().getProperty("num"));
offsetCountAtIndex(idx, -1); offsetCountAtIndex(idx, -1);
deckEditor->setModified(true); deckEditor->setModified(true);
} }

View File

@@ -21,6 +21,10 @@
class CardAmountWidget : public QWidget class CardAmountWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
signals:
void deckModified(const QString &modificationReason);
public: public:
explicit CardAmountWidget(QWidget *parent, explicit CardAmountWidget(QWidget *parent,
AbstractTabDeckEditor *deckEditor, AbstractTabDeckEditor *deckEditor,