[Card] Bind search language per FilterString instance

The peg parser rules are set up once per process, so the GenericQuery and
OracleQuery rule actions could not capture per-instance state. Instead of
storing the search language in a process-global that FilterString instance
methods mutate, hand it to the rule actions through a thread-local parse
context and copy it into the filter closures they produce. Card evaluation
in FilterString::check no longer reads any process-global state, and each
instance keeps the language it was built with; constructing one instance no
longer changes what unrelated instances (deck filter, drop-to-hand, zone
views) match against.

The card database display model stores the raw query and rebuilds the
FilterString when the search language changes, since the language is now
bound at parse time.

Add tests for the English/Selected/Both search modes, the English fallback
for untranslated cards, and per-instance language independence.
This commit is contained in:
Lukas Brübach 2026-09-19 10:47:24 +02:00
parent e029173e29
commit 14cf4ee2a9
5 changed files with 81 additions and 33 deletions

View file

@ -239,9 +239,9 @@ void CardDatabaseDisplayModel::setFilterTree(FilterTree *_filterTree)
void CardDatabaseDisplayModel::setStringFilter(const QString &_src)
{
searchText = _src;
delete filterString;
filterString = new FilterString(_src);
filterString->setSearchLanguage(searchLanguage, searchLanguageMode);
filterString = new FilterString(_src, searchLanguage, searchLanguageMode);
dirty();
}
@ -255,7 +255,7 @@ void CardDatabaseDisplayModel::setSearchLanguage(const QString &searchLang, Card
searchLanguageMode = mode;
if (filterString != nullptr) {
filterString->setSearchLanguage(searchLanguage, searchLanguageMode);
setStringFilter(searchText);
}
dirty();
}