Core: compress shortcut settings widget updates

reduces the number of calls to ShortcutSettingsWidget::initialize while
the shortcut settings widget is open and actions get registered. For
example when searching the preferences dialog the shortcut settings
widget is alive and some setting page widgets create a text editor,
which again registers some actions.

Change-Id: Ieb3c3d1c7ce317c3407a9c97514f6cc4a4ce76c4
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2024-06-04 11:37:21 +02:00
parent 6231213aa3
commit 99ce8b522f

View File

@@ -30,6 +30,7 @@
#include <QLineEdit> #include <QLineEdit>
#include <QPointer> #include <QPointer>
#include <QPushButton> #include <QPushButton>
#include <QTimer>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <array> #include <array>
@@ -420,6 +421,7 @@ private:
QGridLayout *m_shortcutLayout; QGridLayout *m_shortcutLayout;
std::vector<std::unique_ptr<ShortcutInput>> m_shortcutInputs; std::vector<std::unique_ptr<ShortcutInput>> m_shortcutInputs;
QPointer<QPushButton> m_addButton = nullptr; QPointer<QPushButton> m_addButton = nullptr;
QTimer m_updateTimer;
}; };
ShortcutSettingsWidget::ShortcutSettingsWidget() ShortcutSettingsWidget::ShortcutSettingsWidget()
@@ -428,7 +430,12 @@ ShortcutSettingsWidget::ShortcutSettingsWidget()
setTargetHeader(Tr::tr("Shortcut")); setTargetHeader(Tr::tr("Shortcut"));
setResetVisible(true); setResetVisible(true);
m_updateTimer.setSingleShot(true);
m_updateTimer.setInterval(100);
connect(ActionManager::instance(), &ActionManager::commandListChanged, connect(ActionManager::instance(), &ActionManager::commandListChanged,
&m_updateTimer, qOverload<>(&QTimer::start));
connect(&m_updateTimer, &QTimer::timeout,
this, &ShortcutSettingsWidget::initialize); this, &ShortcutSettingsWidget::initialize);
connect(this, &ShortcutSettingsWidget::currentCommandChanged, connect(this, &ShortcutSettingsWidget::currentCommandChanged,
this, &ShortcutSettingsWidget::handleCurrentCommandChanged); this, &ShortcutSettingsWidget::handleCurrentCommandChanged);