From 1b83c88eebe6521ba680b909976594ec9fc4117d Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 5 Oct 2022 07:00:08 +0200 Subject: [PATCH] Core: make options page keywords accessible Can be used to search for specific settings. Change-Id: I82579837d0595d01be04c3c7f3515854e6fabb87 Reviewed-by: Eike Ziller --- .../coreplugin/dialogs/ioptionspage.cpp | 47 ++++++++++++------- src/plugins/coreplugin/dialogs/ioptionspage.h | 2 + 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/plugins/coreplugin/dialogs/ioptionspage.cpp b/src/plugins/coreplugin/dialogs/ioptionspage.cpp index 7378b330148..e07c78747af 100644 --- a/src/plugins/coreplugin/dialogs/ioptionspage.cpp +++ b/src/plugins/coreplugin/dialogs/ioptionspage.cpp @@ -91,6 +91,34 @@ void IOptionsPage::setWidgetCreator(const WidgetCreator &widgetCreator) m_widgetCreator = widgetCreator; } +/*! + \fn QStringList Core::IOptionsPage::keywords() const + + Returns a list of ui strings that are used inside the widget. +*/ + +QStringList IOptionsPage::keywords() const +{ + if (!m_keywordsInitialized) { + auto that = const_cast(this); + QWidget *widget = that->widget(); + if (!widget) + return {}; + // find common subwidgets + for (const QLabel *label : widget->findChildren()) + m_keywords << Utils::stripAccelerator(label->text()); + for (const QCheckBox *checkbox : widget->findChildren()) + m_keywords << Utils::stripAccelerator(checkbox->text()); + for (const QPushButton *pushButton : widget->findChildren()) + m_keywords << Utils::stripAccelerator(pushButton->text()); + for (const QGroupBox *groupBox : widget->findChildren()) + m_keywords << Utils::stripAccelerator(groupBox->title()); + + m_keywordsInitialized = true; + } + return m_keywords; +} + /*! Returns the widget to show in the \uicontrol Options dialog. You should create a widget lazily here, and delete it again in the finish() method. This method can be called multiple times, so you @@ -242,24 +270,7 @@ const QList IOptionsPage::allOptionsPages() */ bool IOptionsPage::matches(const QRegularExpression ®exp) const { - if (!m_keywordsInitialized) { - auto that = const_cast(this); - QWidget *widget = that->widget(); - if (!widget) - return false; - // find common subwidgets - for (const QLabel *label : widget->findChildren()) - m_keywords << Utils::stripAccelerator(label->text()); - for (const QCheckBox *checkbox : widget->findChildren()) - m_keywords << Utils::stripAccelerator(checkbox->text()); - for (const QPushButton *pushButton : widget->findChildren()) - m_keywords << Utils::stripAccelerator(pushButton->text()); - for (const QGroupBox *groupBox : widget->findChildren()) - m_keywords << Utils::stripAccelerator(groupBox->title()); - - m_keywordsInitialized = true; - } - for (const QString &keyword : qAsConst(m_keywords)) + for (const QString &keyword : keywords()) if (keyword.contains(regexp)) return true; return false; diff --git a/src/plugins/coreplugin/dialogs/ioptionspage.h b/src/plugins/coreplugin/dialogs/ioptionspage.h index f34552b1051..a1c4a5fa32e 100644 --- a/src/plugins/coreplugin/dialogs/ioptionspage.h +++ b/src/plugins/coreplugin/dialogs/ioptionspage.h @@ -46,6 +46,8 @@ public: using WidgetCreator = std::function; void setWidgetCreator(const WidgetCreator &widgetCreator); + QStringList keywords() const; + virtual bool matches(const QRegularExpression ®exp) const; virtual QWidget *widget(); virtual void apply();