Skip to content
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

param: debounce search with timer to reduce UI lag #12399

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/QmlControls/ParameterEditorController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ ParameterEditorController::ParameterEditorController(QObject *parent)

_buildLists();

_searchTimer.setSingleShot(true);
_searchTimer.setInterval(300);

connect(this, &ParameterEditorController::currentCategoryChanged, this, &ParameterEditorController::_currentCategoryChanged);
connect(this, &ParameterEditorController::currentGroupChanged, this, &ParameterEditorController::_currentGroupChanged);
connect(this, &ParameterEditorController::searchTextChanged, this, &ParameterEditorController::_searchTextChanged);
connect(this, &ParameterEditorController::showModifiedOnlyChanged, this, &ParameterEditorController::_searchTextChanged);

connect(_parameterMgr, &ParameterManager::factAdded, this, &ParameterEditorController::_factAdded);
connect(&_searchTimer, &QTimer::timeout, this, &ParameterEditorController::_performSearch);
connect(_parameterMgr, &ParameterManager::factAdded, this, &ParameterEditorController::_factAdded);

ParameterEditorCategory* category = _categories.count() ? _categories.value<ParameterEditorCategory*>(0) : nullptr;
setCurrentCategory(category);
Expand Down Expand Up @@ -370,6 +373,13 @@ bool ParameterEditorController::_shouldShow(Fact* fact) const
}

void ParameterEditorController::_searchTextChanged(void)
{
if (!_searchTimer.isActive()) {
_searchTimer.start();
}
}

void ParameterEditorController::_performSearch(void)
{
QObjectList newParameterList;

Expand Down
3 changes: 3 additions & 0 deletions src/QmlControls/ParameterEditorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ private slots:
private:
bool _shouldShow(Fact *fact) const;

void _performSearch();

private:
ParameterManager* _parameterMgr = nullptr;
QString _searchText;
QTimer _searchTimer;
ParameterEditorCategory* _currentCategory = nullptr;
ParameterEditorGroup* _currentGroup = nullptr;
bool _showModifiedOnly = false;
Expand Down
Loading