mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-08 17:13:57 -07:00
simplify some methods
This commit is contained in:
parent
6624cd8457
commit
2e0ae92900
1 changed files with 10 additions and 19 deletions
|
|
@ -147,13 +147,15 @@ void CardAmountWidget::addPrinting(const QString &zone)
|
||||||
int addedCount = 1;
|
int addedCount = 1;
|
||||||
// Check if we will need to add extra copies due to replacing copies without providerIds
|
// Check if we will need to add extra copies due to replacing copies without providerIds
|
||||||
QModelIndex existing = deckModel->findCard(rootCard.getName(), zone);
|
QModelIndex existing = deckModel->findCard(rootCard.getName(), zone);
|
||||||
|
|
||||||
|
QString foundProviderId;
|
||||||
int extraCopies = 0;
|
int extraCopies = 0;
|
||||||
bool replacingProviderless = false;
|
bool replacingProviderless = false;
|
||||||
|
|
||||||
if (existing.isValid()) {
|
if (existing.isValid()) {
|
||||||
QString providerId =
|
foundProviderId =
|
||||||
existing.siblingAtColumn(DeckListModelColumns::CARD_PROVIDER_ID).data(Qt::DisplayRole).toString();
|
existing.siblingAtColumn(DeckListModelColumns::CARD_PROVIDER_ID).data(Qt::DisplayRole).toString();
|
||||||
if (providerId.isEmpty()) {
|
if (foundProviderId.isEmpty()) {
|
||||||
int amount = existing.data(Qt::DisplayRole).toInt();
|
int amount = existing.data(Qt::DisplayRole).toInt();
|
||||||
extraCopies = amount - 1; // One less because we *always* add one
|
extraCopies = amount - 1; // One less because we *always* add one
|
||||||
replacingProviderless = true;
|
replacingProviderless = true;
|
||||||
|
|
@ -177,11 +179,8 @@ void CardAmountWidget::addPrinting(const QString &zone)
|
||||||
auto newCardIndex = deckModel->addCard(rootCard, zone);
|
auto newCardIndex = deckModel->addCard(rootCard, zone);
|
||||||
|
|
||||||
// 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.
|
||||||
QString foundProviderId =
|
|
||||||
existing.siblingAtColumn(DeckListModelColumns::CARD_PROVIDER_ID).data(Qt::DisplayRole).toString();
|
|
||||||
if (existing.isValid() && existing != newCardIndex && foundProviderId == "") {
|
if (existing.isValid() && existing != newCardIndex && foundProviderId == "") {
|
||||||
auto amount = existing.data(Qt::DisplayRole);
|
for (int i = 0; i < extraCopies; i++) {
|
||||||
for (int i = 0; i < amount.toInt() - 1; i++) {
|
|
||||||
deckModel->addCard(rootCard, zone);
|
deckModel->addCard(rootCard, zone);
|
||||||
}
|
}
|
||||||
deckModel->removeRow(existing.row(), existing.parent());
|
deckModel->removeRow(existing.row(), existing.parent());
|
||||||
|
|
@ -259,22 +258,14 @@ void CardAmountWidget::decrementCardHelper(const QString &zone)
|
||||||
*/
|
*/
|
||||||
int CardAmountWidget::countCardsInZone(const QString &deckZone)
|
int CardAmountWidget::countCardsInZone(const QString &deckZone)
|
||||||
{
|
{
|
||||||
if (rootCard.getPrinting().getUuid().isEmpty()) {
|
QString uuid = rootCard.getPrinting().getUuid();
|
||||||
return 0; // Cards without uuids/providerIds CANNOT match another card, they are undefined for us.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!deckModel) {
|
if (uuid.isEmpty()) {
|
||||||
return -1;
|
return 0; // Cards without uuids/providerIds CANNOT match another card, they are undefined for us.
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<ExactCard> cards = deckModel->getCardsForZone(deckZone);
|
QList<ExactCard> cards = deckModel->getCardsForZone(deckZone);
|
||||||
|
|
||||||
int count = 0;
|
return std::count_if(cards.cbegin(), cards.cend(),
|
||||||
for (auto currentCard : cards) {
|
[&uuid](const ExactCard &card) { return card.getPrinting().getUuid() == uuid; });
|
||||||
if (currentCard.getPrinting().getUuid() == rootCard.getPrinting().getProperty("uuid")) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue