bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const { CardInfo *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow); if (!cardNameBeginning.isEmpty()) if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive)) return false; if (!cardName.isEmpty()) if (!info->getName().contains(cardName, Qt::CaseInsensitive)) return false; if (!cardText.isEmpty()) if (!info->getText().contains(cardText, Qt::CaseInsensitive)) return false; if (!cardColors.isEmpty()) if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X"))) return false; if (!cardTypes.isEmpty()) if (!cardTypes.contains(info->getMainCardType())) return false; return true; }
void DlgEditTokens::tokenSelectionChanged(const QModelIndex ¤t, const QModelIndex & /* previous */) { const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current); CardInfo *cardInfo = current.row() >= 0 ? cardDatabaseModel->getCard(realIndex.row()) : cardDatabaseModel->getDatabase()->getCard(); if (!cardInfo->getName().isEmpty()) currentCard = cardInfo; else currentCard = 0; nameEdit->setText(cardInfo->getName()); const QString cardColor = cardInfo->getColors().isEmpty() ? QString() : (cardInfo->getColors().size() > 1 ? QString("m") : cardInfo->getColors().first()); colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString)); ptEdit->setText(cardInfo->getPowTough()); annotationEdit->setText(cardInfo->getText()); }
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if ((index.row() >= cardList.size()) || (index.column() >= 5)) return QVariant(); if (role != Qt::DisplayRole) return QVariant(); CardInfo *card = cardList.at(index.row()); switch (index.column()){ case 0: return card->getName(); case 1: { QStringList setList; const QList<CardSet *> &sets = card->getSets(); for (int i = 0; i < sets.size(); i++) setList << sets[i]->getShortName(); return setList.join(", "); } case 2: return card->getManaCost(); case 3: return card->getCardType(); case 4: return card->getPowTough(); default: return QVariant(); } }
QString PictureLoader::getPicUrl() { if (!picDownload) return QString(""); CardInfo *card = cardBeingDownloaded.getCard(); CardSet *set=cardBeingDownloaded.getCurrentSet(); QString picUrl = QString(""); // if sets have been defined for the card, they can contain custom picUrls if(set) { // first check if Hq is enabled and a custom Hq card url exists in cards.xml if(picDownloadHq) { picUrl = card->getCustomPicURLHq(set->getShortName()); if (!picUrl.isEmpty()) return picUrl; } // then, test for a custom, non-Hq card url in cards.xml picUrl = card->getCustomPicURL(set->getShortName()); if (!picUrl.isEmpty()) return picUrl; } // if a card has a muid, use the default url; if not, use the fallback int muid = set ? card->getMuId(set->getShortName()) : 0; if(muid) picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl(); else picUrl = picDownloadHq ? settingsCache->getPicUrlHqFallback() : settingsCache->getPicUrlFallback(); picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName())); picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); if (set) { picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); } if (picUrl.contains("!name!") || picUrl.contains("!setcode!") || picUrl.contains("!setname!") || picUrl.contains("!cardid!")) { qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl; return QString(""); } return picUrl; }
QString PictureLoader::getPicUrl() { if (!picDownload) return QString(""); CardInfo *card = cardBeingDownloaded.getCard(); CardSet *set=cardBeingDownloaded.getCurrentSet(); QString picUrl = QString(""); // if sets have been defined for the card, they can contain custom picUrls if(set) { picUrl = card->getCustomPicURL(set->getShortName()); if (!picUrl.isEmpty()) return picUrl; } // if a card has a muid, use the default url; if not, use the fallback int muid = set ? card->getMuId(set->getShortName()) : 0; picUrl = muid ? settingsCache->getPicUrl() : settingsCache->getPicUrlFallback(); picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName())); picUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower())); picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); if (set) { picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); picUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower())); picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); picUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower())); } if ( picUrl.contains("!name!") || picUrl.contains("!name_lower!") || picUrl.contains("!setcode!") || picUrl.contains("!setcode_lower!") || picUrl.contains("!setname!") || picUrl.contains("!setname_lower!") || picUrl.contains("!cardid!") ) { qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl; return QString(""); } return picUrl; }