Bulk editing dialog functionality.

This commit is contained in:
Lukas Brübach 2025-02-07 07:20:36 +01:00
parent 5a3af5a511
commit b11d3e0c55
5 changed files with 248 additions and 193 deletions

View file

@ -280,5 +280,7 @@ void PrintingSelector::toggleVisibilityNavigationButtons(bool _state)
void PrintingSelector::selectSetForCards() void PrintingSelector::selectSetForCards()
{ {
DlgSelectSetForCards *setSelectionDialog = new DlgSelectSetForCards(nullptr, deckModel); DlgSelectSetForCards *setSelectionDialog = new DlgSelectSetForCards(nullptr, deckModel);
setSelectionDialog->show(); if (!setSelectionDialog->exec()) {
return;
}
} }

View file

@ -7,7 +7,9 @@
#include "dlg_select_set_for_cards.h" #include "dlg_select_set_for_cards.h"
#include <QCheckBox> #include <QCheckBox>
#include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QMessageBox>
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include <QPushButton> #include <QPushButton>
@ -17,8 +19,7 @@
#include <qdrag.h> #include <qdrag.h>
#include <qevent.h> #include <qevent.h>
DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_model) DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_model) : QDialog(parent), model(_model)
: QDialog(parent), model(_model)
{ {
setMinimumSize(500, 500); setMinimumSize(500, 500);
setAcceptDrops(true); setAcceptDrops(true);
@ -51,7 +52,8 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
uneditedCardsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); uneditedCardsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
uneditedCardsArea->setWidgetResizable(true); uneditedCardsArea->setWidgetResizable(true);
uneditedCardsFlowWidget = new FlowWidget(uneditedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded); uneditedCardsFlowWidget =
new FlowWidget(uneditedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
uneditedCardsArea->setWidget(uneditedCardsFlowWidget); uneditedCardsArea->setWidget(uneditedCardsFlowWidget);
bottomLayout->addWidget(uneditedCardsLabel); bottomLayout->addWidget(uneditedCardsLabel);
@ -65,9 +67,32 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
sortSetsByCount(); sortSetsByCount();
updateCardLists(); updateCardLists();
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
splitter->addWidget(buttonBox);
// Set stretch factors: top (2:3), bottom (1:3) // Set stretch factors: top (2:3), bottom (1:3)
splitter->setStretchFactor(0, 3); splitter->setStretchFactor(0, 6);
splitter->setStretchFactor(1, 1); splitter->setStretchFactor(1, 2);
splitter->setStretchFactor(2, 1);
}
void DlgSelectSetForCards::actOK()
{
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
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;
}
model->removeRow(find_card.row(), find_card.parent());
model->addCard(card, CardDatabaseManager::getInstance()->getSpecificSetForCard(card, modifiedSet, ""),
DECK_ZONE_MAIN);
}
}
accept();
} }
void DlgSelectSetForCards::sortSetsByCount() void DlgSelectSetForCards::sortSetsByCount()
@ -189,8 +214,6 @@ void DlgSelectSetForCards::updateCardLists()
} }
} }
void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event) void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event)
{ {
if (event->mimeData()->hasFormat("application/x-setentrywidget")) { if (event->mimeData()->hasFormat("application/x-setentrywidget")) {
@ -224,6 +247,68 @@ void DlgSelectSetForCards::dropEvent(QDropEvent *event)
event->acceptProposedAction(); event->acceptProposedAction();
} }
QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets()
{
QMap<QString, QStringList> setCards;
if (!model)
return setCards;
DeckList *decklist = model->getDeckList();
if (!decklist)
return setCards;
InnerDecklistNode *listRoot = decklist->getRoot();
if (!listRoot)
return setCards;
for (auto *i : *listRoot) {
auto *countCurrentZone = dynamic_cast<InnerDecklistNode *>(i);
if (!countCurrentZone)
continue;
for (auto *cardNode : *countCurrentZone) {
auto *currentCard = dynamic_cast<DecklistCardNode *>(cardNode);
if (!currentCard)
continue;
CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCard(currentCard->getName());
if (!infoPtr)
continue;
CardInfoPerSetMap infoPerSetMap = infoPtr->getSets();
for (auto it = infoPerSetMap.begin(); it != infoPerSetMap.end(); ++it) {
setCards[it.key()].append(currentCard->getName());
}
}
}
return setCards;
}
QMap<QString, QStringList> DlgSelectSetForCards::getModifiedCards()
{
QMap<QString, QStringList> modifiedCards;
for (int i = 0; i < listLayout->count(); ++i) {
QWidget *widget = listLayout->itemAt(i)->widget();
if (auto entry = qobject_cast<SetEntryWidget *>(widget)) {
if (entry->isChecked()) {
QStringList cardsInSet = entry->getAllCardsForSet();
for (QString cardInSet : cardsInSet) {
bool alreadyContained = false;
for (QString key : modifiedCards.keys()) {
if (modifiedCards[key].contains(cardInSet)) {
alreadyContained = true;
}
}
if (!alreadyContained) {
modifiedCards[entry->setName].append(cardInSet);
}
}
}
}
}
return modifiedCards;
}
SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_setName, int count) SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_setName, int count)
: QWidget(_parent), parent(_parent), setName(_setName), expanded(false) : QWidget(_parent), parent(_parent), setName(_setName), expanded(false)
@ -255,7 +340,8 @@ SetEntryWidget::SetEntryWidget(DlgSelectSetForCards *_parent, const QString &_se
alreadySelectedCardsLabel->setText("Cards in set already selected in higher priority set:"); alreadySelectedCardsLabel->setText("Cards in set already selected in higher priority set:");
alreadySelectedCardsLabel->hide(); alreadySelectedCardsLabel->hide();
alreadySelectedCardListContainer = new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAlwaysOff); alreadySelectedCardListContainer =
new FlowWidget(this, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAlwaysOff);
alreadySelectedCardListContainer->hide(); alreadySelectedCardListContainer->hide();
layout->addWidget(possibleCardsLabel); layout->addWidget(possibleCardsLabel);
@ -289,8 +375,8 @@ void SetEntryWidget::mousePressEvent(QMouseEvent *event)
} }
} }
void SetEntryWidget::mouseMoveEvent(QMouseEvent *event)
void SetEntryWidget::mouseMoveEvent(QMouseEvent *event) { {
if (!(event->buttons() & Qt::LeftButton)) if (!(event->buttons() & Qt::LeftButton))
return; return;
@ -322,7 +408,6 @@ void SetEntryWidget::mouseMoveEvent(QMouseEvent *event) {
drag->exec(Qt::MoveAction); drag->exec(Qt::MoveAction);
} }
bool SetEntryWidget::isChecked() const bool SetEntryWidget::isChecked() const
{ {
return checkBox->isChecked(); return checkBox->isChecked();
@ -399,40 +484,3 @@ void SetEntryWidget::populateCardList()
alreadySelectedCardListContainer->addWidget(picture_widget); alreadySelectedCardListContainer->addWidget(picture_widget);
} }
} }
QMap<QString, QStringList> DlgSelectSetForCards::getCardsForSets()
{
QMap<QString, QStringList> setCards;
if (!model)
return setCards;
DeckList *decklist = model->getDeckList();
if (!decklist)
return setCards;
InnerDecklistNode *listRoot = decklist->getRoot();
if (!listRoot)
return setCards;
for (auto *i : *listRoot) {
auto *countCurrentZone = dynamic_cast<InnerDecklistNode *>(i);
if (!countCurrentZone)
continue;
for (auto *cardNode : *countCurrentZone) {
auto *currentCard = dynamic_cast<DecklistCardNode *>(cardNode);
if (!currentCard)
continue;
CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCard(currentCard->getName());
if (!infoPtr)
continue;
CardInfoPerSetMap infoPerSetMap = infoPtr->getSets();
for (auto it = infoPerSetMap.begin(); it != infoPerSetMap.end(); ++it) {
setCards[it.key()].append(currentCard->getName());
}
}
}
return setCards;
}

View file

@ -22,12 +22,14 @@ public:
explicit DlgSelectSetForCards(QWidget *parent, DeckListModel *_model); explicit DlgSelectSetForCards(QWidget *parent, DeckListModel *_model);
void sortSetsByCount(); void sortSetsByCount();
QMap<QString, QStringList> getCardsForSets(); QMap<QString, QStringList> getCardsForSets();
QMap<QString, QStringList> getModifiedCards();
QVBoxLayout *listLayout; QVBoxLayout *listLayout;
public slots: public slots:
void updateCardLists(); void updateCardLists();
void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) override;
void actOK();
private: private:
QVBoxLayout *layout; QVBoxLayout *layout;

View file

@ -166,14 +166,17 @@ AbstractDecklistNode *InnerDecklistNode::findCardChildByNameProviderIdAndNumber(
const QString &_cardNumber) const QString &_cardNumber)
{ {
for (const auto &i : *this) { for (const auto &i : *this) {
if (i != nullptr && i->getName() == _name) { if (!i || i->getName() != _name) {
if (i->getCardCollectorNumber() == _cardNumber) { continue;
if (i->getCardProviderId() == _providerId) { }
if (_cardNumber != "" && i->getCardCollectorNumber() != _cardNumber) {
continue;
}
if (_providerId != "" && i->getCardProviderId() != _providerId) {
continue;
}
return i; return i;
} }
}
}
}
return nullptr; return nullptr;
} }

View file

@ -137,7 +137,7 @@ public:
void clearTree(); void clearTree();
AbstractDecklistNode *findChild(const QString &_name); AbstractDecklistNode *findChild(const QString &_name);
AbstractDecklistNode *findCardChildByNameProviderIdAndNumber(const QString &_name, AbstractDecklistNode *findCardChildByNameProviderIdAndNumber(const QString &_name,
const QString &_providerId, const QString &_providerId = "",
const QString &_cardNumber = ""); const QString &_cardNumber = "");
int height() const override; int height() const override;
int recursiveCount(bool countTotalCards = false) const; int recursiveCount(bool countTotalCards = false) const;