Add modelDirty signal, add helper functions to gather all main and sub card types. (#5819)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL
2025-04-10 04:21:02 +02:00
committed by GitHub
parent 676ea0d5a7
commit 9b5f5595b0
3 changed files with 47 additions and 0 deletions

View File

@@ -472,6 +472,45 @@ QStringList CardDatabase::getAllMainCardTypes() const
return types.values();
}
QMap<QString, int> CardDatabase::getAllMainCardTypesWithCount() const
{
QMap<QString, int> typeCounts;
QHashIterator<QString, CardInfoPtr> cardIterator(cards);
while (cardIterator.hasNext()) {
QString type = cardIterator.next().value()->getMainCardType();
typeCounts[type]++;
}
return typeCounts;
}
QMap<QString, int> CardDatabase::getAllSubCardTypesWithCount() const
{
QMap<QString, int> typeCounts;
QHashIterator<QString, CardInfoPtr> cardIterator(cards);
while (cardIterator.hasNext()) {
QString type = cardIterator.next().value()->getCardType();
QStringList parts = type.split("");
if (parts.size() > 1) { // Ensure there are subtypes
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QStringList subtypes = parts[1].split(" ", Qt::SkipEmptyParts);
#else
QStringList subtypes = parts[1].split(" ", QString::SkipEmptyParts);
#endif
for (const QString &subtype : subtypes) {
typeCounts[subtype]++;
}
}
}
return typeCounts;
}
void CardDatabase::checkUnknownSets()
{
auto _sets = getSetList();

View File

@@ -98,6 +98,8 @@ public:
LoadStatus loadFromFile(const QString &fileName);
bool saveCustomTokensToFile();
QStringList getAllMainCardTypes() const;
QMap<QString, int> getAllMainCardTypesWithCount() const;
QMap<QString, int> getAllSubCardTypesWithCount() const;
LoadStatus getLoadStatus() const
{
return loadStatus;

View File

@@ -87,6 +87,7 @@ public:
void setIsToken(FilterBool _isToken)
{
isToken = _isToken;
emit modelDirty();
dirty();
}
@@ -97,17 +98,20 @@ public:
filterString = nullptr;
}
cardName = sanitizeCardName(_cardName, characterTranslation);
emit modelDirty();
dirty();
}
void setStringFilter(const QString &_src)
{
delete filterString;
filterString = new FilterString(_src);
emit modelDirty();
dirty();
}
void setCardNameSet(const QSet<QString> &_cardNameSet)
{
cardNameSet = _cardNameSet;
emit modelDirty();
dirty();
}
@@ -119,6 +123,8 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
bool canFetchMore(const QModelIndex &parent) const override;
void fetchMore(const QModelIndex &parent) override;
signals:
void modelDirty();
protected:
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;