Add text debounce to QuickFilterView & ComboQuickFilterView (#3072)

This commit is contained in:
Tristan 2023-01-11 03:38:23 -06:00 committed by GitHub
parent a82d4402f8
commit 93acec9682
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 2 deletions

View File

@ -6,8 +6,14 @@ ComboQuickFilterView::ComboQuickFilterView(QWidget *parent)
{
ui->setupUi(this);
debounceTimer = new QTimer(this);
debounceTimer->setSingleShot(true);
connect(debounceTimer, &QTimer::timeout, this,
[this]() { emit filterTextChanged(ui->lineEdit->text()); });
connect(ui->lineEdit, &QLineEdit::textChanged, this,
[this](const QString &text) { emit filterTextChanged(text); });
[this](const QString &text) { debounceTimer->start(150); });
}
ComboQuickFilterView::~ComboQuickFilterView()

View File

@ -5,6 +5,7 @@
#include <QWidget>
#include <QComboBox>
#include <QTimer>
namespace Ui {
class ComboQuickFilterView;
@ -32,6 +33,7 @@ signals:
private:
Ui::ComboQuickFilterView *ui;
QTimer *debounceTimer;
};
#endif // COMBOQUICKFILTERVIEW_H

View File

@ -7,10 +7,16 @@ QuickFilterView::QuickFilterView(QWidget *parent, bool defaultOn)
{
ui->setupUi(this);
debounceTimer = new QTimer(this);
debounceTimer->setSingleShot(true);
connect(ui->closeFilterButton, &QAbstractButton::clicked, this, &QuickFilterView::closeFilter);
connect(debounceTimer, &QTimer::timeout, this,
[this]() { emit filterTextChanged(ui->filterLineEdit->text()); });
connect(ui->filterLineEdit, &QLineEdit::textChanged, this,
[this](const QString &text) { emit filterTextChanged(text); });
[this](const QString &text) { debounceTimer->start(150); });
if (!defaultOn) {
closeFilter();

View File

@ -7,6 +7,7 @@
#include <memory>
#include <QWidget>
#include <QTimer>
namespace Ui {
class QuickFilterView;
@ -31,6 +32,7 @@ signals:
private:
std::unique_ptr<Ui::QuickFilterView> ui;
QTimer *debounceTimer;
};
#endif // QUICKFILTERVIEW_H