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();