[VDS] Share one color-identity match rule between the two deck grids

The remote public decks model verbatim-copied updateColorMatches' switch,
down to the ExactMatch normalization and the fact that Includes/Excludes do
not normalize case. Extract colorIdentityMatches() next to the FilterMode
enum and call it from both so the subtle rule cannot drift.
This commit is contained in:
Lukas Brübach 2026-09-19 07:49:26 +02:00 committed by GitHub
parent 80ad41ea69
commit 9ce9696737
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 52 deletions

View file

@ -99,30 +99,7 @@ void RemotePublicDecksModel::rebuildVisibleIndices()
if (!activeColors.isEmpty()) {
const QString &identity = entry.colorIdentity;
bool colorMatch = true;
switch (colorFilterMode) {
case VisualDeckStorageSortFilterProxyModel::ExactMatch: {
QSet<QChar> activeSet;
for (const QChar &color : activeColors) {
activeSet.insert(color.toUpper());
}
QSet<QChar> identitySet;
for (const QChar &color : identity) {
identitySet.insert(color.toUpper());
}
colorMatch = activeSet == identitySet;
break;
}
case VisualDeckStorageSortFilterProxyModel::Includes:
colorMatch = std::all_of(activeColors.begin(), activeColors.end(),
[&identity](const QChar &color) { return identity.contains(color); });
break;
case VisualDeckStorageSortFilterProxyModel::Excludes:
colorMatch = std::none_of(activeColors.begin(), activeColors.end(),
[&identity](const QChar &color) { return identity.contains(color); });
break;
}
if (!colorMatch) {
if (!colorIdentityMatches(colorFilterMode, activeColors, identity)) {
continue;
}
}

View file

@ -11,6 +11,34 @@ VisualDeckStorageSortFilterProxyModel::VisualDeckStorageSortFilterProxyModel(QOb
setDynamicSortFilter(false);
}
bool colorIdentityMatches(VisualDeckStorageSortFilterProxyModel::FilterMode mode,
const QSet<QChar> &colors,
const QString &identity)
{
switch (mode) {
case VisualDeckStorageSortFilterProxyModel::ExactMatch: {
QSet<QChar> activeColorSet;
for (const QChar &color : colors) {
activeColorSet.insert(color.toUpper());
}
QSet<QChar> colorIdentitySet;
for (const QChar &color : identity) {
colorIdentitySet.insert(color.toUpper());
}
return activeColorSet == colorIdentitySet;
}
case VisualDeckStorageSortFilterProxyModel::Includes:
return std::all_of(colors.begin(), colors.end(),
[&identity](const QChar &color) { return identity.contains(color); });
case VisualDeckStorageSortFilterProxyModel::Excludes:
return std::none_of(colors.begin(), colors.end(),
[&identity](const QChar &color) { return identity.contains(color); });
}
return false;
}
void VisualDeckStorageSortFilterProxyModel::setSourceModel(QAbstractItemModel *model)
{
if (QAbstractItemModel *oldModel = sourceModel()) {
@ -255,34 +283,7 @@ void VisualDeckStorageSortFilterProxyModel::updateColorMatches()
for (int row = 0; row < count; ++row) {
const QString colorIdentity = source->dataForRow(row).colorIdentity;
bool matches = true;
switch (colorFilterMode) {
case ExactMatch: {
QSet<QChar> activeColorSet;
for (const QChar &color : activeColors) {
activeColorSet.insert(color.toUpper());
}
QSet<QChar> colorIdentitySet;
for (const QChar &color : colorIdentity) {
colorIdentitySet.insert(color.toUpper());
}
matches = activeColorSet == colorIdentitySet;
break;
}
case Includes:
matches = std::all_of(activeColors.begin(), activeColors.end(),
[&colorIdentity](const QChar &color) { return colorIdentity.contains(color); });
break;
case Excludes:
matches = std::none_of(activeColors.begin(), activeColors.end(),
[&colorIdentity](const QChar &color) { return colorIdentity.contains(color); });
break;
}
colorMatches[row] = matches;
colorMatches[row] = colorIdentityMatches(colorFilterMode, activeColors, colorIdentity);
}
}

View file

@ -102,4 +102,14 @@ private:
QList<bool> colorMatches; ///< Per-row color identity match.
};
/**
* @brief Whether an identity string matches the active color-identity filter.
*
* The single source of truth for the color identity matching rule, shared by
* the Visual Deck Storage proxy and the remote public decks model.
*/
[[nodiscard]] bool colorIdentityMatches(VisualDeckStorageSortFilterProxyModel::FilterMode mode,
const QSet<QChar> &colors,
const QString &identity);
#endif // VISUAL_DECK_STORAGE_SORT_FILTER_PROXY_MODEL_H