mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Add buttons to clear and set all to preferred printing.
This commit is contained in:
parent
e37d36a317
commit
eae9171de9
4 changed files with 86 additions and 0 deletions
|
|
@ -312,6 +312,44 @@ QString DeckLoader::exportDeckToDecklist(DecklistWebsite website)
|
|||
return deckString;
|
||||
}
|
||||
|
||||
// This struct is here to support the forEachCard function call, defined in decklist.
|
||||
// It requires a function to be called for each card, and it will set the providerId to the preferred printing.
|
||||
struct SetProviderIdToPreferred
|
||||
{
|
||||
// Main operator for struct, allowing the foreachcard to work.
|
||||
SetProviderIdToPreferred()
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(const InnerDecklistNode *node, DecklistCardNode *card) const
|
||||
{
|
||||
Q_UNUSED(node);
|
||||
CardInfoPerSet preferredSet = CardDatabaseManager::getInstance()->getSpecificSetForCard(
|
||||
card->getName(),
|
||||
CardDatabaseManager::getInstance()->getPreferredPrintingProviderIdForCard(card->getName()));
|
||||
QString providerId = preferredSet.getProperty("uuid");
|
||||
QString setShortName = preferredSet.getPtr()->getShortName();
|
||||
QString collectorNumber = preferredSet.getProperty("num");
|
||||
|
||||
card->setCardProviderId(providerId);
|
||||
card->setCardCollectorNumber(collectorNumber);
|
||||
card->setCardSetShortName(setShortName);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function iterates through each card in the decklist and sets the providerId
|
||||
* on each card based on its set name and collector number.
|
||||
*/
|
||||
void DeckLoader::setProviderIdToPreferredPrinting()
|
||||
{
|
||||
// Set up the struct to call.
|
||||
SetProviderIdToPreferred setProviderIdToPreferred;
|
||||
|
||||
// Call the forEachCard method for each card in the deck
|
||||
forEachCard(setProviderIdToPreferred);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the providerId on each card in the decklist based on its set name and collector number.
|
||||
*/
|
||||
|
|
@ -332,6 +370,25 @@ void DeckLoader::resolveSetNameAndNumberToProviderID()
|
|||
forEachCard(setProviderId);
|
||||
}
|
||||
|
||||
// This struct is here to support the forEachCard function call, defined in decklist.
|
||||
// It requires a function to be called for each card, and it will set the providerId.
|
||||
struct ClearSetNameNumberAndProviderId
|
||||
{
|
||||
// Main operator for struct, allowing the foreachcard to work.
|
||||
ClearSetNameNumberAndProviderId()
|
||||
{
|
||||
}
|
||||
|
||||
void operator()(const InnerDecklistNode *node, DecklistCardNode *card) const
|
||||
{
|
||||
Q_UNUSED(node);
|
||||
// Set the providerId on the card
|
||||
card->setCardSetShortName(nullptr);
|
||||
card->setCardCollectorNumber(nullptr);
|
||||
card->setCardProviderId(nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the set name and numbers on each card in the decklist.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ public:
|
|||
bool saveToFile(const QString &fileName, FileFormat fmt);
|
||||
bool updateLastLoadedTimestamp(const QString &fileName, FileFormat fmt);
|
||||
QString exportDeckToDecklist(DecklistWebsite website);
|
||||
void setProviderIdToPreferredPrinting();
|
||||
|
||||
void resolveSetNameAndNumberToProviderID();
|
||||
|
||||
|
|
|
|||
|
|
@ -103,6 +103,15 @@ DlgSelectSetForCards::DlgSelectSetForCards(QWidget *parent, DeckListModel *_mode
|
|||
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOK()));
|
||||
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
clearButton = new QPushButton(buttonBox);
|
||||
connect(clearButton, &QPushButton::clicked, this, &DlgSelectSetForCards::actClear);
|
||||
|
||||
setAllToPreferredButton = new QPushButton(buttonBox);
|
||||
connect(setAllToPreferredButton, &QPushButton::clicked, this, &DlgSelectSetForCards::actSetAllToPreferred);
|
||||
|
||||
buttonBox->addButton(clearButton, QDialogButtonBox::ActionRole);
|
||||
buttonBox->addButton(setAllToPreferredButton, QDialogButtonBox::ActionRole);
|
||||
|
||||
// Set stretch factors
|
||||
splitter->setStretchFactor(0, 6); // Scroll area gets more space
|
||||
splitter->setStretchFactor(1, 2); // Bottom part gets less space
|
||||
|
|
@ -125,6 +134,8 @@ void DlgSelectSetForCards::retranslateUi()
|
|||
{
|
||||
instructionLabel->setText(tr("Check Sets to enable them. Drag-and-Drop to reorder them and change their "
|
||||
"priority. Cards will use the printing of the highest priority enabled set."));
|
||||
clearButton->setText(tr("Clear all set information"));
|
||||
setAllToPreferredButton->setText(tr("Set all to preferred"));
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::actOK()
|
||||
|
|
@ -144,6 +155,19 @@ void DlgSelectSetForCards::actOK()
|
|||
accept();
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::actClear()
|
||||
{
|
||||
model->getDeckList()->clearSetNamesAndNumbers();
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::actSetAllToPreferred()
|
||||
{
|
||||
model->getDeckList()->clearSetNamesAndNumbers();
|
||||
model->getDeckList()->setProviderIdToPreferredPrinting();
|
||||
accept();
|
||||
}
|
||||
|
||||
void DlgSelectSetForCards::sortSetsByCount()
|
||||
{
|
||||
QMap<QString, int> setsForCards = getSetsForCards();
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ signals:
|
|||
|
||||
public slots:
|
||||
void actOK();
|
||||
void actClear();
|
||||
void actSetAllToPreferred();
|
||||
void updateLayoutOrder();
|
||||
void updateCardLists();
|
||||
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
|
|
@ -53,6 +55,8 @@ private:
|
|||
QListWidget *listWidget;
|
||||
DeckListModel *model;
|
||||
QMap<QString, SetEntryWidget *> setEntries;
|
||||
QPushButton *clearButton;
|
||||
QPushButton *setAllToPreferredButton;
|
||||
|
||||
QMap<QString, int> getSetsForCards();
|
||||
void updateCardAvailability();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue