ThoreBor / Anki_Leaderboard

Anki 2.1 Add-On
https://ankiweb.net/shared/info/41708974
MIT License
52 stars 11 forks source link

Disable sorting only temporarily when refreshing #73

Closed zjosua closed 4 years ago

zjosua commented 4 years ago

This is how the Qt docs suggest to fix #66, as cited in the SO thread you already linked in the issue. Disable sorting before updating the table and enable it again afterwards.

Tested with Anki version 2.1.26 (961833a1).

ThoreBor commented 4 years ago

I also tried this, but I'm having two problems with this.

  1. When refreshing is disabled, sorting the leaderboard causes a highlight issue: sorting, refresh disabled

  2. Highlighting and auto scrolling are disabled when refreshing is enabled. If I remove if config["refresh"] == "False": in Line 28, there's another highlighting issue: sorting, refresh enabled1 sorting, refresh enabled2

I tested this with Anki 2.1.25 on windows.

zjosua commented 4 years ago

Scrolling works fine for me. I can see the highlighting issue as well though. However, when I delay the highlighting, it works fine. My guess is that the sortIndicatorChanged signal runs change_colors before sorting is completed.

zjosua commented 4 years ago

Just to be clear; I don't propose to add a delay. I commited this change to show that the highlighting issue is probably caused by the async execution of the sorting and the sortIndicatorChanged signal.

The best solution would be a signal that is emitted when sorting is completed, but I could not find one so far. Maybe there is way to make sure the change_colors methods are only called when no other thread is accessing the QTableWidget? Or we could disable sorting and use the QHeaderView.sectionClicked signal to kick off a custom sorting and highlighting function.

ThoreBor commented 4 years ago

You're right, this seems to be the problem. A custom sorting and highlighting function would probably be the best solution. I agree that sorting when refreshing is enabled would be nice, but I think that it's not super urgent. I don't have the time to solve this at the moment, but I'll keep it in mind.