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:
Eike Ziller
2013-12-03 14:17:03 +01:00
parent ea1a92484a
commit deb43b4c8a
118 changed files with 1093 additions and 1731 deletions

View File

@@ -56,67 +56,54 @@ CompletionSettingsPage::~CompletionSettingsPage()
delete m_page;
}
QWidget *CompletionSettingsPage::createPage(QWidget *parent)
QWidget *CompletionSettingsPage::widget()
{
QWidget *w = new QWidget(parent);
m_page = new Ui::CompletionSettingsPage;
m_page->setupUi(w);
if (!m_widget) {
QWidget *m_widget = new QWidget;
m_page = new Ui::CompletionSettingsPage;
m_page->setupUi(m_widget);
const TextEditor::CompletionSettings &settings =
TextEditor::TextEditorSettings::completionSettings();
const TextEditor::CompletionSettings &settings =
TextEditor::TextEditorSettings::completionSettings();
int caseSensitivityIndex = 0;
switch (settings.m_caseSensitivity) {
case TextEditor::CaseSensitive:
caseSensitivityIndex = 0;
break;
case TextEditor::CaseInsensitive:
caseSensitivityIndex = 1;
break;
case TextEditor::FirstLetterCaseSensitive:
caseSensitivityIndex = 2;
break;
int caseSensitivityIndex = 0;
switch (settings.m_caseSensitivity) {
case TextEditor::CaseSensitive:
caseSensitivityIndex = 0;
break;
case TextEditor::CaseInsensitive:
caseSensitivityIndex = 1;
break;
case TextEditor::FirstLetterCaseSensitive:
caseSensitivityIndex = 2;
break;
}
int completionTriggerIndex = 0;
switch (settings.m_completionTrigger) {
case TextEditor::ManualCompletion:
completionTriggerIndex = 0;
break;
case TextEditor::TriggeredCompletion:
completionTriggerIndex = 1;
break;
case TextEditor::AutomaticCompletion:
completionTriggerIndex = 2;
break;
}
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
m_page->surroundSelectedText->setChecked(settings.m_surroundingAutoBrackets);
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
m_page->enableDoxygenCheckBox->setChecked(m_commentsSettings.m_enableDoxygen);
m_page->generateBriefCheckBox->setChecked(m_commentsSettings.m_generateBrief);
m_page->leadingAsterisksCheckBox->setChecked(m_commentsSettings.m_leadingAsterisks);
m_page->generateBriefCheckBox->setEnabled(m_page->enableDoxygenCheckBox->isChecked());
}
int completionTriggerIndex = 0;
switch (settings.m_completionTrigger) {
case TextEditor::ManualCompletion:
completionTriggerIndex = 0;
break;
case TextEditor::TriggeredCompletion:
completionTriggerIndex = 1;
break;
case TextEditor::AutomaticCompletion:
completionTriggerIndex = 2;
break;
}
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets);
m_page->surroundSelectedText->setChecked(settings.m_surroundingAutoBrackets);
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete);
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName);
m_page->enableDoxygenCheckBox->setChecked(m_commentsSettings.m_enableDoxygen);
m_page->generateBriefCheckBox->setChecked(m_commentsSettings.m_generateBrief);
m_page->leadingAsterisksCheckBox->setChecked(m_commentsSettings.m_leadingAsterisks);
if (m_searchKeywords.isEmpty()) {
QTextStream(&m_searchKeywords) << m_page->caseSensitivityLabel->text()
<< ' ' << m_page->autoInsertBrackets->text()
<< ' ' << m_page->surroundSelectedText->text()
<< ' ' << m_page->completionTriggerLabel->text()
<< ' ' << m_page->partiallyComplete->text()
<< ' ' << m_page->spaceAfterFunctionName->text()
<< ' ' << m_page->enableDoxygenCheckBox->text()
<< ' ' << m_page->generateBriefCheckBox->text()
<< ' ' << m_page->leadingAsterisksCheckBox->text();
m_searchKeywords.remove(QLatin1Char('&'));
}
m_page->generateBriefCheckBox->setEnabled(m_page->enableDoxygenCheckBox->isChecked());
return w;
return m_widget;
}
void CompletionSettingsPage::apply()
@@ -144,11 +131,6 @@ void CompletionSettingsPage::apply()
emit commentsSettingsChanged(m_commentsSettings);
}
bool CompletionSettingsPage::matches(const QString &s) const
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}
TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
{
switch (m_page->caseSensitivity->currentIndex()) {
@@ -175,6 +157,7 @@ TextEditor::CompletionTrigger CompletionSettingsPage::completionTrigger() const
void CompletionSettingsPage::finish()
{
delete m_widget;
if (!m_page) // page was never shown
return;
delete m_page;

View File

@@ -35,6 +35,8 @@
#include <texteditor/completionsettings.h>
#include <texteditor/texteditoroptionspage.h>
#include <QPointer>
namespace CppTools {
namespace Internal {
@@ -52,10 +54,9 @@ public:
CompletionSettingsPage(QObject *parent);
~CompletionSettingsPage();
QWidget *createPage(QWidget *parent);
QWidget *widget();
void apply();
void finish();
bool matches(const QString &) const;
const CommentsSettings &commentsSettings() const;
@@ -69,7 +70,7 @@ private:
bool requireCommentsSettingsUpdate() const;
Ui::CompletionSettingsPage *m_page;
QString m_searchKeywords;
QPointer<QWidget> m_widget;
CommentsSettings m_commentsSettings;
};

View File

@@ -101,23 +101,6 @@ void CppCodeModelSettingsWidget::applyToSettings() const
m_settings->toSettings(Core::ICore::settings());
}
QString CppCodeModelSettingsWidget::searchKeywords() const
{
QString rc;
QTextStream ts(&rc);
ts << m_ui->theGroupBox->title()
<< ' ' << m_ui->cLabel->text()
<< ' ' << m_ui->cppLabel->text()
<< ' ' << m_ui->objcLabel->text()
<< ' ' << m_ui->objcppLabel->text()
<< ' ' << m_ui->anotherGroupBox->title()
<< ' ' << m_ui->ignorePCHCheckBox->text();
foreach (const QString &mmsNames, m_settings->availableModelManagerSupportersByName().keys())
ts << ' ' << mmsNames;
rc.remove(QLatin1Char('&'));
return rc;
}
bool CppCodeModelSettingsWidget::applyToSettings(QComboBox *chooser, const QString &mimeType) const
{
QString newId = chooser->itemData(chooser->currentIndex()).toString();
@@ -141,12 +124,12 @@ CppCodeModelSettingsPage::CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSe
setCategoryIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
}
QWidget *CppCodeModelSettingsPage::createPage(QWidget *parent)
QWidget *CppCodeModelSettingsPage::widget()
{
m_widget = new CppCodeModelSettingsWidget(parent);
m_widget->setSettings(m_settings);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
if (!m_widget) {
m_widget = new CppCodeModelSettingsWidget;
m_widget->setSettings(m_settings);
}
return m_widget;
}
@@ -156,7 +139,7 @@ void CppCodeModelSettingsPage::apply()
m_widget->applyToSettings();
}
bool CppCodeModelSettingsPage::matches(const QString &s) const
void CppCodeModelSettingsPage::finish()
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
delete m_widget;
}

View File

@@ -56,8 +56,6 @@ public:
void setSettings(const QSharedPointer<CppCodeModelSettings> &s);
void applyToSettings() const;
QString searchKeywords() const;
private:
bool applyToSettings(QComboBox *chooser, const QString &mimeType) const;
void applyToWidget(QComboBox *chooser, const QString &mimeType) const;
@@ -73,15 +71,13 @@ public:
explicit CppCodeModelSettingsPage(QSharedPointer<CppCodeModelSettings> &settings,
QObject *parent = 0);
QWidget *createPage(QWidget *parent);
QWidget *widget();
void apply();
void finish() { }
bool matches(const QString &s) const;
void finish();
private:
const QSharedPointer<CppCodeModelSettings> m_settings;
QPointer<CppCodeModelSettingsWidget> m_widget;
QString m_searchKeywords;
};
} // Internal namespace

View File

@@ -428,44 +428,6 @@ void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::IC
updatePreview();
}
QString CppCodeStylePreferencesWidget::searchKeywords() const
{
QString rc;
QLatin1Char sep(' ');
QTextStream(&rc)
<< sep << m_ui->tabSettingsWidget->searchKeywords()
<< sep << m_ui->indentBlockBraces->text()
<< sep << m_ui->indentBlockBody->text()
<< sep << m_ui->indentClassBraces->text()
<< sep << m_ui->indentEnumBraces->text()
<< sep << m_ui->indentNamespaceBraces->text()
<< sep << m_ui->indentNamespaceBody->text()
<< sep << m_ui->indentAccessSpecifiers->text()
<< sep << m_ui->indentDeclarationsRelativeToAccessSpecifiers->text()
<< sep << m_ui->indentFunctionBody->text()
<< sep << m_ui->indentFunctionBraces->text()
<< sep << m_ui->indentSwitchLabels->text()
<< sep << m_ui->indentCaseStatements->text()
<< sep << m_ui->indentCaseBlocks->text()
<< sep << m_ui->indentCaseBreak->text()
<< sep << m_ui->bindStarToIdentifier->text()
<< sep << m_ui->bindStarToTypeName->text()
<< sep << m_ui->bindStarToLeftSpecifier->text()
<< sep << m_ui->bindStarToRightSpecifier->text()
<< sep << m_ui->contentGroupBox->title()
<< sep << m_ui->bracesGroupBox->title()
<< sep << m_ui->switchGroupBox->title()
<< sep << m_ui->alignmentGroupBox->title()
<< sep << m_ui->pointerReferencesGroupBox->title()
<< sep << m_ui->extraPaddingConditions->text()
<< sep << m_ui->alignAssignments->text()
;
for (int i = 0; i < m_ui->categoryTab->count(); i++)
QTextStream(&rc) << sep << m_ui->categoryTab->tabText(i);
rc.remove(QLatin1Char('&'));
return rc;
}
void CppCodeStylePreferencesWidget::slotCodeStyleSettingsChanged()
{
if (m_blockUpdates)
@@ -564,19 +526,20 @@ CppCodeStyleSettingsPage::CppCodeStyleSettingsPage(QWidget *parent) :
setCategoryIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
}
QWidget *CppCodeStyleSettingsPage::createPage(QWidget *parent)
QWidget *CppCodeStyleSettingsPage::widget()
{
CppCodeStylePreferences *originalCodeStylePreferences
= CppToolsSettings::instance()->cppCodeStyle();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(m_widget);
m_pageCppCodeStylePreferences->setDelegatingPool(originalCodeStylePreferences->delegatingPool());
m_pageCppCodeStylePreferences->setCodeStyleSettings(originalCodeStylePreferences->codeStyleSettings());
m_pageCppCodeStylePreferences->setCurrentDelegate(originalCodeStylePreferences->currentDelegate());
// we set id so that it won't be possible to set delegate to the original prefs
m_pageCppCodeStylePreferences->setId(originalCodeStylePreferences->id());
m_widget = new CodeStyleEditor(TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID),
m_pageCppCodeStylePreferences, parent);
if (!m_widget) {
CppCodeStylePreferences *originalCodeStylePreferences
= CppToolsSettings::instance()->cppCodeStyle();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(m_widget);
m_pageCppCodeStylePreferences->setDelegatingPool(originalCodeStylePreferences->delegatingPool());
m_pageCppCodeStylePreferences->setCodeStyleSettings(originalCodeStylePreferences->codeStyleSettings());
m_pageCppCodeStylePreferences->setCurrentDelegate(originalCodeStylePreferences->currentDelegate());
// we set id so that it won't be possible to set delegate to the original prefs
m_pageCppCodeStylePreferences->setId(originalCodeStylePreferences->id());
m_widget = new CodeStyleEditor(TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID),
m_pageCppCodeStylePreferences);
}
return m_widget;
}
@@ -601,9 +564,9 @@ void CppCodeStyleSettingsPage::apply()
}
}
bool CppCodeStyleSettingsPage::matches(const QString &s) const
void CppCodeStyleSettingsPage::finish()
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
delete m_widget;
}
} // namespace Internal

View File

@@ -66,8 +66,6 @@ public:
void setCodeStyle(CppTools::CppCodeStylePreferences *codeStylePreferences);
QString searchKeywords() const;
private slots:
void decorateEditors(const TextEditor::FontSettings &fontSettings);
void setVisualizeWhitespace(bool on);
@@ -95,13 +93,11 @@ class CppCodeStyleSettingsPage : public Core::IOptionsPage
public:
explicit CppCodeStyleSettingsPage(QWidget *parent = 0);
QWidget *createPage(QWidget *parent);
QWidget *widget();
void apply();
void finish() { }
bool matches(const QString &) const;
void finish();
private:
QString m_searchKeywords;
CppCodeStylePreferences *m_pageCppCodeStylePreferences;
QPointer<TextEditor::CodeStyleEditor> m_widget;
};

View File

@@ -293,21 +293,6 @@ CppFileSettings CppFileSettingsWidget::settings() const
return rc;
}
QString CppFileSettingsWidget::searchKeywords() const
{
QString rc;
QTextStream(&rc) << m_ui->headersGroupBox->title()
<< ' ' << m_ui->headerSuffixLabel->text()
<< ' ' << m_ui->headerSearchPathsLabel->text()
<< ' ' << m_ui->sourcesGroupBox->title()
<< ' ' << m_ui->sourceSuffixLabel->text()
<< ' ' << m_ui->sourceSearchPathsLabel->text()
<< ' ' << m_ui->lowerCaseFileNamesCheckBox->text()
<< ' ' << m_ui->licenseTemplateLabel->text();
rc.remove(QLatin1Char('&'));
return rc;
}
static inline void setComboText(QComboBox *cb, const QString &text, int defaultIndex = 0)
{
const int index = cb->findText(text);
@@ -355,13 +340,13 @@ CppFileSettingsPage::CppFileSettingsPage(QSharedPointer<CppFileSettings> &settin
setCategoryIcon(QLatin1String(Constants::SETTINGS_CATEGORY_CPP_ICON));
}
QWidget *CppFileSettingsPage::createPage(QWidget *parent)
QWidget *CppFileSettingsPage::widget()
{
m_widget = new CppFileSettingsWidget(parent);
m_widget->setSettings(*m_settings);
if (m_searchKeywords.isEmpty())
m_searchKeywords = m_widget->searchKeywords();
if (!m_widget) {
m_widget = new CppFileSettingsWidget;
m_widget->setSettings(*m_settings);
}
return m_widget;
}
@@ -378,9 +363,9 @@ void CppFileSettingsPage::apply()
}
}
bool CppFileSettingsPage::matches(const QString &s) const
void CppFileSettingsPage::finish()
{
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
delete m_widget;
}
} // namespace Internal

View File

@@ -80,8 +80,6 @@ public:
CppFileSettings settings() const;
void setSettings(const CppFileSettings &s);
QString searchKeywords() const;
private slots:
void slotEdit();
@@ -98,15 +96,13 @@ public:
explicit CppFileSettingsPage(QSharedPointer<CppFileSettings> &settings,
QObject *parent = 0);
QWidget *createPage(QWidget *parent);
QWidget *widget();
void apply();
void finish() { }
bool matches(const QString &) const;
void finish();
private:
const QSharedPointer<CppFileSettings> m_settings;
QPointer<CppFileSettingsWidget> m_widget;
QString m_searchKeywords;
};
} // namespace Internal