Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement item categorization #44

Merged
merged 66 commits into from
Mar 18, 2023
Merged

Implement item categorization #44

merged 66 commits into from
Mar 18, 2023

Conversation

derselbst
Copy link
Owner

This PR adds support to categorize images into sections.

This took longer than expected because I restructured the entire asynchronous model fillup: Previously, there was one huge class SortedImageModel, which took care of initial filling of the model and watching the directory for any changes. This has been split up.

Now, there is an ImageSectionDataContainer which contains the sections and the individual images (or regular files). This container is threadsafe and accessed for reading by the UI thread and for writing by a backgroundThread. The container is populated by a DirectoryWorker, whenever the directory is changed. Additionally, it watches this directory for changes, adds or removes files, and triggers asynchronous decoding for any new files.
The container in turn is a friend of the SortedImageModel. When adding or removing items, the container calls the beginInsert- / beginRemoveRows functions of the model. In order for this to work without potential deadlocks or delays in event processing, the DirectoryWorker and the SortedImageModel are both living in the backgroundThread, so that we can use Qt::DirectConnection.

We cannot set the SortedImageModel directly for a QListView as both would be living in different threads. However, the QListView has set a QSortFilterProxyModel anyway, which are both living in the UI thread. And the latter then has set the SortedImageModel. Not sure if this is supposed to work, but so far it does.

While the model is filled up in the background, one may observe flickering in the QListView (i.e. any already drawn items disappear, appear again, and so on). Not sure how to fix that.

Special thanks to @pmfoss for demonstrating how to implement this kind of item categorization!

@derselbst derselbst added the enhancement New feature or request label Mar 5, 2023
@derselbst derselbst merged commit 348dad7 into master Mar 18, 2023
@derselbst derselbst deleted the categorization3 branch March 18, 2023 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant