From 43488ba18ce09509495bccc2f1a93f68c4930fcb Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Wed, 5 Feb 2025 13:00:05 -0900 Subject: [PATCH 1/2] param: debounce search with timer to reduce UI lag --- src/QmlControls/ParameterEditorController.cc | 15 +++++++++++++-- src/QmlControls/ParameterEditorController.h | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 29ad95a1832e..4a403f9e53ab 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -19,17 +19,21 @@ QGC_LOGGING_CATEGORY(ParameterEditorControllerLog, "qgc.qmlcontrols.parameteredi ParameterEditorController::ParameterEditorController(QObject *parent) : FactPanelController(parent) , _parameterMgr(_vehicle->parameterManager()) + , _searchTimer(new QTimer(this)) { // qCDebug(ParameterEditorControllerLog) << Q_FUNC_INFO << this; _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(0) : nullptr; setCurrentCategory(category); @@ -370,6 +374,13 @@ bool ParameterEditorController::_shouldShow(Fact* fact) const } void ParameterEditorController::_searchTextChanged(void) +{ + if (!_searchTimer->isActive()) { + _searchTimer->start(); + } +} + +void ParameterEditorController::_performSearch(void) { QObjectList newParameterList; diff --git a/src/QmlControls/ParameterEditorController.h b/src/QmlControls/ParameterEditorController.h index 9895525b7478..9252a68c25b6 100644 --- a/src/QmlControls/ParameterEditorController.h +++ b/src/QmlControls/ParameterEditorController.h @@ -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; From c0d1866cce29bdcab8fac64f4578f442cebe243c Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Fri, 7 Feb 2025 11:13:08 -0900 Subject: [PATCH 2/2] qtimer change from pointer --- src/QmlControls/ParameterEditorController.cc | 11 +++++------ src/QmlControls/ParameterEditorController.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 4a403f9e53ab..9c618f99ed1e 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -19,20 +19,19 @@ QGC_LOGGING_CATEGORY(ParameterEditorControllerLog, "qgc.qmlcontrols.parameteredi ParameterEditorController::ParameterEditorController(QObject *parent) : FactPanelController(parent) , _parameterMgr(_vehicle->parameterManager()) - , _searchTimer(new QTimer(this)) { // qCDebug(ParameterEditorControllerLog) << Q_FUNC_INFO << this; _buildLists(); - _searchTimer->setSingleShot(true); - _searchTimer->setInterval(300); + _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(_searchTimer, &QTimer::timeout, this, &ParameterEditorController::_performSearch); + connect(&_searchTimer, &QTimer::timeout, this, &ParameterEditorController::_performSearch); connect(_parameterMgr, &ParameterManager::factAdded, this, &ParameterEditorController::_factAdded); ParameterEditorCategory* category = _categories.count() ? _categories.value(0) : nullptr; @@ -375,8 +374,8 @@ bool ParameterEditorController::_shouldShow(Fact* fact) const void ParameterEditorController::_searchTextChanged(void) { - if (!_searchTimer->isActive()) { - _searchTimer->start(); + if (!_searchTimer.isActive()) { + _searchTimer.start(); } } diff --git a/src/QmlControls/ParameterEditorController.h b/src/QmlControls/ParameterEditorController.h index 9252a68c25b6..86427de9f1c2 100644 --- a/src/QmlControls/ParameterEditorController.h +++ b/src/QmlControls/ParameterEditorController.h @@ -146,7 +146,7 @@ private slots: private: ParameterManager* _parameterMgr = nullptr; QString _searchText; - QTimer* _searchTimer; + QTimer _searchTimer; ParameterEditorCategory* _currentCategory = nullptr; ParameterEditorGroup* _currentGroup = nullptr; bool _showModifiedOnly = false;