mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 04:43:56 -07:00
Debounce and limit searches.
This commit is contained in:
parent
d98bca8be8
commit
fb557d2b14
2 changed files with 14 additions and 0 deletions
|
|
@ -39,6 +39,12 @@ TabArchidekt::TabArchidekt(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor)
|
||||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||||
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processApiJson(QNetworkReply *)));
|
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(processApiJson(QNetworkReply *)));
|
||||||
|
|
||||||
|
searchDebounceTimer = new QTimer(this);
|
||||||
|
searchDebounceTimer->setSingleShot(true); // We only want it to fire once after inactivity
|
||||||
|
searchDebounceTimer->setInterval(300); // 300ms debounce
|
||||||
|
|
||||||
|
connect(searchDebounceTimer, &QTimer::timeout, this, [this]() { doSearchImmediate(); });
|
||||||
|
|
||||||
container = new QWidget(this);
|
container = new QWidget(this);
|
||||||
mainLayout = new QVBoxLayout(container);
|
mainLayout = new QVBoxLayout(container);
|
||||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
@ -417,6 +423,11 @@ QString TabArchidekt::buildSearchUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabArchidekt::doSearch()
|
void TabArchidekt::doSearch()
|
||||||
|
{
|
||||||
|
searchDebounceTimer->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabArchidekt::doSearchImmediate()
|
||||||
{
|
{
|
||||||
QString url = buildSearchUrl();
|
QString url = buildSearchUrl();
|
||||||
QNetworkRequest req{QUrl(url)};
|
QNetworkRequest req{QUrl(url)};
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ public:
|
||||||
* Updates the current page display with results asynchronously.
|
* Updates the current page display with results asynchronously.
|
||||||
*/
|
*/
|
||||||
void doSearch();
|
void doSearch();
|
||||||
|
void doSearchImmediate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve the tab display text
|
* @brief Retrieve the tab display text
|
||||||
|
|
@ -149,6 +150,8 @@ public slots:
|
||||||
void getTopDecks();
|
void getTopDecks();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QTimer* searchDebounceTimer; ///< Timer to debounce search requests by spin-boxes etc.
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Layout Containers
|
// Layout Containers
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue