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

Keep sub-sorting order #15074

Merged
merged 1 commit into from
Jun 14, 2021
Merged

Conversation

d-s-x
Copy link
Contributor

@d-s-x d-s-x commented Jun 7, 2021

Fixes #15073

Sub-sorting now works like in most grids where sub-sorting is a thing (except there is still no indication in UI).
Sub-sorting column tracked from sort() method that is called exactly once per view sort unlike lessThan() so it is a bit cleaner now too.

This complements earlier work done in #14423

src/gui/transferlistsortmodel.h Outdated Show resolved Hide resolved
@FranciscoPombal FranciscoPombal added the GUI GUI-related issues/changes label Jun 7, 2021
src/gui/transferlistsortmodel.cpp Outdated Show resolved Hide resolved
src/gui/transferlistsortmodel.cpp Outdated Show resolved Hide resolved
src/gui/transferlistsortmodel.cpp Outdated Show resolved Hide resolved
return compare(left.sibling(left.row(), m_subSortColumn), right.sibling(right.row(), m_subSortColumn)) < 0;
if (result == 0) {
const int subResult = compare(left.sibling(left.row(), m_subSortColumn), right.sibling(right.row(), m_subSortColumn));
return m_subSortColumnOrder == m_lastSortColumnOrder ? subResult < 0 : subResult > 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you compare m_subSortColumnOrder with m_lastSortColumnOrder? It's not clear. At least you should add a code comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... Actually this is wrong. Looks like I've outsmarted myself. Fixed, comment added

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glassez
Well, I was wrong last time but right first time. Qt reverses lessThan() as a whole so sorting descending means that sub-
sorting has to be reversed. And if sub-sorting is descending the sub-result must be inversed too. That means if both ordered descending the sub-result is double-inversed (which is the same as no inversion). Obviously, if both ordered Ascending this also means that no inversion should happen. And to check that exactly one is descending is the same as checking that both are not equal.
Fixed, comment added.

src/gui/transferlistsortmodel.h Outdated Show resolved Hide resolved
mutable int m_lastSortColumn = -1;
mutable int m_lastSortColumnOrder = 0;
Copy link
Member

@Chocobo1 Chocobo1 Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks wasteful to use 4 bytes to store very few items. I would suggest using signed char (to differentiate with the char type which is usually for characters).
This applies to CachedSettingValue<> too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's too much... This is not a memory-critical place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use single int8_t to encode both column index and sort order at the same time so every user will waste 7 bytes less at the expense of some runtime overhead and inability to express more than 126 columns. Sort order will be encoded using sign bit and index itself will be stored with +1 offset, 0 will mean "unset" which also allows to save on code size by replacing if (m_lastSortColumn != -1) with much shorter if (m_lastSortColumn). If we agree to never have more than 62 columns we may even spare 1 bit for future use.

Copy link
Member

@Chocobo1 Chocobo1 Jun 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's too much...

It is only a smaller type isn't? Or we can use the alias qint8.
This is not a thing that I very insist so I still gave my approval.

I can use single int8_t to encode both column index and sort order at the same time so every user will waste 7 bytes less at the expense of some runtime overhead and inability to express more than 126 columns.

That is a way to encode it but it is overly complex for our simple usage here. For now let's stick to simple code.

src/gui/transferlistsortmodel.cpp Outdated Show resolved Hide resolved
src/gui/transferlistsortmodel.cpp Outdated Show resolved Hide resolved
src/gui/transferlistsortmodel.cpp Show resolved Hide resolved
@Chocobo1 Chocobo1 added this to the 4.4.0 milestone Jun 11, 2021
Chocobo1
Chocobo1 previously approved these changes Jun 11, 2021
glassez
glassez previously approved these changes Jun 11, 2021
glassez
glassez previously approved these changes Jun 11, 2021
@Chocobo1
Copy link
Member

@qbittorrent/frequent-contributors
Please test this PR and (only) give approvals after it works as intended.

mutable int m_lastSortColumn = -1;
mutable int m_lastSortOrder = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransferListSortModel::sort is not const, it should work without marking these variables mutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed (×4)

thalieht
thalieht previously approved these changes Jun 12, 2021
Copy link
Contributor

@thalieht thalieht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested

@d-s-x d-s-x dismissed stale reviews from thalieht and glassez via de1e64b June 12, 2021 17:48
@Chocobo1 Chocobo1 merged commit 2bd5aca into qbittorrent:master Jun 14, 2021
@Chocobo1
Copy link
Member

@d-s-x
Thank you!

glassez pushed a commit to glassez/qBittorrent that referenced this pull request Jun 14, 2021
@d-s-x d-s-x deleted the keep-subsort-order branch June 14, 2021 11:07
glassez pushed a commit that referenced this pull request Jun 15, 2021
IceCodeNew pushed a commit to IceCodeNew/qBittorrent-Enhanced-Edition that referenced this pull request Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep sub-sorting order (acsending/descending)
6 participants