mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-27 00:14:40 -07:00
[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:
parent
40ac336a28
commit
c301ebd5d6
3 changed files with 40 additions and 52 deletions
|
|
@ -99,30 +99,7 @@ void RemotePublicDecksModel::rebuildVisibleIndices()
|
||||||
|
|
||||||
if (!activeColors.isEmpty()) {
|
if (!activeColors.isEmpty()) {
|
||||||
const QString &identity = entry.colorIdentity;
|
const QString &identity = entry.colorIdentity;
|
||||||
bool colorMatch = true;
|
if (!colorIdentityMatches(colorFilterMode, activeColors, identity)) {
|
||||||
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) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,34 @@ VisualDeckStorageSortFilterProxyModel::VisualDeckStorageSortFilterProxyModel(QOb
|
||||||
setDynamicSortFilter(false);
|
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)
|
void VisualDeckStorageSortFilterProxyModel::setSourceModel(QAbstractItemModel *model)
|
||||||
{
|
{
|
||||||
if (QAbstractItemModel *oldModel = sourceModel()) {
|
if (QAbstractItemModel *oldModel = sourceModel()) {
|
||||||
|
|
@ -255,34 +283,7 @@ void VisualDeckStorageSortFilterProxyModel::updateColorMatches()
|
||||||
|
|
||||||
for (int row = 0; row < count; ++row) {
|
for (int row = 0; row < count; ++row) {
|
||||||
const QString colorIdentity = source->dataForRow(row).colorIdentity;
|
const QString colorIdentity = source->dataForRow(row).colorIdentity;
|
||||||
|
colorMatches[row] = colorIdentityMatches(colorFilterMode, activeColors, 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,4 +102,14 @@ private:
|
||||||
QList<bool> colorMatches; ///< Per-row color identity match.
|
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
|
#endif // VISUAL_DECK_STORAGE_SORT_FILTER_PROXY_MODEL_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue