Add a display for modified cards.

This commit is contained in:
Lukas Brübach 2025-02-08 01:23:49 +01:00
parent 69adf806e6
commit cdc7fbc965
2 changed files with 77 additions and 21 deletions

View file

@ -27,6 +27,7 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
QVBoxLayout *mainLayout = new QVBoxLayout(this); QVBoxLayout *mainLayout = new QVBoxLayout(this);
setLayout(mainLayout); setLayout(mainLayout);
// Main vertical splitter
QSplitter *splitter = new QSplitter(Qt::Vertical, this); QSplitter *splitter = new QSplitter(Qt::Vertical, this);
mainLayout->addWidget(splitter); mainLayout->addWidget(splitter);
@ -41,10 +42,13 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
listContainer->setLayout(listLayout); listContainer->setLayout(listLayout);
scrollArea->setWidget(listContainer); scrollArea->setWidget(listContainer);
// Bottom section container // Bottom horizontal splitter
QWidget *bottomContainer = new QWidget(this); QSplitter *bottomSplitter = new QSplitter(Qt::Horizontal, this);
QVBoxLayout *bottomLayout = new QVBoxLayout(bottomContainer);
bottomLayout->setContentsMargins(0, 0, 0, 0); // Left container
QWidget *leftContainer = new QWidget(this);
QVBoxLayout *leftLayout = new QVBoxLayout(leftContainer);
leftLayout->setContentsMargins(0, 0, 0, 0);
uneditedCardsLabel = new QLabel("Unmodified Cards:", this); uneditedCardsLabel = new QLabel("Unmodified Cards:", this);
uneditedCardsArea = new QScrollArea(this); uneditedCardsArea = new QScrollArea(this);
@ -56,13 +60,36 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
new FlowWidget(uneditedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded); new FlowWidget(uneditedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
uneditedCardsArea->setWidget(uneditedCardsFlowWidget); uneditedCardsArea->setWidget(uneditedCardsFlowWidget);
bottomLayout->addWidget(uneditedCardsLabel); leftLayout->addWidget(uneditedCardsLabel);
bottomLayout->addWidget(uneditedCardsArea); leftLayout->addWidget(uneditedCardsArea);
bottomContainer->setLayout(bottomLayout); leftContainer->setLayout(leftLayout);
// Add widgets to the splitter // Right container
QWidget *rightContainer = new QWidget(this);
QVBoxLayout *rightLayout = new QVBoxLayout(rightContainer);
rightLayout->setContentsMargins(0, 0, 0, 0);
modifiedCardsLabel = new QLabel("Modified Cards:", this);
modifiedCardsArea = new QScrollArea(this);
modifiedCardsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
modifiedCardsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
modifiedCardsArea->setWidgetResizable(true);
modifiedCardsFlowWidget =
new FlowWidget(modifiedCardsArea, Qt::Horizontal, Qt::ScrollBarAlwaysOff, Qt::ScrollBarAsNeeded);
modifiedCardsArea->setWidget(modifiedCardsFlowWidget);
rightLayout->addWidget(modifiedCardsLabel);
rightLayout->addWidget(modifiedCardsArea);
rightContainer->setLayout(rightLayout);
// Add left and right containers to the bottom splitter
bottomSplitter->addWidget(leftContainer);
bottomSplitter->addWidget(rightContainer);
// Add widgets to the main splitter
splitter->addWidget(scrollArea); splitter->addWidget(scrollArea);
splitter->addWidget(bottomContainer); splitter->addWidget(bottomSplitter);
cardsForSets = getCardsForSets(); cardsForSets = getCardsForSets();
@ -74,12 +101,16 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
splitter->addWidget(buttonBox); splitter->addWidget(buttonBox);
// Set stretch factors: top (2:3), bottom (1:3) // Set stretch factors
splitter->setStretchFactor(0, 6); splitter->setStretchFactor(0, 6); // Scroll area gets more space
splitter->setStretchFactor(1, 2); splitter->setStretchFactor(1, 2); // Bottom part gets less space
splitter->setStretchFactor(2, 1); splitter->setStretchFactor(2, 1); // Buttons take minimal space
bottomSplitter->setStretchFactor(0, 1); // Left and right equally split
bottomSplitter->setStretchFactor(1, 1);
} }
void DlgSelectSetForCards::actOK() void DlgSelectSetForCards::actOK()
{ {
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards(); QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
@ -172,17 +203,17 @@ void DlgSelectSetForCards::updateCardLists()
} }
uneditedCardsFlowWidget->clearLayout(); uneditedCardsFlowWidget->clearLayout();
modifiedCardsFlowWidget->clearLayout();
QStringList selectedCards; // Map from set name to a set of selected cards in that set
QMap<QString, QSet<QString>> selectedCardsBySet;
for (SetEntryWidget *entryWidget : entry_widgets) { for (SetEntryWidget *entryWidget : entry_widgets) {
if (entryWidget->isChecked()) { if (entryWidget->isChecked()) {
QStringList cardsInSet = entryWidget->getAllCardsForSet(); QStringList cardsInSet = entryWidget->getAllCardsForSet();
for (QString cardInSet : cardsInSet) { QSet<QString> cardSet = QSet<QString>(cardsInSet.begin(), cardsInSet.end()); // Convert list to set
selectedCards.append(cardInSet); selectedCardsBySet.insert(entryWidget->setName, cardSet);
}
} }
} }
selectedCards.removeDuplicates();
DeckList *decklist = model->getDeckList(); DeckList *decklist = model->getDeckList();
if (!decklist) if (!decklist)
@ -202,16 +233,38 @@ void DlgSelectSetForCards::updateCardLists()
if (!currentCard) if (!currentCard)
continue; continue;
if (!selectedCards.contains(currentCard->getName())) { bool found = false;
QString foundSetName;
// Check across all sets if the card is present
for (auto it = selectedCardsBySet.begin(); it != selectedCardsBySet.end(); ++it) {
if (it.value().contains(currentCard->getName())) {
found = true;
foundSetName = it.key(); // Store the set name where it was found
break; // Stop at the first match
}
}
if (!found) {
// The card was not in any selected set
CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCard(currentCard->getName()); CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCard(currentCard->getName());
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(uneditedCardsFlowWidget); CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(uneditedCardsFlowWidget);
picture_widget->setCard(infoPtr); picture_widget->setCard(infoPtr);
uneditedCardsFlowWidget->addWidget(picture_widget); uneditedCardsFlowWidget->addWidget(picture_widget);
} } else {
CardInfoPtr infoPtr = CardDatabaseManager::getInstance()->getCardByNameAndProviderId(
currentCard->getName(), CardDatabaseManager::getInstance()
->getSpecificSetForCard(currentCard->getName(), foundSetName, "")
.getProperty("uuid"));
CardInfoPictureWidget *picture_widget = new CardInfoPictureWidget(modifiedCardsFlowWidget);
picture_widget->setCard(infoPtr);
modifiedCardsFlowWidget->addWidget(picture_widget);}
} }
} }
} }
void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event) void DlgSelectSetForCards::dragEnterEvent(QDragEnterEvent *event)
{ {
if (event->mimeData()->hasFormat("application/x-setentrywidget")) { if (event->mimeData()->hasFormat("application/x-setentrywidget")) {

View file

@ -20,7 +20,6 @@ class DlgSelectSetForCards : public QDialog
public: public:
explicit DlgSelectSetForCards(QWidget *parent, DeckListModel *_model); explicit DlgSelectSetForCards(QWidget *parent, DeckListModel *_model);
void actOK();
void sortSetsByCount(); void sortSetsByCount();
QMap<QString, QStringList> getCardsForSets(); QMap<QString, QStringList> getCardsForSets();
QMap<QString, QStringList> getModifiedCards(); QMap<QString, QStringList> getModifiedCards();
@ -30,6 +29,7 @@ public:
QMap<QString, QStringList> cardsForSets; QMap<QString, QStringList> cardsForSets;
public slots: public slots:
void actOK();
void updateCardLists(); void updateCardLists();
void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) override;
@ -40,6 +40,9 @@ private:
QScrollArea *uneditedCardsArea; QScrollArea *uneditedCardsArea;
FlowWidget *uneditedCardsFlowWidget; FlowWidget *uneditedCardsFlowWidget;
QLabel *uneditedCardsLabel; QLabel *uneditedCardsLabel;
QScrollArea *modifiedCardsArea;
FlowWidget *modifiedCardsFlowWidget;
QLabel *modifiedCardsLabel;
QWidget *listContainer; QWidget *listContainer;
QListWidget *listWidget; QListWidget *listWidget;
DeckListModel *model; DeckListModel *model;