Skip to content

Conversation

@AJWilderland
Copy link

Problem
File → Export… → Games in filter in ChessX exports the correct number of games, but the wrong subset: it writes the first N games of the database instead of the filtered games.

Root cause
Output::outputUtf8(QTextStream&, FilterX&) and Output::outputLatin1(QDataStream&, FilterX&) iterate:

for (int i = 0; i < filter.count(); ++i)
    filter.database()->loadGame(i, game);

Here filter.count() is the number of included games, but i is used as a database index. This ignores the mask in filter.

Fix

  • Loop over the full index range (filter.size()).
  • At each index i, check filter.contains(i) to test membership.
  • Only then call filter.database()->loadGame(i, game).
  • Use a new counter doneCount which is incremented only for included games to compute progress.

No changes to UI, GameList, or FilterModel. The export records now matches the filtered view.

@AJWilderland
Copy link
Author

Thank you for reviewing this fix. This PR addresses a long-standing mismatch between the filtered games displayed in the UI and the list of games actually exported by the Export… → Games in filter command.
To test:
1. Load a database
2. Apply a filter via Find → Find tag… (e.g., White = myUsername)
3. Use File → Export… → Games in filter to save a PGN
4. Load the PGN and confirm every game meets the filter criteria (no false positives)
5. Also ensure that no crash or performance regression occurs when the filter is empty or large.

If further adjustments are needed (e.g., updating unit tests, adding a UI tooltip), I can submit a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant