mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-09 17:44:01 -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);
|
||||
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);
|
||||
mainLayout = new QVBoxLayout(container);
|
||||
mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
|
@ -417,6 +423,11 @@ QString TabArchidekt::buildSearchUrl()
|
|||
}
|
||||
|
||||
void TabArchidekt::doSearch()
|
||||
{
|
||||
searchDebounceTimer->start();
|
||||
}
|
||||
|
||||
void TabArchidekt::doSearchImmediate()
|
||||
{
|
||||
QString url = buildSearchUrl();
|
||||
QNetworkRequest req{QUrl(url)};
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ public:
|
|||
* Updates the current page display with results asynchronously.
|
||||
*/
|
||||
void doSearch();
|
||||
void doSearchImmediate();
|
||||
|
||||
/**
|
||||
* @brief Retrieve the tab display text
|
||||
|
|
@ -149,6 +150,8 @@ public slots:
|
|||
void getTopDecks();
|
||||
|
||||
private:
|
||||
QTimer* searchDebounceTimer; ///< Timer to debounce search requests by spin-boxes etc.
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Layout Containers
|
||||
// ---------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue