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); 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, connect(ui->lineEdit, &QLineEdit::textChanged, this,
[this](const QString &text) { emit filterTextChanged(text); }); [this](const QString &text) { debounceTimer->start(150); });
} }
ComboQuickFilterView::~ComboQuickFilterView() ComboQuickFilterView::~ComboQuickFilterView()

View File

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

View File

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

View File

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