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

Search: save queries across restarts, related tweaks & fixes #4458

Merged
merged 8 commits into from
Oct 29, 2021

Conversation

ronso0
Copy link
Member

@ronso0 ronso0 commented Oct 18, 2021

Store queries to mixxx.cfg when WSearchLineEdit is destroyed (shutdown or skin change), load when it's created.
(only for the library searchbar, not the control searchbar in the developer tools dialog)
Currently only the selected query is stored on skin change, others are lost.

Delete and Backspace in the popup delete the selected item
This allows cleaning up the history, which I consider a rare maintenance job thus I did not add a delete shortcut for the combobox view.
I also added a control [Library], delete_search_query to delete the current item from the popup or the combobox view.

tweaks & fixes:

  • The search queries popup holds indices 0..n, while the combobox also has index -1 (empty, "Search...").
    When index -1 is selected in the combobox and the list view is opened index 0 is auto-set but not highlighted.
    Select first index manually (only in the list).
  • Avoid storing duplicate items when switching between library features.
  • Some searchbar COs could be triggered (accidentally) while the searchbar is disabled (AutoDJ, Rec, ...). Debug asserts were used which I replaced with regular tests in order to avoid unexpected behaviour in releases.

https://bugs.launchpad.net/mixxx/+bug/1943084
https://bugs.launchpad.net/mixxx/+bug/1947479

@github-actions github-actions bot added the ui label Oct 18, 2021
@ronso0 ronso0 added library and removed ui labels Oct 18, 2021
@github-actions github-actions bot added the ui label Oct 18, 2021
@ronso0 ronso0 changed the title Search: Backspace deletes saved query Search: save queries across restarts, related tweaks & fixes Oct 18, 2021
@Be-ing
Copy link
Contributor

Be-ing commented Oct 18, 2021

+102 −6
a small cost for a very useful feature

@ronso0
Copy link
Member Author

ronso0 commented Oct 18, 2021

Yes, I was surprised how easy it is to save and load the queries. So easy that I'm afraid I overlooked a fundamental mistake...
But it works beautifully.

@poelzi
Copy link
Contributor

poelzi commented Oct 18, 2021

Thank you for fixing the bug of disappearing queries, I was wondering where that came frome.
Lolz, I was thinking about saving the search queries, already thought about database models and API of the subsystem, you instead went the shortest of all path, well done. I rather like a simple system now then a perfectly designed subsystem in 3 years.
I would limit the number of entries saved in the config file to maybe 50 ? 500 ? over 9000 ?

@Be-ing
Copy link
Contributor

Be-ing commented Oct 19, 2021

I think this quick hack of using mixxx.cfg is adequate. AFAIK there isn't a technical reason this couldn't work as well as storing this data in the SQLite database, but this seems much simpler. When we replace the library with Aoide we'll probably have a completely different system for storing queries persistently. Considering how useful this feature is and the low complexity of the code being added here, I agree that it is worth it to have this now even if the user data may be incompatible with the future system.

@@ -146,9 +149,15 @@ WSearchLineEdit::WSearchLineEdit(QWidget* pParent)
clearButtonSize.width() + m_frameWidth + kClearButtonClearence,
layoutDirection()));

loadQueriesFromConfig();
Copy link
Contributor

Choose a reason for hiding this comment

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

This will cause strange behaviour if there is more then 1 searchbar, but I don't know if this is even supported.
If there is a shared store for the queries there must be some sort of sync between the boxes and the config file, at least the object updated.

Copy link
Member Author

@ronso0 ronso0 Oct 19, 2021

Choose a reason for hiding this comment

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

when a searchbar widget is created from the skin parser it's bound to the library widget.
So, if there is more than one searchbar only the last one is bound. didn't try that though. Edit both are bound and could work, but the queries are not sync'ed. Nothing to worry about since that is not a supported use case.

There's another WSearchLineEdit in the dev tools, but it's created without passing the settings pointer, thus no queries are stored for that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering we will not be doing a major redesign of the QWidgets library to add a second WSearchLineEdit, I am willing to accept something kinda hacky.

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

Limiting the storage sounds reasonable. That could happen in WSearchLineEdit itself by setting maxCount().

for (int index = 0; index < count(); index++) {
m_pConfig->setValue(
ConfigKey(kSavedQueriesConfigGroup, QString::number(index)),
this->itemText(index));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this->itemText(index));
itemText(index));

@@ -297,6 +331,11 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) {
slotSaveSearch();
}
}
} else {
if (keyEvent->key() == Qt::Key_Backspace) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment, how this works, it is not obvious when reading the code.
Doesn't it interfere with the backspace when editing the querry?

Copy link
Member

Choose a reason for hiding this comment

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

Ah got it.
The issue is that we have the check if the popup is visible twice.
Maybe two functions for each case makes it obvious.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

The is just a readability issue.
The rest looks good.
Thank you.

@@ -439,6 +481,30 @@ void WSearchLineEdit::slotMoveSelectedHistory(int steps) {
m_saveTimer.stop();
}

void WSearchLineEdit::slotDeleteCurrentItem() {
Copy link
Member

Choose a reason for hiding this comment

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

The name is misleading, because it deletes the current item or the highlighted item.
Since we gave the Chech in the calling code in the backspace case anyway I think the best solution is to make two functions and move the check into the valueChanged callback.
Alternative would be a better function name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I turned this into deleteSelectedListItem() and deleteSelectedComboboxItem(), and slotDeleteCurrentItem() which is connected to the CO which would pick one of the two depending on isVisible()

@@ -297,6 +331,11 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) {
slotSaveSearch();
}
}
} else {
if (keyEvent->key() == Qt::Key_Backspace) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah got it.
The issue is that we have the check if the popup is visible twice.
Maybe two functions for each case makes it obvious.

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

Limiting the storage sounds reasonable. That could happen in WSearchLineEdit itself by setting maxCount().

What about 50?
I think that would allow the popup to be roughly as tall as the screen height.

@ronso0 ronso0 force-pushed the search-delete-saved-queries branch from e1297fe to 966c0c0 Compare October 19, 2021 16:05
@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

@daschuer I implemented your suggestions. Please take a look.

btw I just discovered a bug (also in main):

  • select a search query
  • switch to another feature
  • select the previous query
  • switch back to the previous feature
  • the query is now twice in the list

I'll check if setDuplicatesEnabled(false) fixes this or if we need a duplicate filter in slotSaveSearch()

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

Limiting the storage sounds reasonable. That could happen in WSearchLineEdit itself by setting maxCount().

What about 50? I think that would allow the popup to be roughly as tall as the screen height.

ahemm, kMaxSearchEntries = 50; is already in place 😁

@daschuer
Copy link
Member

Thank you.

I have just tested this and can confirm the issue:

  • Delete an entry form the pop up
  • Restart Mixxx
  • The last entry is listed twice.

Another thing is that I was tempted to use the del key instead of backspace more than once during the test. Can we add it as well?

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

Another thing is that I was tempted to use the del key instead of backspace more than once during the test. Can we add it as well?

Sure we could do that.
But considering Del is CMD + Backspace on macs that would add extra complexity (see #4330) I'm unsure how to proceed.

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

I fixed the duplicate bug, but I'll also need to fix the writing to the config to avoid duplicates there, probably wipe all entries before saving.

@ronso0 ronso0 force-pushed the search-delete-saved-queries branch 2 times, most recently from f47176a to e9055d9 Compare October 19, 2021 20:20
@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

I fixed the duplicate bug, but I'll also need to fix the writing to the config to avoid duplicates there, probably wipe all entries before saving.

Done.

@ronso0
Copy link
Member Author

ronso0 commented Oct 19, 2021

Further optimization would be to set QKey constants and use them for the tooltip and the key event filter.
Won't happen here though.

@ronso0 ronso0 force-pushed the search-delete-saved-queries branch from 45c0a1d to d13e847 Compare October 20, 2021 01:38
@daschuer
Copy link
Member

daschuer commented Oct 20, 2021

But considering Del is CMD + Backspace on macs that would add extra complexity (see #4330) I'm unsure how to proceed.

I think it is sufficient to just add the del key.
It is probably unlikely that a Mac user uses CND + Backspace if Backspace allone works as well.

I have just checked how Firefox and Chrome works. Backspace starts immediately to edit the highlighted entry. It can be deleted by Shift+del and Shift +CMD+ Backspace..

Not sure if this patter is relevant for us.

@ronso0 ronso0 force-pushed the search-delete-saved-queries branch from d13e847 to c78d9a4 Compare October 20, 2021 23:30
@ronso0 ronso0 force-pushed the search-delete-saved-queries branch from c78d9a4 to a93b621 Compare October 20, 2021 23:38
@ronso0
Copy link
Member Author

ronso0 commented Oct 20, 2021

suggestions addded & squashed.
Ready!

@daschuer
Copy link
Member

daschuer commented Oct 21, 2021

Thank you, I will do a final check.

In general, you should not rebase a PR under review. This creates untested commits and makes it hard for the reviewer to review the changes compared to the last review. See: https://github.com/mixxxdj/mixxx/blob/main/CONTRIBUTING.md#all-contributors

@ronso0
Copy link
Member Author

ronso0 commented Oct 21, 2021

Sorry, won't happen again. I'd like to avoid formatting one-line commits, and since I merged main I couldn't ammend anymore.

@daschuer
Copy link
Member

Ok, no big deal in this case. Just ask before.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

This works like a charm. Thank you.

@daschuer daschuer merged commit 66be9a8 into mixxxdj:main Oct 29, 2021
@ronso0 ronso0 deleted the search-delete-saved-queries branch October 29, 2021 12:01
@ronso0 ronso0 added the changelog This PR should be included in the changelog label Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog This PR should be included in the changelog library ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants