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

Place the 'Recycle Bin' at the bottom of the list when groups are sorted. #7004

Conversation

pruthig
Copy link
Contributor

@pruthig pruthig commented Oct 1, 2021

The code changes are made to place 'Recycle bin' at the bottom when the list of groups is sorted. The sorting can be either in ascending order or in descending order. I have added this change in the logic wherein groups are sorted. As per the changes, 'Recycle bin' will be swapped with last index and sorting will be performed on the list excepting the last element (read 'Recycle bin')

Fixes #6495

Screenshots

Following snapshot shows 'Recycle bin' at bottom when list is sorted in ascending order:

image

Following snapshot shows 'Recycle bin' at bottom when list is sorted in descending order:

image

Testing strategy

I manually tested the changes on my Windows 10 machine.

Type of change

  • ✅ New feature (change that adds functionality)

@droidmonkey
Copy link
Member

Heck yah!

@droidmonkey droidmonkey added this to the v2.7.0 milestone Oct 1, 2021
@droidmonkey
Copy link
Member

Your implementation is not correct. The Recycle Bin is a defined group in the database (database()->metadata()->recycleBin()). You can just check for that group within the sort function and always return such that the group is sorted last.

@droidmonkey
Copy link
Member

droidmonkey commented Oct 1, 2021

This code works perfectly:

auto recycleBin = database()->metadata()->recycleBin();
std::sort(
    m_children.begin(), m_children.end(), [=](const Group* childGroup1, const Group* childGroup2) -> bool {
        if (childGroup1 == recycleBin) {
            return false;
        }
        QString name1 = childGroup1->name();
        QString name2 = childGroup2->name();
        return reverse ? name1.compare(name2, Qt::CaseInsensitive) > 0
                       : name1.compare(name2, Qt::CaseInsensitive) < 0;
    });

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2021

Codecov Report

Merging #7004 (17e13b0) into develop (2514c1d) will increase coverage by 0.01%.
The diff coverage is 90.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #7004      +/-   ##
===========================================
+ Coverage    63.68%   63.69%   +0.01%     
===========================================
  Files          330      330              
  Lines        41598    41601       +3     
===========================================
+ Hits         26489    26494       +5     
+ Misses       15109    15107       -2     
Impacted Files Coverage Δ
src/core/Group.cpp 94.42% <90.00%> (-0.11%) ⬇️
src/core/Entry.cpp 83.89% <0.00%> (+0.21%) ⬆️
src/core/FileWatcher.cpp 86.75% <0.00%> (+1.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2514c1d...17e13b0. Read the comment docs.

}

std::sort(beginIter, endIter, [reverse](const Group* childGroup1, const Group* childGroup2) -> bool {
Group* recycleBin = Q_NULLPTR;
Copy link
Member

Choose a reason for hiding this comment

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

We use nullptr.


std::sort(beginIter, endIter, [reverse](const Group* childGroup1, const Group* childGroup2) -> bool {
Group* recycleBin = Q_NULLPTR;
if(database()) {
Copy link
Member

Choose a reason for hiding this comment

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

missing space after if

@pruthig pruthig marked this pull request as ready for review October 1, 2021 17:09
@droidmonkey
Copy link
Member

Need to run make format

@droidmonkey droidmonkey merged commit 6c18b10 into keepassxreboot:develop Oct 2, 2021
@pruthig pruthig deleted the feature/groups-sort-recyclebin-at-end branch October 2, 2021 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort function should place recycling bin at the very bottom of the list
3 participants