-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
No longer trigger unneccessary searches om left and right cursor keys #11289
Conversation
On second thought: let's not make pressing Right trigger a search. |
Otoh that would delay triggering the search (debounce timer is restarted on each keystroke). |
|
This is the expected behavior! |
src/widget/wsearchlineedit.cpp
Outdated
QLineEdit* pEdit = lineEdit(); | ||
bool hadSelectedText = pEdit->hasSelectedText(); | ||
bool hadSelectedText = pEdit ? pEdit->hasSelectedText() : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These null checks do not help and only complicate the code. We expect that there is always a line QLineEdit. Just invoke lineEdit()
without using any mutable, local variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no guarantee that line edit is not null:
https://github.com/qt/qtbase/blob/e0a5915f88a780ba0791bce5ed042e92036a4900/src/widgets/widgets/qcombobox.cpp#L1697
Better safe than sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nup, I figured it's the other way around:
if it's editable then there's always a QLineEdit.
And since the editable state is not changed there will always be a lineEdit()
https://github.com/mixxxdj/mixxx/pull/11289/files#diff-85c225cd63139457cde84ddb0d2f69c854c16f8254672cd19587fd25dd755c62L94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you need to use VERIFY_OR_DEBUG_ASSERT Then please simplify the code, i.e. invoke lineEdit()
when needed and use the resulting pointer directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sake of completeness, if isEditable
is true then there is a QLineEdit, otherwise lineEdit() is a nullptr:
void QComboBox::setEditable(bool editable)
{
Q_D(QComboBox);
if (isEditable() == editable)
return;
QStyleOptionComboBox opt;
initStyleOption(&opt);
if (editable) {
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
d->viewContainer()->updateScrollers();
view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
}
QLineEdit *le = new QLineEdit(this);
le->setPalette(palette());
setLineEdit(le);
} else {
if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) {
d->viewContainer()->updateScrollers();
view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
setAttribute(Qt::WA_InputMethodEnabled, false);
d->lineEdit->hide();
d->lineEdit->deleteLater();
d->lineEdit = nullptr;
}
d->updateDelegate();
d->updateFocusPolicy();
d->viewContainer()->updateTopBottomMargin();
if (!testAttribute(Qt::WA_Resized))
adjustSize();
}
I did some usability test and it works now nice even with a looong delay of 10 s |
@@ -803,3 +809,11 @@ void WSearchLineEdit::slotSetFont(const QFont& font) { | |||
updateClearAndDropdownButton(getSearchText()); | |||
} | |||
} | |||
|
|||
bool WSearchLineEdit::hasSelectedText() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/widget/wsearchlineedit.cpp
Outdated
@@ -517,6 +525,12 @@ void WSearchLineEdit::slotRestoreSearch(const QString& text) { | |||
enableSearch(text); | |||
} | |||
|
|||
void WSearchLineEdit::triggerSearchDelayed() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
triggerSearchDebounced()
for consistent naming?
src/widget/wsearchlineedit.cpp
Outdated
case Qt::Key_Right: | ||
case Qt::Key_Right: { | ||
// Both keys may change or clear the selection (suggested completion). | ||
const bool hadSelectedText = hasSelectedText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hadSelectedTextBeforeKeyPressed
for disambiguation of the very similar identifiers.
src/widget/wsearchlineedit.cpp
Outdated
slotTriggerSearch(); | ||
// fetch lineEdit again, because we have no guarantee that pEdit | ||
// is still valid after QComboBox::keyPressEvent() | ||
if (hadSelectedTextBeforeKeyPressed && hasSelectedText()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Condition is wrong? Doesn't match the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please squash the commits.
Tbh, to me, this feels a bit complicated by now. I thought of the QCompleter signals initially, thought it was too complicated, but I gave it a shot and it turns out to be pretty simple, and solid so far. Please take a look at 1bdd6eb. I'll open a PR tomorrow. |
My original approach was like this, but I did not manage to make it work reliable. |
Co-authored-by: ronso0 <ronso0@mixxx.org>
… removed. This fixes a regression described in issue mixxxdj#11287
Rebase done. |
@ronso0: So we can merge this? |
return false; | ||
} | ||
return pEdit->hasSelectedText(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I already pointed out earlier, this is obsolete:
There is always a QLineEdit because we set the combobox editable in the constructor, and we rely on that in many places here. Please see
https://github.com/qt/qtbase/blob/4903e45231b00fb8a06f0b3c60af764f13e831bd/src/widgets/widgets/qcombobox.cpp#L1787-L1802
Just use lineEdit() directly.
Also applies here 7165f0b#diff-85c225cd63139457cde84ddb0d2f69c854c16f8254672cd19587fd25dd755c62R316
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other changes LGTM, thanks!
Done |
the pre-commit issue is caused by #11386 |
Thank you! |
This fixes #11287, a regression from
e25071d