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

FileBrowser.cpp : add naturalCompare function #7333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jinxuan2001
Copy link

add naturalCompare function :In the current FileBrowser::addItems , the ordering of directories and files is based on alphabetical order. Especially when dealing with directories, the code is sorted by name (fileName < d->text(0)). To implement natural sorting, we need to implement a custom comparison function. For example, you can add "file1", "file2",... ", "file10", rather than alphabetically placing "file10" before "file2". This is a realization idea, personal ideas only provide reference

	modified:   src/gui/FileBrowser.cpp
@Rossmaxx Rossmaxx linked an issue Jun 20, 2024 that may be closed by this pull request
@Rossmaxx
Copy link
Contributor

Take a look at #5772 too.

Thanks for the contribution ;-)

@DomClark
Copy link
Member

The sorting function looks good, but it only appears to be applied to root directories. Would you be able to apply it to all file browser entries?

@Rossmaxx
Copy link
Contributor

Another nitpick, @sakertooth sped up file browser searching recently. Hope this PR doesn't undo his speed benefit accidentally, in favour of aesthetics.

@Rossmaxx
Copy link
Contributor

I looked for another method. On quick googling, i found that QString has a compare function. Why not use that instead?

@Rossmaxx
Copy link
Contributor

Another method i found. https://stackoverflow.com/questions/11933883/sort-filenames-naturally-with-qt

@sakertooth
Copy link
Contributor

To achieve natural sorting, we can use QCollator instead. I think what is best is to make a global pure function for natural sorting, so that anyone that needs to do a natural sort can choose to do so.

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.

Browser - Sort Order
5 participants