forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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));
|
||||
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();
|
||||
}
|
||||
|
||||
m_filesToUnregister.clear();
|
||||
|
||||
if (m_searchKeywords.isEmpty())
|
||||
m_searchKeywords = m_ui.groupBox->title();
|
||||
return widget;
|
||||
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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
if (!m_widget) {
|
||||
m_widget = new QWidget;
|
||||
m_ui.setupUi(m_widget);
|
||||
|
||||
updateFilterPage();
|
||||
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();
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
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));
|
||||
m_font = qvariant_cast<QFont>(HelpManager::customValue(QLatin1String("font"), m_font));
|
||||
|
||||
updateFontSize();
|
||||
updateFontStyle();
|
||||
updateFontFamily();
|
||||
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_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_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()));
|
||||
|
||||
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_returnOnClose = HelpManager::customValue(QLatin1String("ReturnOnClose"),
|
||||
false).toBool();
|
||||
m_ui->m_returnOnClose->setChecked(m_returnOnClose);
|
||||
}
|
||||
m_ui->homePageLineEdit->setText(m_homePage);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user