diff options
author | Eike Ziller <eike.ziller@digia.com> | 2013-12-03 14:17:03 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@digia.com> | 2013-12-10 13:31:48 +0100 |
commit | deb43b4c8a261855252aeee09fd6df283576932e (patch) | |
tree | a844379f47974fd681b86aa2187735e03639b567 /src/plugins/help | |
parent | ea1a92484ac99057b06130a012164bf9788650e9 (diff) |
Preferences: Add default implementation for filtering
The default "matches" method now takes the widget and looks for all
child labels, checkboxes, push buttons and group boxes.
Because of that, the former "createWidget" method
can be called multiple times without creating a new widget
(-->widget()), and the "finished" method must ensure that the created
widget gets deleted, since not all widgets that were created are added
to the UI anymore.
Change-Id: Ia231c7c78dd8819146668e6447d36d22e7836904
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
Diffstat (limited to 'src/plugins/help')
-rw-r--r-- | src/plugins/help/docsettingspage.cpp | 35 | ||||
-rw-r--r-- | src/plugins/help/docsettingspage.h | 9 | ||||
-rw-r--r-- | src/plugins/help/filtersettingspage.cpp | 45 | ||||
-rw-r--r-- | src/plugins/help/filtersettingspage.h | 7 | ||||
-rw-r--r-- | src/plugins/help/generalsettingspage.cpp | 91 | ||||
-rw-r--r-- | src/plugins/help/generalsettingspage.h | 7 |
6 files changed, 90 insertions, 104 deletions
diff --git a/src/plugins/help/docsettingspage.cpp b/src/plugins/help/docsettingspage.cpp index 627aaab13fc..36fdda46b07 100644 --- a/src/plugins/help/docsettingspage.cpp +++ b/src/plugins/help/docsettingspage.cpp @@ -50,27 +50,26 @@ DocSettingsPage::DocSettingsPage() setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON)); } -QWidget *DocSettingsPage::createPage(QWidget *parent) +QWidget *DocSettingsPage::widget() { - QWidget *widget = new QWidget(parent); - m_ui.setupUi(widget); + if (!m_widget) { + m_widget = new QWidget; + m_ui.setupUi(m_widget); - connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addDocumentation())); - connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeDocumentation())); + connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addDocumentation())); + connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeDocumentation())); - m_ui.docsListWidget->installEventFilter(this); + m_ui.docsListWidget->installEventFilter(this); - const QStringList nameSpaces = HelpManager::registeredNamespaces(); - foreach (const QString &nameSpace, nameSpaces) { - addItem(nameSpace, HelpManager::fileFromNamespace(nameSpace)); - m_filesToRegister.insert(nameSpace, HelpManager::fileFromNamespace(nameSpace)); - } - - m_filesToUnregister.clear(); + const QStringList nameSpaces = HelpManager::registeredNamespaces(); + foreach (const QString &nameSpace, nameSpaces) { + addItem(nameSpace, HelpManager::fileFromNamespace(nameSpace)); + m_filesToRegister.insert(nameSpace, HelpManager::fileFromNamespace(nameSpace)); + } - if (m_searchKeywords.isEmpty()) - m_searchKeywords = m_ui.groupBox->title(); - return widget; + m_filesToUnregister.clear(); + } + return m_widget; } void DocSettingsPage::addDocumentation() @@ -155,9 +154,9 @@ void DocSettingsPage::apply() m_filesToUnregister.clear(); } -bool DocSettingsPage::matches(const QString &s) const +void DocSettingsPage::finish() { - return m_searchKeywords.contains(s, Qt::CaseInsensitive); + delete m_widget; } bool DocSettingsPage::eventFilter(QObject *object, QEvent *event) diff --git a/src/plugins/help/docsettingspage.h b/src/plugins/help/docsettingspage.h index 337db8f7b79..ed93f9ec7af 100644 --- a/src/plugins/help/docsettingspage.h +++ b/src/plugins/help/docsettingspage.h @@ -33,6 +33,8 @@ #include "ui_docsettingspage.h" #include <coreplugin/dialogs/ioptionspage.h> +#include <QPointer> + namespace Help { namespace Internal { @@ -43,10 +45,9 @@ class DocSettingsPage : public Core::IOptionsPage public: DocSettingsPage(); - QWidget *createPage(QWidget *parent); + QWidget *widget(); void apply(); - void finish() {} - bool matches(const QString &s) const; + void finish(); private slots: void addDocumentation(); @@ -59,8 +60,8 @@ private: private: Ui::DocSettingsPage m_ui; + QPointer<QWidget> m_widget; - QString m_searchKeywords; QString m_recentDialogPath; typedef QHash<QString, QString> NameSpaceToPathHash; diff --git a/src/plugins/help/filtersettingspage.cpp b/src/plugins/help/filtersettingspage.cpp index f97cdfa879a..351ddd54538 100644 --- a/src/plugins/help/filtersettingspage.cpp +++ b/src/plugins/help/filtersettingspage.cpp @@ -51,29 +51,26 @@ FilterSettingsPage::FilterSettingsPage() setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON)); } -QWidget *FilterSettingsPage::createPage(QWidget *parent) +QWidget *FilterSettingsPage::widget() { - QWidget *widget = new QWidget(parent); - m_ui.setupUi(widget); - - updateFilterPage(); - - connect(m_ui.attributeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), - this, SLOT(updateFilterMap())); - connect(m_ui.filterWidget, - SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, - SLOT(updateAttributes(QListWidgetItem*))); - connect(m_ui.filterAddButton, SIGNAL(clicked()), this, SLOT(addFilter())); - connect(m_ui.filterRemoveButton, SIGNAL(clicked()), this, - SLOT(removeFilter())); - connect(HelpManager::instance(), SIGNAL(documentationChanged()), - this, SLOT(updateFilterPage())); - - if (m_searchKeywords.isEmpty()) { - m_searchKeywords = m_ui.filterGroupBox->title() + QLatin1Char(' ') - + m_ui.attributesGroupBox->title(); + if (!m_widget) { + m_widget = new QWidget; + m_ui.setupUi(m_widget); + + updateFilterPage(); + + connect(m_ui.attributeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,int)), + this, SLOT(updateFilterMap())); + connect(m_ui.filterWidget, + SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, + SLOT(updateAttributes(QListWidgetItem*))); + connect(m_ui.filterAddButton, SIGNAL(clicked()), this, SLOT(addFilter())); + connect(m_ui.filterRemoveButton, SIGNAL(clicked()), this, + SLOT(removeFilter())); + connect(HelpManager::instance(), SIGNAL(documentationChanged()), + this, SLOT(updateFilterPage())); } - return widget; + return m_widget; } void FilterSettingsPage::updateFilterPage() @@ -230,11 +227,7 @@ void FilterSettingsPage::finish() { disconnect(HelpManager::instance(), SIGNAL(documentationChanged()), this, SLOT(updateFilterPage())); -} - -bool FilterSettingsPage::matches(const QString &s) const -{ - return m_searchKeywords.contains(s, Qt::CaseInsensitive); + delete m_widget; } QString FilterSettingsPage::msgFilterLabel(const QString &filter) const diff --git a/src/plugins/help/filtersettingspage.h b/src/plugins/help/filtersettingspage.h index 3d20d19521d..33634b0d257 100644 --- a/src/plugins/help/filtersettingspage.h +++ b/src/plugins/help/filtersettingspage.h @@ -33,6 +33,8 @@ #include "ui_filtersettingspage.h" #include <coreplugin/dialogs/ioptionspage.h> +#include <QPointer> + namespace Help { namespace Internal { @@ -43,10 +45,9 @@ class FilterSettingsPage : public Core::IOptionsPage public: FilterSettingsPage(); - QWidget *createPage(QWidget *parent); + QWidget *widget(); void apply(); void finish(); - bool matches(const QString &s) const; signals: void filtersChanged(); @@ -64,12 +65,12 @@ private: private: QString msgFilterLabel(const QString &filter) const; Ui::FilterSettingsPage m_ui; + QPointer<QWidget> m_widget; typedef QMap<QString, QStringList> FilterMap; FilterMap m_filterMap; FilterMap m_filterMapBackup; - QString m_searchKeywords; QStringList m_removedFilters; }; diff --git a/src/plugins/help/generalsettingspage.cpp b/src/plugins/help/generalsettingspage.cpp index 43ac9b1aed9..53848cff7c2 100644 --- a/src/plugins/help/generalsettingspage.cpp +++ b/src/plugins/help/generalsettingspage.cpp @@ -72,59 +72,54 @@ GeneralSettingsPage::GeneralSettingsPage() setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON)); } -QWidget *GeneralSettingsPage::createPage(QWidget *parent) +QWidget *GeneralSettingsPage::widget() { - QWidget *widget = new QWidget(parent); - m_ui = new Ui::GeneralSettingsPage; - m_ui->setupUi(widget); - m_ui->sizeComboBox->setEditable(false); - m_ui->styleComboBox->setEditable(false); - - m_font = qvariant_cast<QFont>(HelpManager::customValue(QLatin1String("font"), m_font)); - - updateFontSize(); - updateFontStyle(); - updateFontFamily(); - - m_homePage = HelpManager::customValue(QLatin1String("HomePage"), QString()) - .toString(); - if (m_homePage.isEmpty()) { - m_homePage = HelpManager::customValue(QLatin1String("DefaultHomePage"), - Help::Constants::AboutBlank).toString(); - } - m_ui->homePageLineEdit->setText(m_homePage); + if (!m_widget) { + m_widget = new QWidget; + m_ui = new Ui::GeneralSettingsPage; + m_ui->setupUi(m_widget); + m_ui->sizeComboBox->setEditable(false); + m_ui->styleComboBox->setEditable(false); + + m_font = qvariant_cast<QFont>(HelpManager::customValue(QLatin1String("font"), m_font)); + + updateFontSize(); + updateFontStyle(); + updateFontFamily(); + + m_homePage = HelpManager::customValue(QLatin1String("HomePage"), QString()) + .toString(); + if (m_homePage.isEmpty()) { + m_homePage = HelpManager::customValue(QLatin1String("DefaultHomePage"), + Help::Constants::AboutBlank).toString(); + } + m_ui->homePageLineEdit->setText(m_homePage); - m_startOption = HelpManager::customValue(QLatin1String("StartOption"), - Help::Constants::ShowLastPages).toInt(); - m_ui->helpStartComboBox->setCurrentIndex(m_startOption); + m_startOption = HelpManager::customValue(QLatin1String("StartOption"), + Help::Constants::ShowLastPages).toInt(); + m_ui->helpStartComboBox->setCurrentIndex(m_startOption); - m_contextOption = HelpManager::customValue(QLatin1String("ContextHelpOption"), - Help::Constants::SideBySideIfPossible).toInt(); - m_ui->contextHelpComboBox->setCurrentIndex(m_contextOption); + m_contextOption = HelpManager::customValue(QLatin1String("ContextHelpOption"), + Help::Constants::SideBySideIfPossible).toInt(); + m_ui->contextHelpComboBox->setCurrentIndex(m_contextOption); - connect(m_ui->currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage())); - connect(m_ui->blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage())); - connect(m_ui->defaultPageButton, SIGNAL(clicked()), this, SLOT(setDefaultPage())); + connect(m_ui->currentPageButton, SIGNAL(clicked()), this, SLOT(setCurrentPage())); + connect(m_ui->blankPageButton, SIGNAL(clicked()), this, SLOT(setBlankPage())); + connect(m_ui->defaultPageButton, SIGNAL(clicked()), this, SLOT(setDefaultPage())); - HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer(); - if (!viewer) - m_ui->currentPageButton->setEnabled(false); + HelpViewer *viewer = CentralWidget::instance()->currentHelpViewer(); + if (!viewer) + m_ui->currentPageButton->setEnabled(false); - m_ui->errorLabel->setVisible(false); - connect(m_ui->importButton, SIGNAL(clicked()), this, SLOT(importBookmarks())); - connect(m_ui->exportButton, SIGNAL(clicked()), this, SLOT(exportBookmarks())); + m_ui->errorLabel->setVisible(false); + connect(m_ui->importButton, SIGNAL(clicked()), this, SLOT(importBookmarks())); + connect(m_ui->exportButton, SIGNAL(clicked()), this, SLOT(exportBookmarks())); - if (m_searchKeywords.isEmpty()) { - QTextStream(&m_searchKeywords) << ' ' << m_ui->contextHelpLabel->text() - << ' ' << m_ui->startPageLabel->text() << ' ' << m_ui->homePageLabel->text(); - m_searchKeywords.remove(QLatin1Char('&')); + m_returnOnClose = HelpManager::customValue(QLatin1String("ReturnOnClose"), + false).toBool(); + m_ui->m_returnOnClose->setChecked(m_returnOnClose); } - - m_returnOnClose = HelpManager::customValue(QLatin1String("ReturnOnClose"), - false).toBool(); - m_ui->m_returnOnClose->setChecked(m_returnOnClose); - - return widget; + return m_widget; } void GeneralSettingsPage::apply() @@ -342,13 +337,9 @@ int GeneralSettingsPage::closestPointSizeIndex(int desiredPointSize) const return closestIndex; } -bool GeneralSettingsPage::matches(const QString &s) const -{ - return m_searchKeywords.contains(s, Qt::CaseInsensitive); -} - void GeneralSettingsPage::finish() { + delete m_widget; if (!m_ui) // page was never shown return; delete m_ui; diff --git a/src/plugins/help/generalsettingspage.h b/src/plugins/help/generalsettingspage.h index 70fb588b96d..06fdd45b9f5 100644 --- a/src/plugins/help/generalsettingspage.h +++ b/src/plugins/help/generalsettingspage.h @@ -33,6 +33,8 @@ #include "ui_generalsettingspage.h" #include <coreplugin/dialogs/ioptionspage.h> +#include <QPointer> + namespace Help { namespace Internal { @@ -45,10 +47,9 @@ class GeneralSettingsPage : public Core::IOptionsPage public: GeneralSettingsPage(); - QWidget *createPage(QWidget *parent); + QWidget *widget(); void apply(); void finish(); - bool matches(const QString &s) const; signals: void fontChanged(); @@ -79,7 +80,7 @@ private: int m_startOption; bool m_returnOnClose; - QString m_searchKeywords; + QPointer<QWidget> m_widget; Ui::GeneralSettingsPage *m_ui; }; |