Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardDatabaseQuerier Class Reference

Provides lookup and convenience functions for querying cards and their printings. More...

#include <card_database_querier.h>

Inheritance diagram for CardDatabaseQuerier:
[legend]
Collaboration diagram for CardDatabaseQuerier:
[legend]

Public Member Functions

 CardDatabaseQuerier (QObject *parent, const CardDatabase *db, const ICardPreferenceProvider *prefs)
 Constructs a CardDatabaseQuerier.
CardInfoPtr getCardInfo (const QString &cardName) const
 Retrieves a card by its exact name.
QList< CardInfoPtrgetCardInfos (const QStringList &cardNames) const
 Retrieves multiple cards by their exact names.
CardInfoPtr getCardBySimpleName (const QString &cardName) const
 Retrieves a card using simplified name matching.
CardInfoPtr lookupCardByName (const QString &name) const
 Looks up a card using exact name first, then simplified matching as fallback.
ExactCard getCard (const CardRef &cardRef) const
 Converts a CardRef into an ExactCard.
QList< ExactCardgetCards (const QList< CardRef > &cardRefs) const
 Resolves multiple CardRefs into ExactCards.
ExactCard guessCard (const CardRef &cardRef) const
 Attempts a more flexible card lookup using both simple name matching and CardRef rules.
ExactCard getRandomCard () const
 Returns a random card from the database using the preferred printing.
ExactCard getCardFromSameSet (const QString &cardName, const PrintingInfo &otherPrinting) const
 Returns a printing of a card from the same set as another given printing when possible.
ExactCard getPreferredCard (const QString &cardName) const
 Returns the preferred printing of a card based on user preferences and set priority.
ExactCard getPreferredCard (const CardInfoPtr &cardInfo) const
 Returns the preferred printing of a card based on user preferences and set priority.
bool isPreferredPrinting (const CardRef &cardRef) const
 Checks whether the CardRef refers to the preferred printing.
PrintingInfo getPreferredPrinting (const QString &cardName) const
 Returns the preferred printing for the given card name.
PrintingInfo getPreferredPrinting (const CardInfoPtr &cardInfo) const
 Returns the preferred printing for the given card.
QString getPreferredPrintingProviderId (const QString &cardName) const
 Returns the providerId of the preferred printing.
PrintingInfo getSpecificPrinting (const CardRef &cardRef) const
 Retrieves a specific printing referenced by CardRef.
PrintingInfo getSpecificPrinting (const QString &cardName, const QString &setCode, const QString &collectorNumber) const
 Searches for a specific printing by set code and collector number.
PrintingInfo findPrintingWithId (const CardInfoPtr &card, const QString &providerId) const
 Searches for a printing that matches a given providerId.
QStringList getAllMainCardTypes () const
 Returns a list of all main card types present in the database.
QMap< QString, int > getAllMainCardTypesWithCount () const
 Returns a mapping of main card types to their occurrence counts.
QMap< QString, int > getAllSubCardTypesWithCount () const
 Returns a mapping of card subtypes to their occurrence counts.

Private Attributes

const CardDatabasedb
 Card database used for all lookups.
const ICardPreferenceProviderprefs
 Preference provider for preferred printings.

Detailed Description

Provides lookup and convenience functions for querying cards and their printings.

The CardDatabaseQuerier class offers various lookup helpers for retrieving card information (e.g., CardInfoPtr, ExactCard, and PrintingInfo) from a CardDatabase. It also applies user printing preferences via ICardPreferenceProvider when determining preferred printings.

Constructor & Destructor Documentation

◆ CardDatabaseQuerier()

CardDatabaseQuerier::CardDatabaseQuerier ( QObject * parent,
const CardDatabase * db,
const ICardPreferenceProvider * prefs )
explicit

Constructs a CardDatabaseQuerier.

Parameters
parentParent QObject.
dbPointer to the CardDatabase used for lookups.
prefsPointer to card preference provider which supplies user-preference for printings.

Member Function Documentation

◆ findPrintingWithId()

PrintingInfo CardDatabaseQuerier::findPrintingWithId ( const CardInfoPtr & cardInfo,
const QString & providerId ) const
nodiscard

Searches for a printing that matches a given providerId.

Parameters
cardCard to search.
providerIdProvider identifier to match.
Returns
Matching PrintingInfo, or empty if not found.

Finds the PrintingInfo in the cardInfo that has the given uuid field.

Parameters
cardInfoThe CardInfo to search
providerIdThe uuid to look for
Returns
The PrintingInfo, or a default-constructed PrintingInfo if not found.
Here is the caller graph for this function:

◆ getAllMainCardTypes()

QStringList CardDatabaseQuerier::getAllMainCardTypes ( ) const
nodiscard

Returns a list of all main card types present in the database.

Returns
List of main card type strings.

◆ getAllMainCardTypesWithCount()

QMap< QString, int > CardDatabaseQuerier::getAllMainCardTypesWithCount ( ) const
nodiscard

Returns a mapping of main card types to their occurrence counts.

Returns
Map of main card type to count.
Here is the caller graph for this function:

◆ getAllSubCardTypesWithCount()

QMap< QString, int > CardDatabaseQuerier::getAllSubCardTypesWithCount ( ) const
nodiscard

Returns a mapping of card subtypes to their occurrence counts.

Returns
Map of subtype string to count.
Here is the caller graph for this function:

◆ getCard()

ExactCard CardDatabaseQuerier::getCard ( const CardRef & cardRef) const
nodiscard

Converts a CardRef into an ExactCard.

If the providerId is empty, the preferred printing is used. If providerId exists but cannot be found, an ExactCard with an empty PrintingInfo is returned.

Parameters
cardRefCard reference with name and optional providerId.
Returns
The resolved ExactCard, or empty if no card was found.

Looks up the card corresponding to the CardRef. If the providerId is empty, will default to the preferred printing. If providerId is given but not found, the PrintingInfo will be empty.

Parameters
cardRefThe card to look up.
Returns
A specific printing of a card, or empty if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardBySimpleName()

CardInfoPtr CardDatabaseQuerier::getCardBySimpleName ( const QString & cardName) const
nodiscard

Retrieves a card using simplified name matching.

The name is automatically normalized, so callers do not need to simplify it.

Parameters
cardNameA (possibly simplified or misspelled) card name.
Returns
A CardInfoPtr, or null if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardFromSameSet()

ExactCard CardDatabaseQuerier::getCardFromSameSet ( const QString & cardName,
const PrintingInfo & otherPrinting ) const
nodiscard

Returns a printing of a card from the same set as another given printing when possible.

If no matching printing exists, falls back to a standard lookup.

Parameters
cardNameCard to retrieve.
otherPrintingPrinting to match the set against.
Returns
Matching ExactCard if found, otherwise fallback ExactCard.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardInfo()

CardInfoPtr CardDatabaseQuerier::getCardInfo ( const QString & cardName) const
nodiscard

Retrieves a card by its exact name.

Parameters
cardNameExact card name.
Returns
A CardInfoPtr, or null if no matching card exists.

Looks up the cardInfo corresponding to the cardName.

Parameters
cardNameThe card name to look up
Returns
A CardInfoPtr, or null if not corresponding CardInfo is found.
Here is the caller graph for this function:

◆ getCardInfos()

QList< CardInfoPtr > CardDatabaseQuerier::getCardInfos ( const QStringList & cardNames) const
nodiscard

Retrieves multiple cards by their exact names.

Failed lookups are skipped and not included in the result.

Parameters
cardNamesList of exact card names.
Returns
List of CardInfoPtr objects for which a match was found.

Looks up the cardInfos for a list of card names.

Parameters
cardNamesThe card names to look up
Returns
A List of CardInfoPtr. Any failed lookups will be ignored and dropped from the resulting list

◆ getCards()

QList< ExactCard > CardDatabaseQuerier::getCards ( const QList< CardRef > & cardRefs) const
nodiscard

Resolves multiple CardRefs into ExactCards.

Failed entries are not included in the result.

Parameters
cardRefsList of card references.
Returns
List of successfully resolved ExactCards.

Looks up the cards corresponding to the CardRefs. If the providerId is empty, will default to the preferred printing. If providerId is given but not found, the PrintingInfo will be empty.

Parameters
cardRefsThe cards to look up. If providerId is empty for an entry, will default to the preferred printing for that entry. If providerId is given but not found, the PrintingInfo will be empty for that entry.
Returns
A list of cards. Any failed lookups will be ignored and dropped from the resulting list.
Here is the call graph for this function:

◆ getPreferredCard() [1/2]

ExactCard CardDatabaseQuerier::getPreferredCard ( const CardInfoPtr & cardInfo) const
nodiscard

Returns the preferred printing of a card based on user preferences and set priority.

Parameters
cardInfoCard information object.
Returns
The preferred ExactCard.

Gets the card representing the preferred printing of the cardInfo

Parameters
cardInfoThe cardInfo to find the preferred printing for
Returns
A specific printing of a card
Here is the call graph for this function:

◆ getPreferredCard() [2/2]

ExactCard CardDatabaseQuerier::getPreferredCard ( const QString & cardName) const
nodiscard

Returns the preferred printing of a card based on user preferences and set priority.

Parameters
cardNameName of the card.
Returns
The preferred ExactCard.

Gets the card representing the preferred printing of the cardInfo

Parameters
cardNameThe cardName to find the preferred card and printing for
Returns
A specific printing of a card
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPreferredPrinting() [1/2]

PrintingInfo CardDatabaseQuerier::getPreferredPrinting ( const CardInfoPtr & cardInfo) const
nodiscard

Returns the preferred printing for the given card.

Parameters
cardInfoCard information object.
Returns
Preferred PrintingInfo, or empty if not applicable.
Here is the call graph for this function:

◆ getPreferredPrinting() [2/2]

PrintingInfo CardDatabaseQuerier::getPreferredPrinting ( const QString & cardName) const
nodiscard

Returns the preferred printing for the given card name.

Parameters
cardNameCard name.
Returns
Preferred PrintingInfo, or empty if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPreferredPrintingProviderId()

QString CardDatabaseQuerier::getPreferredPrintingProviderId ( const QString & cardName) const
nodiscard

Returns the providerId of the preferred printing.

Parameters
cardNameCard name.
Returns
ProviderId string for preferred printing.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRandomCard()

ExactCard CardDatabaseQuerier::getRandomCard ( ) const
nodiscard

Returns a random card from the database using the preferred printing.

Returns
A random ExactCard, or empty if the database is empty.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecificPrinting() [1/2]

PrintingInfo CardDatabaseQuerier::getSpecificPrinting ( const CardRef & cardRef) const
nodiscard

Retrieves a specific printing referenced by CardRef.

Parameters
cardRefCard reference including providerId.
Returns
Matching PrintingInfo, or empty if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSpecificPrinting() [2/2]

PrintingInfo CardDatabaseQuerier::getSpecificPrinting ( const QString & cardName,
const QString & setCode,
const QString & collectorNumber ) const
nodiscard

Searches for a specific printing by set code and collector number.

Parameters
cardNameCard name to search.
setCodeSet (short) code to match.
collectorNumberCollector number. If empty, any printing from the set is returned.
Returns
Matching PrintingInfo, or empty if not found.
Here is the call graph for this function:

◆ guessCard()

ExactCard CardDatabaseQuerier::guessCard ( const CardRef & cardRef) const
nodiscard

Attempts a more flexible card lookup using both simple name matching and CardRef rules.

If providerId is missing, uses preferred printing. If lookup fails, attempts simplified name.

Parameters
cardRefCard reference to resolve.
Returns
The best-guess ExactCard, or empty if unresolved.

Looks up the card by CardRef, simplifying the name if required. If the providerId is empty, will default to the preferred printing. If providerId is given but not found, the PrintingInfo will be empty.

Parameters
cardRefThe card to look up.
Returns
A specific printing of a card, or empty if not found.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isPreferredPrinting()

bool CardDatabaseQuerier::isPreferredPrinting ( const CardRef & cardRef) const
nodiscard

Checks whether the CardRef refers to the preferred printing.

Parameters
cardRefCard reference to test.
Returns
True if providerId matches the preferred printing.
Here is the call graph for this function:

◆ lookupCardByName()

CardInfoPtr CardDatabaseQuerier::lookupCardByName ( const QString & name) const
nodiscard

Looks up a card using exact name first, then simplified matching as fallback.

Parameters
nameRaw card name input.
Returns
The best-match CardInfoPtr, or null if no match is found.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ db

const CardDatabase* CardDatabaseQuerier::db
private

Card database used for all lookups.

◆ prefs

const ICardPreferenceProvider* CardDatabaseQuerier::prefs
private

Preference provider for preferred printings.


The documentation for this class was generated from the following files: