feat(tree): implement sortData and sortKey#560
Open
slook wants to merge 2 commits intoceccopierangiolieugenio:mainfrom
Open
feat(tree): implement sortData and sortKey#560slook wants to merge 2 commits intoceccopierangiolieugenio:mainfrom
slook wants to merge 2 commits intoceccopierangiolieugenio:mainfrom
Conversation
Contributor
Author
|
Pushed a change only to clarify the docstrings but did not make any changes to the code. If not deemed suitable for merging then it is open for suggestions or other ideas to be taken from it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TTkTreeWidget() and TTkTreeWidgetItem():
sortKey()andsortData()to provide custom values to thekeyargument of the internalsort()function.keykeyword argument forsortChildren().Nonefall-back to the simple character-based sorting.TTkFileTreeWidget() and TTkFileTreeWidgetItem():
_rawdata values which were stored but hadn't been implemented yet.sortData()inFileTreeWidgetItemnow returnsListinstead ofstrtype.FileTreeWidgetItemitems after populating the widget instead of sorting every row after each insertion which was causing a very large performance impact while listing large folders after enabling a sort column.Folders are always grouped at the top (regardless of the direction of the sort order), including inside expanded children:

Sorting by "Size" uses the
_rawvalues in theFileTreeWidgetItemto give natural sorting order ^^The file and folder items are now always grouped at the top and the proper numeric values cause the items to be displayed in a much more logical manor that makes navigating a filesystem work more like one would reasonably expect. It is a good example of the reason why such an implementation is desirable. The documentation strings explain how to implement it for any purpose.
The default behaviour of
TTkTreeis unchanged, you have to override thesortKey()orsortData()in a sub-class to get some other values to use as thekeyto do custom sorting strategies. The advantage of allowingAnytype of value (or tuple of values) to be returned bysortKey()is that any complexity of multi-factor ordering can be sorted() in a single pass.Note: AI (Cognition) wrote the regex used for alphanumeric splitting and a human (me) implemented the sorting with reference to the Python docs sorted() and https://docs.python.org/3/howto/sorting.html#sortinghowto