mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Merge branch 'master' into build/6162-use-vcpk-everywhere-aqt-install
This commit is contained in:
commit
ccaff42c90
27 changed files with 522 additions and 500 deletions
|
|
@ -21,11 +21,14 @@ set(cockatrice_SOURCES
|
||||||
src/client/sound_engine.cpp
|
src/client/sound_engine.cpp
|
||||||
src/client/tapped_out_interface.cpp
|
src/client/tapped_out_interface.cpp
|
||||||
src/client/update_downloader.cpp
|
src/client/update_downloader.cpp
|
||||||
src/database/card_completer_proxy_model.cpp
|
|
||||||
src/database/card_database.cpp
|
src/database/card_database.cpp
|
||||||
src/database/card_database_manager.cpp
|
src/database/card_database_manager.cpp
|
||||||
src/database/card_database_model.cpp
|
src/database/model/card_database_model.cpp
|
||||||
src/database/card_search_model.cpp
|
src/database/model/card_database_display_model.cpp
|
||||||
|
src/database/model/card/card_completer_proxy_model.cpp
|
||||||
|
src/database/model/card/card_search_model.cpp
|
||||||
|
src/database/model/token/token_display_model.cpp
|
||||||
|
src/database/model/token/token_edit_model.cpp
|
||||||
src/database/parser/card_database_parser.cpp
|
src/database/parser/card_database_parser.cpp
|
||||||
src/database/parser/cockatrice_xml_3.cpp
|
src/database/parser/cockatrice_xml_3.cpp
|
||||||
src/database/parser/cockatrice_xml_4.cpp
|
src/database/parser/cockatrice_xml_4.cpp
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ CardDatabase::~CardDatabase()
|
||||||
|
|
||||||
void CardDatabase::clear()
|
void CardDatabase::clear()
|
||||||
{
|
{
|
||||||
clearDatabaseMutex->lock();
|
QMutexLocker locker(clearDatabaseMutex);
|
||||||
|
|
||||||
for (const auto &card : cards.values()) {
|
for (const auto &card : cards.values()) {
|
||||||
if (card) {
|
if (card) {
|
||||||
|
|
@ -58,8 +58,110 @@ void CardDatabase::clear()
|
||||||
ICardDatabaseParser::clearSetlist();
|
ICardDatabaseParser::clearSetlist();
|
||||||
|
|
||||||
loadStatus = NotLoaded;
|
loadStatus = NotLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
clearDatabaseMutex->unlock();
|
LoadStatus CardDatabase::loadFromFile(const QString &fileName)
|
||||||
|
{
|
||||||
|
QFile file(fileName);
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
if (!file.isOpen()) {
|
||||||
|
return FileError;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto parser : availableParsers) {
|
||||||
|
file.reset();
|
||||||
|
if (parser->getCanParseFile(fileName, file)) {
|
||||||
|
file.reset();
|
||||||
|
parser->parseFile(file);
|
||||||
|
return Ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadStatus CardDatabase::loadCardDatabase(const QString &path)
|
||||||
|
{
|
||||||
|
auto startTime = QTime::currentTime();
|
||||||
|
LoadStatus tempLoadStatus = NotLoaded;
|
||||||
|
if (!path.isEmpty()) {
|
||||||
|
QMutexLocker locker(loadFromFileMutex);
|
||||||
|
tempLoadStatus = loadFromFile(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
int msecs = startTime.msecsTo(QTime::currentTime());
|
||||||
|
qCInfo(CardDatabaseLoadingLog) << "Loaded card database: Path =" << path << "Status =" << tempLoadStatus
|
||||||
|
<< "Cards =" << cards.size() << "Sets =" << sets.size()
|
||||||
|
<< QString("%1ms").arg(msecs);
|
||||||
|
|
||||||
|
return tempLoadStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
LoadStatus CardDatabase::loadCardDatabases()
|
||||||
|
{
|
||||||
|
QMutexLocker locker(reloadDatabaseMutex);
|
||||||
|
qCInfo(CardDatabaseLoadingLog) << "Card Database Loading Started";
|
||||||
|
|
||||||
|
clear(); // remove old db
|
||||||
|
|
||||||
|
loadStatus = loadCardDatabase(SettingsCache::instance().getCardDatabasePath()); // load main card database
|
||||||
|
loadCardDatabase(SettingsCache::instance().getTokenDatabasePath()); // load tokens database
|
||||||
|
loadCardDatabase(SettingsCache::instance().getSpoilerCardDatabasePath()); // load spoilers database
|
||||||
|
|
||||||
|
// find all custom card databases, recursively & following symlinks
|
||||||
|
// then load them alphabetically
|
||||||
|
auto customPaths = collectCustomDatabasePaths();
|
||||||
|
for (int i = 0, n = customPaths.size(); i < n; ++i) {
|
||||||
|
const auto &path = customPaths.at(i);
|
||||||
|
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << path << ")";
|
||||||
|
loadCardDatabase(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// AFTER all the cards have been loaded
|
||||||
|
|
||||||
|
// resolve the reverse-related tags
|
||||||
|
|
||||||
|
refreshCachedReverseRelatedCards();
|
||||||
|
|
||||||
|
if (loadStatus == Ok) {
|
||||||
|
checkUnknownSets(); // update deck editors, etc
|
||||||
|
qCInfo(CardDatabaseLoadingSuccessOrFailureLog) << "Card Database Loading Success";
|
||||||
|
emit cardDatabaseLoadingFinished();
|
||||||
|
} else {
|
||||||
|
qCInfo(CardDatabaseLoadingSuccessOrFailureLog) << "Card Database Loading Failed";
|
||||||
|
emit cardDatabaseLoadingFailed(); // bring up the settings dialog
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList CardDatabase::collectCustomDatabasePaths()
|
||||||
|
{
|
||||||
|
QDirIterator it(SettingsCache::instance().getCustomCardDatabasePath(), {"*.xml"}, QDir::Files,
|
||||||
|
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
||||||
|
|
||||||
|
QStringList paths;
|
||||||
|
while (it.hasNext())
|
||||||
|
paths << it.next();
|
||||||
|
paths.sort();
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabase::refreshCachedReverseRelatedCards()
|
||||||
|
{
|
||||||
|
for (const auto &card : cards) {
|
||||||
|
card->resetReverseRelatedCards2Me();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &card : cards) {
|
||||||
|
for (auto *rel : card->getReverseRelatedCards()) {
|
||||||
|
if (auto target = cards.value(rel->getName())) {
|
||||||
|
auto *newRel = new CardRelation(card->getName(), rel->getAttachType(), rel->getIsCreateAllExclusion(),
|
||||||
|
rel->getIsVariable(), rel->getDefaultCount(), rel->getIsPersistent());
|
||||||
|
target->addReverseRelatedCards2Me(newRel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDatabase::addCard(CardInfoPtr card)
|
void CardDatabase::addCard(CardInfoPtr card)
|
||||||
|
|
@ -69,21 +171,20 @@ void CardDatabase::addCard(CardInfoPtr card)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if card already exists just add the new set property
|
auto name = card->getName();
|
||||||
if (cards.contains(card->getName())) {
|
|
||||||
CardInfoPtr sameCard = cards[card->getName()];
|
// If a card already exists, just add the new set property.
|
||||||
for (const auto &printings : card->getSets()) {
|
if (auto existing = cards.value(name)) {
|
||||||
for (const PrintingInfo &printing : printings) {
|
for (const auto &printings : card->getSets())
|
||||||
sameCard->addToSet(printing.getSet(), printing);
|
for (const auto &printing : printings)
|
||||||
}
|
existing->addToSet(printing.getSet(), printing);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addCardMutex->lock();
|
QMutexLocker locker(addCardMutex);
|
||||||
cards.insert(card->getName(), card);
|
cards.insert(name, card);
|
||||||
simpleNameCards.insert(card->getSimpleName(), card);
|
simpleNameCards.insert(card->getSimpleName(), card);
|
||||||
addCardMutex->unlock();
|
|
||||||
emit cardAdded(card);
|
emit cardAdded(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,10 +204,9 @@ void CardDatabase::removeCard(CardInfoPtr card)
|
||||||
for (auto *cardRelation : card->getReverseRelatedCards2Me())
|
for (auto *cardRelation : card->getReverseRelatedCards2Me())
|
||||||
cardRelation->deleteLater();
|
cardRelation->deleteLater();
|
||||||
|
|
||||||
removeCardMutex->lock();
|
QMutexLocker locker(removeCardMutex);
|
||||||
cards.remove(card->getName());
|
cards.remove(card->getName());
|
||||||
simpleNameCards.remove(card->getSimpleName());
|
simpleNameCards.remove(card->getSimpleName());
|
||||||
removeCardMutex->unlock();
|
|
||||||
emit cardRemoved(card);
|
emit cardRemoved(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -187,6 +287,15 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
return simpleNameCards.value(CardInfo::simplifyName(cardName));
|
return simpleNameCards.value(CardInfo::simplifyName(cardName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CardInfoPtr CardDatabase::lookupCardByName(const QString &name) const
|
||||||
|
{
|
||||||
|
if (auto info = getCardInfo(name))
|
||||||
|
return info;
|
||||||
|
if (auto info = getCardBySimpleName(name))
|
||||||
|
return info;
|
||||||
|
return getCardBySimpleName(CardInfo::simplifyName(name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks up the card by CardRef, simplifying the name if required.
|
* Looks up the card by CardRef, simplifying the name if required.
|
||||||
* If the providerId is empty, will default to the preferred printing.
|
* If the providerId is empty, will default to the preferred printing.
|
||||||
|
|
@ -197,21 +306,11 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
|
||||||
*/
|
*/
|
||||||
ExactCard CardDatabase::guessCard(const CardRef &cardRef) const
|
ExactCard CardDatabase::guessCard(const CardRef &cardRef) const
|
||||||
{
|
{
|
||||||
CardInfoPtr temp = getCardInfo(cardRef.name);
|
auto card = lookupCardByName(cardRef.name);
|
||||||
|
auto printing =
|
||||||
|
cardRef.providerId.isEmpty() ? getPreferredPrinting(card) : findPrintingWithId(card, cardRef.providerId);
|
||||||
|
|
||||||
if (temp == nullptr) { // get card by simple name instead
|
return ExactCard(card, printing);
|
||||||
temp = getCardBySimpleName(cardRef.name);
|
|
||||||
if (temp == nullptr) { // still could not find the card, so simplify the cardName too
|
|
||||||
const auto &simpleCardName = CardInfo::simplifyName(cardRef.name);
|
|
||||||
temp = getCardBySimpleName(simpleCardName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cardRef.providerId.isEmpty() || cardRef.providerId.isNull()) {
|
|
||||||
return ExactCard(temp, getPreferredPrinting(temp));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExactCard(temp, findPrintingWithId(temp, cardRef.providerId));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExactCard CardDatabase::getRandomCard()
|
ExactCard CardDatabase::getRandomCard()
|
||||||
|
|
@ -227,6 +326,21 @@ ExactCard CardDatabase::getRandomCard()
|
||||||
return ExactCard{randomCard, getPreferredPrinting(randomCard)};
|
return ExactCard{randomCard, getPreferredPrinting(randomCard)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExactCard CardDatabase::getCardFromSameSet(const QString &cardName, const PrintingInfo &otherPrinting) const
|
||||||
|
{
|
||||||
|
// The source card does not have a printing defined, which means we can't get a card from the same set.
|
||||||
|
if (otherPrinting == PrintingInfo()) {
|
||||||
|
return getCard({cardName});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The source card does have a printing defined, which means we can attempt to get a card from the same set.
|
||||||
|
PrintingInfo relatedPrinting = getSpecificPrinting(cardName, otherPrinting.getSet()->getCorrectedShortName(), "");
|
||||||
|
ExactCard relatedCard(guessCard({cardName}).getCardPtr(), relatedPrinting);
|
||||||
|
|
||||||
|
// If we didn't find a card from the same set, just try to find any card with the same name.
|
||||||
|
return relatedCard ? relatedCard : getCard({cardName});
|
||||||
|
}
|
||||||
|
|
||||||
CardSetPtr CardDatabase::getSet(const QString &setName)
|
CardSetPtr CardDatabase::getSet(const QString &setName)
|
||||||
{
|
{
|
||||||
if (sets.contains(setName)) {
|
if (sets.contains(setName)) {
|
||||||
|
|
@ -252,112 +366,6 @@ SetList CardDatabase::getSetList() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadFromFile(const QString &fileName)
|
|
||||||
{
|
|
||||||
QFile file(fileName);
|
|
||||||
file.open(QIODevice::ReadOnly);
|
|
||||||
if (!file.isOpen()) {
|
|
||||||
return FileError;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto parser : availableParsers) {
|
|
||||||
file.reset();
|
|
||||||
if (parser->getCanParseFile(fileName, file)) {
|
|
||||||
file.reset();
|
|
||||||
parser->parseFile(file);
|
|
||||||
return Ok;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadCardDatabase(const QString &path)
|
|
||||||
{
|
|
||||||
auto startTime = QTime::currentTime();
|
|
||||||
LoadStatus tempLoadStatus = NotLoaded;
|
|
||||||
if (!path.isEmpty()) {
|
|
||||||
loadFromFileMutex->lock();
|
|
||||||
tempLoadStatus = loadFromFile(path);
|
|
||||||
loadFromFileMutex->unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
int msecs = startTime.msecsTo(QTime::currentTime());
|
|
||||||
qCInfo(CardDatabaseLoadingLog) << "Loaded card database: Path =" << path << "Status =" << tempLoadStatus
|
|
||||||
<< "Cards =" << cards.size() << "Sets =" << sets.size()
|
|
||||||
<< QString("%1ms").arg(msecs);
|
|
||||||
|
|
||||||
return tempLoadStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadStatus CardDatabase::loadCardDatabases()
|
|
||||||
{
|
|
||||||
reloadDatabaseMutex->lock();
|
|
||||||
|
|
||||||
qCInfo(CardDatabaseLoadingLog) << "Card Database Loading Started";
|
|
||||||
|
|
||||||
clear(); // remove old db
|
|
||||||
|
|
||||||
loadStatus = loadCardDatabase(SettingsCache::instance().getCardDatabasePath()); // load main card database
|
|
||||||
loadCardDatabase(SettingsCache::instance().getTokenDatabasePath()); // load tokens database
|
|
||||||
loadCardDatabase(SettingsCache::instance().getSpoilerCardDatabasePath()); // load spoilers database
|
|
||||||
|
|
||||||
// find all custom card databases, recursively & following symlinks
|
|
||||||
// then load them alphabetically
|
|
||||||
QDirIterator customDatabaseIterator(SettingsCache::instance().getCustomCardDatabasePath(), QStringList() << "*.xml",
|
|
||||||
QDir::Files, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
|
|
||||||
QStringList databasePaths;
|
|
||||||
while (customDatabaseIterator.hasNext()) {
|
|
||||||
customDatabaseIterator.next();
|
|
||||||
databasePaths.push_back(customDatabaseIterator.filePath());
|
|
||||||
}
|
|
||||||
databasePaths.sort();
|
|
||||||
|
|
||||||
for (auto i = 0; i < databasePaths.size(); ++i) {
|
|
||||||
const auto &databasePath = databasePaths.at(i);
|
|
||||||
qCInfo(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << databasePath << ")";
|
|
||||||
loadCardDatabase(databasePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
// AFTER all the cards have been loaded
|
|
||||||
|
|
||||||
// resolve the reverse-related tags
|
|
||||||
refreshCachedReverseRelatedCards();
|
|
||||||
|
|
||||||
if (loadStatus == Ok) {
|
|
||||||
checkUnknownSets(); // update deck editors, etc
|
|
||||||
qCInfo(CardDatabaseLoadingSuccessOrFailureLog) << "Card Database Loading Success";
|
|
||||||
emit cardDatabaseLoadingFinished();
|
|
||||||
} else {
|
|
||||||
qCInfo(CardDatabaseLoadingSuccessOrFailureLog) << "Card Database Loading Failed";
|
|
||||||
emit cardDatabaseLoadingFailed(); // bring up the settings dialog
|
|
||||||
}
|
|
||||||
|
|
||||||
reloadDatabaseMutex->unlock();
|
|
||||||
return loadStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the card representing the preferred printing of the cardInfo
|
|
||||||
*
|
|
||||||
* @param cardInfo The cardInfo to find the preferred printing for
|
|
||||||
* @return A specific printing of a card
|
|
||||||
*/
|
|
||||||
ExactCard CardDatabase::getPreferredCard(const CardInfoPtr &cardInfo) const
|
|
||||||
{
|
|
||||||
return ExactCard(cardInfo, getPreferredPrinting(cardInfo));
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
|
|
||||||
{
|
|
||||||
CardInfoPtr cardInfo = getCardInfo(cardRef.name);
|
|
||||||
if (!cardInfo) {
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return findPrintingWithId(cardInfo, cardRef.providerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the PrintingInfo in the cardInfo that has the given uuid field.
|
* Finds the PrintingInfo in the cardInfo that has the given uuid field.
|
||||||
*
|
*
|
||||||
|
|
@ -378,6 +386,68 @@ PrintingInfo CardDatabase::findPrintingWithId(const CardInfoPtr &cardInfo, const
|
||||||
return PrintingInfo();
|
return PrintingInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrintingInfo CardDatabase::getSpecificPrinting(const CardRef &cardRef) const
|
||||||
|
{
|
||||||
|
CardInfoPtr cardInfo = getCardInfo(cardRef.name);
|
||||||
|
if (!cardInfo) {
|
||||||
|
return PrintingInfo(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return findPrintingWithId(cardInfo, cardRef.providerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
|
||||||
|
const QString &setShortName,
|
||||||
|
const QString &collectorNumber) const
|
||||||
|
{
|
||||||
|
CardInfoPtr cardInfo = getCardInfo(cardName);
|
||||||
|
if (!cardInfo) {
|
||||||
|
return PrintingInfo(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetToPrintingsMap setMap = cardInfo->getSets();
|
||||||
|
if (setMap.empty()) {
|
||||||
|
return PrintingInfo(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &printings : setMap) {
|
||||||
|
for (auto &cardInfoForSet : printings) {
|
||||||
|
if (!collectorNumber.isEmpty()) {
|
||||||
|
if (cardInfoForSet.getSet()->getShortName() == setShortName &&
|
||||||
|
cardInfoForSet.getProperty("num") == collectorNumber) {
|
||||||
|
return cardInfoForSet;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (cardInfoForSet.getSet()->getShortName() == setShortName) {
|
||||||
|
return cardInfoForSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PrintingInfo(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the card representing the preferred printing of the cardInfo
|
||||||
|
*
|
||||||
|
* @param cardInfo The cardInfo to find the preferred printing for
|
||||||
|
* @return A specific printing of a card
|
||||||
|
*/
|
||||||
|
ExactCard CardDatabase::getPreferredCard(const CardInfoPtr &cardInfo) const
|
||||||
|
{
|
||||||
|
return ExactCard(cardInfo, getPreferredPrinting(cardInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CardDatabase::isPreferredPrinting(const CardRef &cardRef) const
|
||||||
|
{
|
||||||
|
if (cardRef.providerId.startsWith("card_")) {
|
||||||
|
return cardRef.providerId ==
|
||||||
|
QLatin1String("card_") + cardRef.name + QString("_") + getPreferredPrintingProviderId(cardRef.name);
|
||||||
|
}
|
||||||
|
return cardRef.providerId == getPreferredPrintingProviderId(cardRef.name);
|
||||||
|
}
|
||||||
|
|
||||||
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
|
PrintingInfo CardDatabase::getPreferredPrinting(const QString &cardName) const
|
||||||
{
|
{
|
||||||
CardInfoPtr cardInfo = getCardInfo(cardName);
|
CardInfoPtr cardInfo = getCardInfo(cardName);
|
||||||
|
|
@ -416,38 +486,6 @@ PrintingInfo CardDatabase::getPreferredPrinting(const CardInfoPtr &cardInfo) con
|
||||||
return PrintingInfo(nullptr);
|
return PrintingInfo(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintingInfo CardDatabase::getSpecificPrinting(const QString &cardName,
|
|
||||||
const QString &setShortName,
|
|
||||||
const QString &collectorNumber) const
|
|
||||||
{
|
|
||||||
CardInfoPtr cardInfo = getCardInfo(cardName);
|
|
||||||
if (!cardInfo) {
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
SetToPrintingsMap setMap = cardInfo->getSets();
|
|
||||||
if (setMap.empty()) {
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto &printings : setMap) {
|
|
||||||
for (auto &cardInfoForSet : printings) {
|
|
||||||
if (collectorNumber != nullptr) {
|
|
||||||
if (cardInfoForSet.getSet()->getShortName() == setShortName &&
|
|
||||||
cardInfoForSet.getProperty("num") == collectorNumber) {
|
|
||||||
return cardInfoForSet;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (cardInfoForSet.getSet()->getShortName() == setShortName) {
|
|
||||||
return cardInfoForSet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return PrintingInfo(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CardDatabase::getPreferredPrintingProviderId(const QString &cardName) const
|
QString CardDatabase::getPreferredPrintingProviderId(const QString &cardName) const
|
||||||
{
|
{
|
||||||
PrintingInfo preferredPrinting = getPreferredPrinting(cardName);
|
PrintingInfo preferredPrinting = getPreferredPrinting(cardName);
|
||||||
|
|
@ -463,58 +501,6 @@ QString CardDatabase::getPreferredPrintingProviderId(const QString &cardName) co
|
||||||
return defaultCardInfo->getName();
|
return defaultCardInfo->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CardDatabase::isPreferredPrinting(const CardRef &cardRef) const
|
|
||||||
{
|
|
||||||
if (cardRef.providerId.startsWith("card_")) {
|
|
||||||
return cardRef.providerId ==
|
|
||||||
QLatin1String("card_") + cardRef.name + QString("_") + getPreferredPrintingProviderId(cardRef.name);
|
|
||||||
}
|
|
||||||
return cardRef.providerId == getPreferredPrintingProviderId(cardRef.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
ExactCard CardDatabase::getCardFromSameSet(const QString &cardName, const PrintingInfo &otherPrinting) const
|
|
||||||
{
|
|
||||||
// The source card does not have a printing defined, which means we can't get a card from the same set.
|
|
||||||
if (otherPrinting == PrintingInfo()) {
|
|
||||||
return getCard({cardName});
|
|
||||||
}
|
|
||||||
|
|
||||||
// The source card does have a printing defined, which means we can attempt to get a card from the same set.
|
|
||||||
PrintingInfo relatedPrinting = getSpecificPrinting(cardName, otherPrinting.getSet()->getCorrectedShortName(), "");
|
|
||||||
ExactCard relatedCard = ExactCard(guessCard({cardName}).getCardPtr(), relatedPrinting);
|
|
||||||
|
|
||||||
// We didn't find a card from the same set, just try to find any card with the same name.
|
|
||||||
if (!relatedCard) {
|
|
||||||
return getCard({cardName});
|
|
||||||
}
|
|
||||||
|
|
||||||
return relatedCard;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabase::refreshCachedReverseRelatedCards()
|
|
||||||
{
|
|
||||||
for (const CardInfoPtr &card : cards)
|
|
||||||
card->resetReverseRelatedCards2Me();
|
|
||||||
|
|
||||||
for (const CardInfoPtr &card : cards) {
|
|
||||||
if (card->getReverseRelatedCards().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (CardRelation *cardRelation : card->getReverseRelatedCards()) {
|
|
||||||
const QString &targetCard = cardRelation->getName();
|
|
||||||
if (!cards.contains(targetCard)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *newCardRelation = new CardRelation(
|
|
||||||
card->getName(), cardRelation->getAttachType(), cardRelation->getIsCreateAllExclusion(),
|
|
||||||
cardRelation->getIsVariable(), cardRelation->getDefaultCount(), cardRelation->getIsPersistent());
|
|
||||||
cards.value(targetCard)->addReverseRelatedCards2Me(newCardRelation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList CardDatabase::getAllMainCardTypes() const
|
QStringList CardDatabase::getAllMainCardTypes() const
|
||||||
{
|
{
|
||||||
QSet<QString> types;
|
QSet<QString> types;
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,7 @@ public:
|
||||||
* function, so you don't need to simplify it beforehand.
|
* function, so you don't need to simplify it beforehand.
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
[[nodiscard]] CardInfoPtr getCardBySimpleName(const QString &cardName) const;
|
||||||
|
CardInfoPtr lookupCardByName(const QString &name) const;
|
||||||
|
|
||||||
CardSetPtr getSet(const QString &setName);
|
CardSetPtr getSet(const QString &setName);
|
||||||
const CardNameMap &getCardList() const
|
const CardNameMap &getCardList() const
|
||||||
|
|
@ -112,6 +113,7 @@ public:
|
||||||
void enableAllUnknownSets();
|
void enableAllUnknownSets();
|
||||||
void markAllSetsAsKnown();
|
void markAllSetsAsKnown();
|
||||||
void notifyEnabledSetsChanged();
|
void notifyEnabledSetsChanged();
|
||||||
|
static QStringList collectCustomDatabasePaths();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
LoadStatus loadCardDatabases();
|
LoadStatus loadCardDatabases();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "card_search_model.h"
|
#include "card_search_model.h"
|
||||||
|
|
||||||
#include "../utility/levenshtein.h"
|
#include "../../../utility/levenshtein.h"
|
||||||
|
#include "../card_database_model.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef CARD_SEARCH_MODEL_H
|
#ifndef CARD_SEARCH_MODEL_H
|
||||||
#define CARD_SEARCH_MODEL_H
|
#define CARD_SEARCH_MODEL_H
|
||||||
|
|
||||||
#include "card_database_model.h"
|
#include "../card_database_display_model.h"
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
|
|
@ -1,157 +1,7 @@
|
||||||
|
#include "card_database_display_model.h"
|
||||||
|
|
||||||
#include "card_database_model.h"
|
#include "card_database_model.h"
|
||||||
|
|
||||||
#include "../filters/filter_tree.h"
|
|
||||||
|
|
||||||
#include <QMap>
|
|
||||||
|
|
||||||
#define CARDDBMODEL_COLUMNS 6
|
|
||||||
|
|
||||||
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromEnabledSets, QObject *parent)
|
|
||||||
: QAbstractListModel(parent), db(_db), showOnlyCardsFromEnabledSets(_showOnlyCardsFromEnabledSets)
|
|
||||||
{
|
|
||||||
connect(db, &CardDatabase::cardAdded, this, &CardDatabaseModel::cardAdded);
|
|
||||||
connect(db, &CardDatabase::cardRemoved, this, &CardDatabaseModel::cardRemoved);
|
|
||||||
connect(db, &CardDatabase::cardDatabaseEnabledSetsChanged, this,
|
|
||||||
&CardDatabaseModel::cardDatabaseEnabledSetsChanged);
|
|
||||||
|
|
||||||
cardDatabaseEnabledSetsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
CardDatabaseModel::~CardDatabaseModel() = default;
|
|
||||||
|
|
||||||
QMap<wchar_t, wchar_t> CardDatabaseDisplayModel::characterTranslation = {{L'“', L'\"'},
|
|
||||||
{L'”', L'\"'},
|
|
||||||
{L'‘', L'\''},
|
|
||||||
{L'’', L'\''}};
|
|
||||||
|
|
||||||
int CardDatabaseModel::rowCount(const QModelIndex & /*parent*/) const
|
|
||||||
{
|
|
||||||
return cardList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
|
|
||||||
{
|
|
||||||
return CARDDBMODEL_COLUMNS;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (!index.isValid() || index.row() >= cardList.size() || index.column() >= CARDDBMODEL_COLUMNS ||
|
|
||||||
(role != Qt::DisplayRole && role != SortRole))
|
|
||||||
return QVariant();
|
|
||||||
|
|
||||||
CardInfoPtr card = cardList.at(index.row());
|
|
||||||
switch (index.column()) {
|
|
||||||
case NameColumn:
|
|
||||||
return card->getName();
|
|
||||||
case SetListColumn:
|
|
||||||
return card->getSetsNames();
|
|
||||||
case ManaCostColumn:
|
|
||||||
return role == SortRole ? QString("%1%2").arg(card->getCmc(), 4, QChar('0')).arg(card->getManaCost())
|
|
||||||
: card->getManaCost();
|
|
||||||
case CardTypeColumn:
|
|
||||||
return card->getCardType();
|
|
||||||
case PTColumn:
|
|
||||||
return card->getPowTough();
|
|
||||||
case ColorColumn:
|
|
||||||
return card->getColors();
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
if (role != Qt::DisplayRole)
|
|
||||||
return QVariant();
|
|
||||||
if (orientation != Qt::Horizontal)
|
|
||||||
return QVariant();
|
|
||||||
switch (section) {
|
|
||||||
case NameColumn:
|
|
||||||
return QString(tr("Name"));
|
|
||||||
case SetListColumn:
|
|
||||||
return QString(tr("Sets"));
|
|
||||||
case ManaCostColumn:
|
|
||||||
return QString(tr("Mana cost"));
|
|
||||||
case CardTypeColumn:
|
|
||||||
return QString(tr("Card type"));
|
|
||||||
case PTColumn:
|
|
||||||
return QString(tr("P/T"));
|
|
||||||
case ColorColumn:
|
|
||||||
return QString(tr("Color(s)"));
|
|
||||||
default:
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabaseModel::cardInfoChanged(CardInfoPtr card)
|
|
||||||
{
|
|
||||||
const int row = cardList.indexOf(card);
|
|
||||||
if (row == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
|
||||||
{
|
|
||||||
if (!showOnlyCardsFromEnabledSets)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (const auto &printings : card->getSets()) {
|
|
||||||
for (const auto &printing : printings) {
|
|
||||||
if (printing.getSet()->getEnabled())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabaseModel::cardDatabaseEnabledSetsChanged()
|
|
||||||
{
|
|
||||||
// remove all the cards no more present in at least one enabled set
|
|
||||||
for (const CardInfoPtr &card : cardList) {
|
|
||||||
if (!checkCardHasAtLeastOneEnabledSet(card)) {
|
|
||||||
cardRemoved(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// re-check all the card currently not shown, maybe their part of a newly-enabled set
|
|
||||||
for (const CardInfoPtr &card : db->getCardList()) {
|
|
||||||
if (!cardListSet.contains(card)) {
|
|
||||||
cardAdded(card);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabaseModel::cardAdded(CardInfoPtr card)
|
|
||||||
{
|
|
||||||
if (checkCardHasAtLeastOneEnabledSet(card)) {
|
|
||||||
// add the card if it's present in at least one enabled set
|
|
||||||
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
|
||||||
cardList.append(card);
|
|
||||||
cardListSet.insert(card);
|
|
||||||
connect(card.data(), &CardInfo::cardInfoChanged, this, &CardDatabaseModel::cardInfoChanged);
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDatabaseModel::cardRemoved(CardInfoPtr card)
|
|
||||||
{
|
|
||||||
const int row = cardList.indexOf(card);
|
|
||||||
if (row == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
|
||||||
disconnect(card.data(), nullptr, this, nullptr);
|
|
||||||
cardListSet.remove(card);
|
|
||||||
card.clear();
|
|
||||||
cardList.removeAt(row);
|
|
||||||
endRemoveRows();
|
|
||||||
}
|
|
||||||
|
|
||||||
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent), isToken(ShowAll), filterString(nullptr)
|
: QSortFilterProxyModel(parent), isToken(ShowAll), filterString(nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -165,6 +15,11 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
|
||||||
loadedRowCount = 0;
|
loadedRowCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMap<wchar_t, wchar_t> CardDatabaseDisplayModel::characterTranslation = {{L'“', L'\"'},
|
||||||
|
{L'”', L'\"'},
|
||||||
|
{L'‘', L'\''},
|
||||||
|
{L'’', L'\''}};
|
||||||
|
|
||||||
bool CardDatabaseDisplayModel::canFetchMore(const QModelIndex &index) const
|
bool CardDatabaseDisplayModel::canFetchMore(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
return loadedRowCount < sourceModel()->rowCount(index);
|
return loadedRowCount < sourceModel()->rowCount(index);
|
||||||
|
|
@ -362,36 +217,4 @@ const QString CardDatabaseDisplayModel::sanitizeCardName(const QString &dirtyNam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QString::fromStdWString(toReturn);
|
return QString::fromStdWString(toReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenDisplayModel::TokenDisplayModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TokenDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
|
||||||
{
|
|
||||||
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
|
||||||
return info->getIsToken() && rowMatchesCardName(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
int TokenDisplayModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
// always load all tokens at start
|
|
||||||
return QSortFilterProxyModel::rowCount(parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
TokenEditModel::TokenEditModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TokenEditModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
|
||||||
{
|
|
||||||
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
|
||||||
return info->getIsToken() && info->getSets().contains(CardSet::TOKENS_SETNAME) && rowMatchesCardName(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
int TokenEditModel::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
// always load all tokens at start
|
|
||||||
return QSortFilterProxyModel::rowCount(parent);
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +1,14 @@
|
||||||
#ifndef CARDDATABASEMODEL_H
|
#ifndef COCKATRICE_CARD_DATABASE_DISPLAY_MODEL_H
|
||||||
#define CARDDATABASEMODEL_H
|
#define COCKATRICE_CARD_DATABASE_DISPLAY_MODEL_H
|
||||||
|
|
||||||
#include "../filters/filter_string.h"
|
#include "../../filters/filter_string.h"
|
||||||
#include "card_database.h"
|
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
class FilterTree;
|
class FilterTree;
|
||||||
|
|
||||||
class CardDatabaseModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
enum Columns
|
|
||||||
{
|
|
||||||
NameColumn,
|
|
||||||
SetListColumn,
|
|
||||||
ManaCostColumn,
|
|
||||||
PTColumn,
|
|
||||||
CardTypeColumn,
|
|
||||||
ColorColumn
|
|
||||||
};
|
|
||||||
enum Role
|
|
||||||
{
|
|
||||||
SortRole = Qt::UserRole
|
|
||||||
};
|
|
||||||
CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromEnabledSets, QObject *parent = nullptr);
|
|
||||||
~CardDatabaseModel() override;
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
|
||||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
|
||||||
CardDatabase *getDatabase() const
|
|
||||||
{
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
CardInfoPtr getCard(int index) const
|
|
||||||
{
|
|
||||||
return cardList[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QList<CardInfoPtr> cardList;
|
|
||||||
QSet<CardInfoPtr> cardListSet; // Supports faster lookups in cardDatabaseEnabledSetsChanged()
|
|
||||||
CardDatabase *db;
|
|
||||||
bool showOnlyCardsFromEnabledSets;
|
|
||||||
|
|
||||||
inline bool checkCardHasAtLeastOneEnabledSet(CardInfoPtr card);
|
|
||||||
private slots:
|
|
||||||
void cardAdded(CardInfoPtr card);
|
|
||||||
void cardRemoved(CardInfoPtr card);
|
|
||||||
void cardInfoChanged(CardInfoPtr card);
|
|
||||||
void cardDatabaseEnabledSetsChanged();
|
|
||||||
};
|
|
||||||
|
|
||||||
class CardDatabaseDisplayModel : public QSortFilterProxyModel
|
class CardDatabaseDisplayModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -138,26 +89,4 @@ private slots:
|
||||||
const QString sanitizeCardName(const QString &dirtyName, const QMap<wchar_t, wchar_t> &table);
|
const QString sanitizeCardName(const QString &dirtyName, const QMap<wchar_t, wchar_t> &table);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TokenDisplayModel : public CardDatabaseDisplayModel
|
#endif // COCKATRICE_CARD_DATABASE_DISPLAY_MODEL_H
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit TokenDisplayModel(QObject *parent = nullptr);
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TokenEditModel : public CardDatabaseDisplayModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit TokenEditModel(QObject *parent = nullptr);
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
146
cockatrice/src/database/model/card_database_model.cpp
Normal file
146
cockatrice/src/database/model/card_database_model.cpp
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
#include "card_database_model.h"
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
|
#define CARDDBMODEL_COLUMNS 6
|
||||||
|
|
||||||
|
CardDatabaseModel::CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromEnabledSets, QObject *parent)
|
||||||
|
: QAbstractListModel(parent), db(_db), showOnlyCardsFromEnabledSets(_showOnlyCardsFromEnabledSets)
|
||||||
|
{
|
||||||
|
connect(db, &CardDatabase::cardAdded, this, &CardDatabaseModel::cardAdded);
|
||||||
|
connect(db, &CardDatabase::cardRemoved, this, &CardDatabaseModel::cardRemoved);
|
||||||
|
connect(db, &CardDatabase::cardDatabaseEnabledSetsChanged, this,
|
||||||
|
&CardDatabaseModel::cardDatabaseEnabledSetsChanged);
|
||||||
|
|
||||||
|
cardDatabaseEnabledSetsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
CardDatabaseModel::~CardDatabaseModel() = default;
|
||||||
|
|
||||||
|
int CardDatabaseModel::rowCount(const QModelIndex & /*parent*/) const
|
||||||
|
{
|
||||||
|
return cardList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CardDatabaseModel::columnCount(const QModelIndex & /*parent*/) const
|
||||||
|
{
|
||||||
|
return CARDDBMODEL_COLUMNS;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid() || index.row() >= cardList.size() || index.column() >= CARDDBMODEL_COLUMNS ||
|
||||||
|
(role != Qt::DisplayRole && role != SortRole))
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
CardInfoPtr card = cardList.at(index.row());
|
||||||
|
switch (index.column()) {
|
||||||
|
case NameColumn:
|
||||||
|
return card->getName();
|
||||||
|
case SetListColumn:
|
||||||
|
return card->getSetsNames();
|
||||||
|
case ManaCostColumn:
|
||||||
|
return role == SortRole ? QString("%1%2").arg(card->getCmc(), 4, QChar('0')).arg(card->getManaCost())
|
||||||
|
: card->getManaCost();
|
||||||
|
case CardTypeColumn:
|
||||||
|
return card->getCardType();
|
||||||
|
case PTColumn:
|
||||||
|
return card->getPowTough();
|
||||||
|
case ColorColumn:
|
||||||
|
return card->getColors();
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CardDatabaseModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (role != Qt::DisplayRole)
|
||||||
|
return QVariant();
|
||||||
|
if (orientation != Qt::Horizontal)
|
||||||
|
return QVariant();
|
||||||
|
switch (section) {
|
||||||
|
case NameColumn:
|
||||||
|
return QString(tr("Name"));
|
||||||
|
case SetListColumn:
|
||||||
|
return QString(tr("Sets"));
|
||||||
|
case ManaCostColumn:
|
||||||
|
return QString(tr("Mana cost"));
|
||||||
|
case CardTypeColumn:
|
||||||
|
return QString(tr("Card type"));
|
||||||
|
case PTColumn:
|
||||||
|
return QString(tr("P/T"));
|
||||||
|
case ColorColumn:
|
||||||
|
return QString(tr("Color(s)"));
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabaseModel::cardInfoChanged(CardInfoPtr card)
|
||||||
|
{
|
||||||
|
const int row = cardList.indexOf(card);
|
||||||
|
if (row == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
emit dataChanged(index(row, 0), index(row, CARDDBMODEL_COLUMNS - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CardDatabaseModel::checkCardHasAtLeastOneEnabledSet(CardInfoPtr card)
|
||||||
|
{
|
||||||
|
if (!showOnlyCardsFromEnabledSets)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (const auto &printings : card->getSets()) {
|
||||||
|
for (const auto &printing : printings) {
|
||||||
|
if (printing.getSet()->getEnabled())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabaseModel::cardDatabaseEnabledSetsChanged()
|
||||||
|
{
|
||||||
|
// remove all the cards no more present in at least one enabled set
|
||||||
|
for (const CardInfoPtr &card : cardList) {
|
||||||
|
if (!checkCardHasAtLeastOneEnabledSet(card)) {
|
||||||
|
cardRemoved(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// re-check all the card currently not shown, maybe their part of a newly-enabled set
|
||||||
|
for (const CardInfoPtr &card : db->getCardList()) {
|
||||||
|
if (!cardListSet.contains(card)) {
|
||||||
|
cardAdded(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabaseModel::cardAdded(CardInfoPtr card)
|
||||||
|
{
|
||||||
|
if (checkCardHasAtLeastOneEnabledSet(card)) {
|
||||||
|
// add the card if it's present in at least one enabled set
|
||||||
|
beginInsertRows(QModelIndex(), cardList.size(), cardList.size());
|
||||||
|
cardList.append(card);
|
||||||
|
cardListSet.insert(card);
|
||||||
|
connect(card.data(), &CardInfo::cardInfoChanged, this, &CardDatabaseModel::cardInfoChanged);
|
||||||
|
endInsertRows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardDatabaseModel::cardRemoved(CardInfoPtr card)
|
||||||
|
{
|
||||||
|
const int row = cardList.indexOf(card);
|
||||||
|
if (row == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
|
disconnect(card.data(), nullptr, this, nullptr);
|
||||||
|
cardListSet.remove(card);
|
||||||
|
card.clear();
|
||||||
|
cardList.removeAt(row);
|
||||||
|
endRemoveRows();
|
||||||
|
}
|
||||||
56
cockatrice/src/database/model/card_database_model.h
Normal file
56
cockatrice/src/database/model/card_database_model.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
#ifndef CARDDATABASEMODEL_H
|
||||||
|
#define CARDDATABASEMODEL_H
|
||||||
|
|
||||||
|
#include "../card_database.h"
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QList>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
|
class CardDatabaseModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
enum Columns
|
||||||
|
{
|
||||||
|
NameColumn,
|
||||||
|
SetListColumn,
|
||||||
|
ManaCostColumn,
|
||||||
|
PTColumn,
|
||||||
|
CardTypeColumn,
|
||||||
|
ColorColumn
|
||||||
|
};
|
||||||
|
enum Role
|
||||||
|
{
|
||||||
|
SortRole = Qt::UserRole
|
||||||
|
};
|
||||||
|
CardDatabaseModel(CardDatabase *_db, bool _showOnlyCardsFromEnabledSets, QObject *parent = nullptr);
|
||||||
|
~CardDatabaseModel() override;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
CardDatabase *getDatabase() const
|
||||||
|
{
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
CardInfoPtr getCard(int index) const
|
||||||
|
{
|
||||||
|
return cardList[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<CardInfoPtr> cardList;
|
||||||
|
QSet<CardInfoPtr> cardListSet; // Supports faster lookups in cardDatabaseEnabledSetsChanged()
|
||||||
|
CardDatabase *db;
|
||||||
|
bool showOnlyCardsFromEnabledSets;
|
||||||
|
|
||||||
|
inline bool checkCardHasAtLeastOneEnabledSet(CardInfoPtr card);
|
||||||
|
private slots:
|
||||||
|
void cardAdded(CardInfoPtr card);
|
||||||
|
void cardRemoved(CardInfoPtr card);
|
||||||
|
void cardInfoChanged(CardInfoPtr card);
|
||||||
|
void cardDatabaseEnabledSetsChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
19
cockatrice/src/database/model/token/token_display_model.cpp
Normal file
19
cockatrice/src/database/model/token/token_display_model.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "token_display_model.h"
|
||||||
|
|
||||||
|
#include "../card_database_model.h"
|
||||||
|
|
||||||
|
TokenDisplayModel::TokenDisplayModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TokenDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
|
{
|
||||||
|
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
|
return info->getIsToken() && rowMatchesCardName(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TokenDisplayModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
// always load all tokens at start
|
||||||
|
return QSortFilterProxyModel::rowCount(parent);
|
||||||
|
}
|
||||||
17
cockatrice/src/database/model/token/token_display_model.h
Normal file
17
cockatrice/src/database/model/token/token_display_model.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef COCKATRICE_TOKEN_DISPLAY_MODEL_H
|
||||||
|
#define COCKATRICE_TOKEN_DISPLAY_MODEL_H
|
||||||
|
|
||||||
|
#include "../card_database_display_model.h"
|
||||||
|
|
||||||
|
class TokenDisplayModel : public CardDatabaseDisplayModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TokenDisplayModel(QObject *parent = nullptr);
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_TOKEN_DISPLAY_MODEL_H
|
||||||
19
cockatrice/src/database/model/token/token_edit_model.cpp
Normal file
19
cockatrice/src/database/model/token/token_edit_model.cpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "token_edit_model.h"
|
||||||
|
|
||||||
|
#include "../card_database_model.h"
|
||||||
|
|
||||||
|
TokenEditModel::TokenEditModel(QObject *parent) : CardDatabaseDisplayModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TokenEditModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
|
||||||
|
{
|
||||||
|
CardInfoPtr info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
|
||||||
|
return info->getIsToken() && info->getSets().contains(CardSet::TOKENS_SETNAME) && rowMatchesCardName(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
int TokenEditModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
// always load all tokens at start
|
||||||
|
return QSortFilterProxyModel::rowCount(parent);
|
||||||
|
}
|
||||||
17
cockatrice/src/database/model/token/token_edit_model.h
Normal file
17
cockatrice/src/database/model/token/token_edit_model.h
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef COCKATRICE_TOKEN_EDIT_MODEL_H
|
||||||
|
#define COCKATRICE_TOKEN_EDIT_MODEL_H
|
||||||
|
|
||||||
|
#include "../card_database_display_model.h"
|
||||||
|
|
||||||
|
class TokenEditModel : public CardDatabaseDisplayModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit TokenEditModel(QObject *parent = nullptr);
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_TOKEN_EDIT_MODEL_H
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
#include "../client/get_text_with_max.h"
|
#include "../client/get_text_with_max.h"
|
||||||
#include "../database/card_database.h"
|
#include "../database/card_database.h"
|
||||||
#include "../database/card_database_manager.h"
|
#include "../database/card_database_manager.h"
|
||||||
#include "../database/card_database_model.h"
|
#include "../database/model/card_database_model.h"
|
||||||
|
#include "../database/model/token/token_edit_model.h"
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
#include "trice_limits.h"
|
#include "trice_limits.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#include "dlg_create_token.h"
|
#include "dlg_create_token.h"
|
||||||
|
|
||||||
#include "../../database/card_database_manager.h"
|
#include "../../database/card_database_manager.h"
|
||||||
#include "../../database/card_database_model.h"
|
#include "../../database/model/card_database_model.h"
|
||||||
|
#include "../../database/model/token/token_display_model.h"
|
||||||
#include "../../interface/widgets/cards/card_info_picture_widget.h"
|
#include "../../interface/widgets/cards/card_info_picture_widget.h"
|
||||||
#include "../../main.h"
|
#include "../../main.h"
|
||||||
#include "../../settings/cache_settings.h"
|
#include "../../settings/cache_settings.h"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#ifndef DECK_EDITOR_DATABASE_DISPLAY_WIDGET_H
|
#ifndef DECK_EDITOR_DATABASE_DISPLAY_WIDGET_H
|
||||||
#define DECK_EDITOR_DATABASE_DISPLAY_WIDGET_H
|
#define DECK_EDITOR_DATABASE_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "../../../database/card_database_model.h"
|
#include "../../../database/model/card_database_display_model.h"
|
||||||
|
#include "../../../database/model/card_database_model.h"
|
||||||
#include "../../../deck/custom_line_edit.h"
|
#include "../../../deck/custom_line_edit.h"
|
||||||
#include "../../../tabs/abstract_tab_deck_editor.h"
|
#include "../../../tabs/abstract_tab_deck_editor.h"
|
||||||
#include "../../../utility/key_signals.h"
|
#include "../../../utility/key_signals.h"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "deck_editor_filter_dock_widget.h"
|
#include "deck_editor_filter_dock_widget.h"
|
||||||
|
|
||||||
#include "../../../database/card_database_model.h"
|
#include "../../../database/model/card_database_model.h"
|
||||||
#include "../../../filters/filter_builder.h"
|
#include "../../../filters/filter_builder.h"
|
||||||
#include "../../../filters/filter_tree_model.h"
|
#include "../../../filters/filter_tree_model.h"
|
||||||
#include "../../../settings/cache_settings.h"
|
#include "../../../settings/cache_settings.h"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define VISUAL_DATABASE_DISPLAY_WIDGET_H
|
#define VISUAL_DATABASE_DISPLAY_WIDGET_H
|
||||||
|
|
||||||
#include "../../../database/card_database.h"
|
#include "../../../database/card_database.h"
|
||||||
#include "../../../database/card_database_model.h"
|
#include "../../../database/model/card_database_model.h"
|
||||||
#include "../../../deck/custom_line_edit.h"
|
#include "../../../deck/custom_line_edit.h"
|
||||||
#include "../../../deck/deck_list_model.h"
|
#include "../../../deck/deck_list_model.h"
|
||||||
#include "../../../filters/filter_tree_model.h"
|
#include "../../../filters/filter_tree_model.h"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
#include "visual_deck_editor_widget.h"
|
#include "visual_deck_editor_widget.h"
|
||||||
|
|
||||||
#include "../../../database/card_completer_proxy_model.h"
|
|
||||||
#include "../../../database/card_database.h"
|
#include "../../../database/card_database.h"
|
||||||
#include "../../../database/card_database_manager.h"
|
#include "../../../database/card_database_manager.h"
|
||||||
#include "../../../database/card_database_model.h"
|
#include "../../../database/model/card/card_completer_proxy_model.h"
|
||||||
#include "../../../database/card_search_model.h"
|
#include "../../../database/model/card/card_search_model.h"
|
||||||
|
#include "../../../database/model/card_database_model.h"
|
||||||
#include "../../../deck/deck_list_model.h"
|
#include "../../../deck/deck_list_model.h"
|
||||||
#include "../../../deck/deck_loader.h"
|
#include "../../../deck/deck_loader.h"
|
||||||
#include "../../../main.h"
|
#include "../../../main.h"
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
#ifndef VISUAL_DECK_EDITOR_H
|
#ifndef VISUAL_DECK_EDITOR_H
|
||||||
#define VISUAL_DECK_EDITOR_H
|
#define VISUAL_DECK_EDITOR_H
|
||||||
|
|
||||||
#include "../../../database/card_completer_proxy_model.h"
|
|
||||||
#include "../../../database/card_database.h"
|
#include "../../../database/card_database.h"
|
||||||
#include "../../../database/card_database_model.h"
|
#include "../../../database/model/card/card_completer_proxy_model.h"
|
||||||
|
#include "../../../database/model/card_database_display_model.h"
|
||||||
|
#include "../../../database/model/card_database_model.h"
|
||||||
#include "../../../deck/deck_list_model.h"
|
#include "../../../deck/deck_list_model.h"
|
||||||
#include "../cards/card_info_picture_with_text_overlay_widget.h"
|
#include "../cards/card_info_picture_with_text_overlay_widget.h"
|
||||||
#include "../cards/card_size_widget.h"
|
#include "../cards/card_size_widget.h"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "../client/tapped_out_interface.h"
|
#include "../client/tapped_out_interface.h"
|
||||||
#include "../database/card_database_manager.h"
|
#include "../database/card_database_manager.h"
|
||||||
#include "../database/card_database_model.h"
|
#include "../database/model/card_database_model.h"
|
||||||
#include "../deck/deck_stats_interface.h"
|
#include "../deck/deck_stats_interface.h"
|
||||||
#include "../dialogs/dlg_load_deck.h"
|
#include "../dialogs/dlg_load_deck.h"
|
||||||
#include "../dialogs/dlg_load_deck_from_clipboard.h"
|
#include "../dialogs/dlg_load_deck_from_clipboard.h"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#include "tab_edhrec_main.h"
|
#include "tab_edhrec_main.h"
|
||||||
|
|
||||||
#include "../../../database/card_completer_proxy_model.h"
|
|
||||||
#include "../../../database/card_database_manager.h"
|
#include "../../../database/card_database_manager.h"
|
||||||
#include "../../../database/card_search_model.h"
|
#include "../../../database/model/card/card_completer_proxy_model.h"
|
||||||
|
#include "../../../database/model/card/card_search_model.h"
|
||||||
#include "../../tab_supervisor.h"
|
#include "../../tab_supervisor.h"
|
||||||
#include "api_response/average_deck/edhrec_average_deck_api_response.h"
|
#include "api_response/average_deck/edhrec_average_deck_api_response.h"
|
||||||
#include "api_response/commander/edhrec_commander_api_response.h"
|
#include "api_response/commander/edhrec_commander_api_response.h"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include "../client/deck_editor_menu.h"
|
#include "../client/deck_editor_menu.h"
|
||||||
#include "../client/tapped_out_interface.h"
|
#include "../client/tapped_out_interface.h"
|
||||||
#include "../database/card_database_manager.h"
|
#include "../database/card_database_manager.h"
|
||||||
#include "../database/card_database_model.h"
|
#include "../database/model/card_database_model.h"
|
||||||
#include "../dialogs/dlg_load_deck.h"
|
#include "../dialogs/dlg_load_deck.h"
|
||||||
#include "../dialogs/dlg_load_deck_from_clipboard.h"
|
#include "../dialogs/dlg_load_deck_from_clipboard.h"
|
||||||
#include "../filters/filter_builder.h"
|
#include "../filters/filter_builder.h"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "tab_deck_editor_visual.h"
|
#include "tab_deck_editor_visual.h"
|
||||||
|
|
||||||
#include "../../database/card_database_model.h"
|
#include "../../database/model/card_database_model.h"
|
||||||
#include "../../deck/deck_list_model.h"
|
#include "../../deck/deck_list_model.h"
|
||||||
#include "../../deck/deck_stats_interface.h"
|
#include "../../deck/deck_stats_interface.h"
|
||||||
#include "../../filters/filter_builder.h"
|
#include "../../filters/filter_builder.h"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "tab_deck_storage_visual.h"
|
#include "tab_deck_storage_visual.h"
|
||||||
|
|
||||||
#include "../../database/card_database_model.h"
|
#include "../../database/model/card_database_model.h"
|
||||||
#include "../../interface/widgets/cards/deck_preview_card_picture_widget.h"
|
#include "../../interface/widgets/cards/deck_preview_card_picture_widget.h"
|
||||||
#include "../../interface/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
#include "../../interface/widgets/visual_deck_storage/visual_deck_storage_widget.h"
|
||||||
#include "../tab_supervisor.h"
|
#include "../tab_supervisor.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue