mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 09:33:57 -07:00
refactor
This commit is contained in:
parent
2e0ae92900
commit
fd75d83213
1 changed files with 18 additions and 12 deletions
|
|
@ -143,6 +143,22 @@ void DlgSelectSetForCards::retranslateUi()
|
||||||
setAllToPreferredButton->setText(tr("Set all to preferred"));
|
setAllToPreferredButton->setText(tr("Set all to preferred"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool swapPrinting(DeckListModel *model, const QString &modifiedSet, const QString &cardName)
|
||||||
|
{
|
||||||
|
QModelIndex idx = model->findCard(cardName, DECK_ZONE_MAIN);
|
||||||
|
if (!idx.isValid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int amount = model->data(idx.siblingAtColumn(DeckListModelColumns::CARD_AMOUNT), Qt::DisplayRole).toInt();
|
||||||
|
model->removeRow(idx.row(), idx.parent());
|
||||||
|
CardInfoPtr cardInfo = CardDatabaseManager::query()->getCardInfo(cardName);
|
||||||
|
PrintingInfo printing = CardDatabaseManager::query()->getSpecificPrinting(cardName, modifiedSet, "");
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
model->addCard(ExactCard(cardInfo, printing), DECK_ZONE_MAIN);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void DlgSelectSetForCards::actOK()
|
void DlgSelectSetForCards::actOK()
|
||||||
{
|
{
|
||||||
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
|
QMap<QString, QStringList> modifiedSetsAndCardsMap = getModifiedCards();
|
||||||
|
|
@ -155,20 +171,10 @@ void DlgSelectSetForCards::actOK()
|
||||||
|
|
||||||
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);
|
swapPrinting(model, modifiedSet, card);
|
||||||
if (!find_card.isValid()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int amount =
|
|
||||||
model->data(find_card.siblingAtColumn(DeckListModelColumns::CARD_AMOUNT), Qt::DisplayRole).toInt();
|
|
||||||
model->removeRow(find_card.row(), find_card.parent());
|
|
||||||
CardInfoPtr cardInfo = CardDatabaseManager::query()->getCardInfo(card);
|
|
||||||
PrintingInfo printing = CardDatabaseManager::query()->getSpecificPrinting(card, modifiedSet, "");
|
|
||||||
for (int i = 0; i < amount; i++) {
|
|
||||||
model->addCard(ExactCard(cardInfo, printing), DECK_ZONE_MAIN);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modifiedSetsAndCardsMap.isEmpty()) {
|
if (!modifiedSetsAndCardsMap.isEmpty()) {
|
||||||
emit deckModified();
|
emit deckModified();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue