Commit fb8e3b99 authored by Nikolai Kosjar's avatar Nikolai Kosjar Committed by Erik Verbruggen

CppTools: Clean up commentssettings

Change-Id: I397195a3e6d8b40a55d2a68429daf6c812f52da2
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 205170a9
...@@ -29,9 +29,9 @@ ...@@ -29,9 +29,9 @@
****************************************************************************/ ****************************************************************************/
#include "completionsettingspage.h" #include "completionsettingspage.h"
#include "ui_completionsettingspage.h"
#include <ui_completionsettingspage.h> #include "cpptoolssettings.h"
#include "cpptoolsconstants.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <texteditor/texteditorsettings.h> #include <texteditor/texteditorsettings.h>
...@@ -40,14 +40,11 @@ ...@@ -40,14 +40,11 @@
using namespace CppTools; using namespace CppTools;
using namespace CppTools::Internal; using namespace CppTools::Internal;
using namespace CppTools::Constants;
CompletionSettingsPage::CompletionSettingsPage(QObject *parent) CompletionSettingsPage::CompletionSettingsPage(QObject *parent)
: TextEditor::TextEditorOptionsPage(parent) : TextEditor::TextEditorOptionsPage(parent)
, m_page(0) , m_page(0)
{ {
m_commentsSettings.fromSettings(QLatin1String(CPPTOOLS_SETTINGSGROUP), Core::ICore::settings());
setId("P.Completion"); setId("P.Completion");
setDisplayName(tr("Completion")); setDisplayName(tr("Completion"));
} }
...@@ -68,11 +65,11 @@ QWidget *CompletionSettingsPage::widget() ...@@ -68,11 +65,11 @@ QWidget *CompletionSettingsPage::widget()
static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CompletionSettingsPage::onCompletionTriggerChanged); this, &CompletionSettingsPage::onCompletionTriggerChanged);
const TextEditor::CompletionSettings &settings = const TextEditor::CompletionSettings &completionSettings =
TextEditor::TextEditorSettings::completionSettings(); TextEditor::TextEditorSettings::completionSettings();
int caseSensitivityIndex = 0; int caseSensitivityIndex = 0;
switch (settings.m_caseSensitivity) { switch (completionSettings.m_caseSensitivity) {
case TextEditor::CaseSensitive: case TextEditor::CaseSensitive:
caseSensitivityIndex = 0; caseSensitivityIndex = 0;
break; break;
...@@ -85,7 +82,7 @@ QWidget *CompletionSettingsPage::widget() ...@@ -85,7 +82,7 @@ QWidget *CompletionSettingsPage::widget()
} }
int completionTriggerIndex = 0; int completionTriggerIndex = 0;
switch (settings.m_completionTrigger) { switch (completionSettings.m_completionTrigger) {
case TextEditor::ManualCompletion: case TextEditor::ManualCompletion:
completionTriggerIndex = 0; completionTriggerIndex = 0;
break; break;
...@@ -99,15 +96,19 @@ QWidget *CompletionSettingsPage::widget() ...@@ -99,15 +96,19 @@ QWidget *CompletionSettingsPage::widget()
m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex); m_page->caseSensitivity->setCurrentIndex(caseSensitivityIndex);
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex); m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
m_page->automaticProposalTimeoutSpinBox->setValue(settings.m_automaticProposalTimeoutInMs); m_page->automaticProposalTimeoutSpinBox
m_page->autoInsertBrackets->setChecked(settings.m_autoInsertBrackets); ->setValue(completionSettings.m_automaticProposalTimeoutInMs);
m_page->surroundSelectedText->setChecked(settings.m_surroundingAutoBrackets); m_page->autoInsertBrackets->setChecked(completionSettings.m_autoInsertBrackets);
m_page->partiallyComplete->setChecked(settings.m_partiallyComplete); m_page->surroundSelectedText->setChecked(completionSettings.m_surroundingAutoBrackets);
m_page->spaceAfterFunctionName->setChecked(settings.m_spaceAfterFunctionName); m_page->partiallyComplete->setChecked(completionSettings.m_partiallyComplete);
m_page->autoSplitStrings->setChecked(settings.m_autoSplitStrings); m_page->spaceAfterFunctionName->setChecked(completionSettings.m_spaceAfterFunctionName);
m_page->enableDoxygenCheckBox->setChecked(m_commentsSettings.m_enableDoxygen); m_page->autoSplitStrings->setChecked(completionSettings.m_autoSplitStrings);
m_page->generateBriefCheckBox->setChecked(m_commentsSettings.m_generateBrief);
m_page->leadingAsterisksCheckBox->setChecked(m_commentsSettings.m_leadingAsterisks); const CommentsSettings &commentsSettings = CppToolsSettings::instance()->commentsSettings();
m_page->enableDoxygenCheckBox->setChecked(commentsSettings.m_enableDoxygen);
m_page->generateBriefCheckBox->setChecked(commentsSettings.m_generateBrief);
m_page->leadingAsterisksCheckBox->setChecked(commentsSettings.m_leadingAsterisks);
m_page->generateBriefCheckBox->setEnabled(m_page->enableDoxygenCheckBox->isChecked()); m_page->generateBriefCheckBox->setEnabled(m_page->enableDoxygenCheckBox->isChecked());
} }
return m_widget; return m_widget;
...@@ -117,27 +118,27 @@ void CompletionSettingsPage::apply() ...@@ -117,27 +118,27 @@ void CompletionSettingsPage::apply()
{ {
if (!m_page) // page was never shown if (!m_page) // page was never shown
return; return;
TextEditor::CompletionSettings settings;
settings.m_caseSensitivity = caseSensitivity(); TextEditor::CompletionSettings completionSettings;
settings.m_completionTrigger = completionTrigger(); completionSettings.m_caseSensitivity = caseSensitivity();
settings.m_automaticProposalTimeoutInMs = m_page->automaticProposalTimeoutSpinBox->value(); completionSettings.m_completionTrigger = completionTrigger();
settings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked(); completionSettings.m_automaticProposalTimeoutInMs
settings.m_surroundingAutoBrackets = m_page->surroundSelectedText->isChecked(); = m_page->automaticProposalTimeoutSpinBox->value();
settings.m_partiallyComplete = m_page->partiallyComplete->isChecked(); completionSettings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
settings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked(); completionSettings.m_surroundingAutoBrackets = m_page->surroundSelectedText->isChecked();
settings.m_autoSplitStrings = m_page->autoSplitStrings->isChecked(); completionSettings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
completionSettings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
TextEditor::TextEditorSettings::setCompletionSettings(settings); completionSettings.m_autoSplitStrings = m_page->autoSplitStrings->isChecked();
TextEditor::TextEditorSettings::setCompletionSettings(completionSettings);
if (!requireCommentsSettingsUpdate()) if (!requireCommentsSettingsUpdate())
return; return;
m_commentsSettings.m_enableDoxygen = m_page->enableDoxygenCheckBox->isChecked(); CommentsSettings commentsSettings;
m_commentsSettings.m_generateBrief = m_page->generateBriefCheckBox->isChecked(); commentsSettings.m_enableDoxygen = m_page->enableDoxygenCheckBox->isChecked();
m_commentsSettings.m_leadingAsterisks = m_page->leadingAsterisksCheckBox->isChecked(); commentsSettings.m_generateBrief = m_page->generateBriefCheckBox->isChecked();
m_commentsSettings.toSettings(QLatin1String(CPPTOOLS_SETTINGSGROUP), Core::ICore::settings()); commentsSettings.m_leadingAsterisks = m_page->leadingAsterisksCheckBox->isChecked();
CppToolsSettings::instance()->setCommentsSettings(commentsSettings);
emit commentsSettingsChanged(m_commentsSettings);
} }
TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const TextEditor::CaseSensitivity CompletionSettingsPage::caseSensitivity() const
...@@ -180,14 +181,10 @@ void CompletionSettingsPage::finish() ...@@ -180,14 +181,10 @@ void CompletionSettingsPage::finish()
m_page = 0; m_page = 0;
} }
const CommentsSettings &CompletionSettingsPage::commentsSettings() const
{
return m_commentsSettings;
}
bool CompletionSettingsPage::requireCommentsSettingsUpdate() const bool CompletionSettingsPage::requireCommentsSettingsUpdate() const
{ {
return m_commentsSettings.m_enableDoxygen != m_page->enableDoxygenCheckBox->isChecked() const CommentsSettings &commentsSettings = CppToolsSettings::instance()->commentsSettings();
|| m_commentsSettings.m_generateBrief != m_page->generateBriefCheckBox->isChecked() return commentsSettings.m_enableDoxygen != m_page->enableDoxygenCheckBox->isChecked()
|| m_commentsSettings.m_leadingAsterisks != m_page->leadingAsterisksCheckBox->isChecked(); || commentsSettings.m_generateBrief != m_page->generateBriefCheckBox->isChecked()
|| commentsSettings.m_leadingAsterisks != m_page->leadingAsterisksCheckBox->isChecked();
} }
...@@ -57,11 +57,6 @@ public: ...@@ -57,11 +57,6 @@ public:
void apply(); void apply();
void finish(); void finish();
const CommentsSettings &commentsSettings() const;
signals:
void commentsSettingsChanged(const CppTools::CommentsSettings &settings);
private: private:
TextEditor::CaseSensitivity caseSensitivity() const; TextEditor::CaseSensitivity caseSensitivity() const;
TextEditor::CompletionTrigger completionTrigger() const; TextEditor::CompletionTrigger completionTrigger() const;
......
...@@ -64,6 +64,7 @@ public: ...@@ -64,6 +64,7 @@ public:
, m_completionSettingsPage(0) , m_completionSettingsPage(0)
{} {}
CommentsSettings m_commentsSettings;
CppCodeStylePreferences *m_globalCodeStyle; CppCodeStylePreferences *m_globalCodeStyle;
CompletionSettingsPage *m_completionSettingsPage; CompletionSettingsPage *m_completionSettingsPage;
}; };
...@@ -82,14 +83,11 @@ CppToolsSettings::CppToolsSettings(QObject *parent) ...@@ -82,14 +83,11 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
qRegisterMetaType<CppTools::CppCodeStyleSettings>("CppTools::CppCodeStyleSettings"); qRegisterMetaType<CppTools::CppCodeStyleSettings>("CppTools::CppCodeStyleSettings");
QSettings *s = Core::ICore::settings();
d->m_commentsSettings.fromSettings(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP), s);
d->m_completionSettingsPage = new CompletionSettingsPage(this); d->m_completionSettingsPage = new CompletionSettingsPage(this);
ExtensionSystem::PluginManager::addObject(d->m_completionSettingsPage); ExtensionSystem::PluginManager::addObject(d->m_completionSettingsPage);
connect(d->m_completionSettingsPage,
SIGNAL(commentsSettingsChanged(CppTools::CommentsSettings)),
this,
SIGNAL(commentsSettingsChanged(CppTools::CommentsSettings)));
// code style factory // code style factory
ICodeStylePreferencesFactory *factory = new CppTools::CppCodeStylePreferencesFactory(); ICodeStylePreferencesFactory *factory = new CppTools::CppCodeStylePreferencesFactory();
TextEditorSettings::registerCodeStyleFactory(factory); TextEditorSettings::registerCodeStyleFactory(factory);
...@@ -170,7 +168,6 @@ CppToolsSettings::CppToolsSettings(QObject *parent) ...@@ -170,7 +168,6 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
pool->loadCustomCodeStyles(); pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool) // load global settings (after built-in settings are added to the pool)
QSettings *s = Core::ICore::settings();
d->m_globalCodeStyle->fromSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s); d->m_globalCodeStyle->fromSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
// legacy handling start (Qt Creator Version < 2.4) // legacy handling start (Qt Creator Version < 2.4)
...@@ -253,5 +250,15 @@ CppCodeStylePreferences *CppToolsSettings::cppCodeStyle() const ...@@ -253,5 +250,15 @@ CppCodeStylePreferences *CppToolsSettings::cppCodeStyle() const
const CommentsSettings &CppToolsSettings::commentsSettings() const const CommentsSettings &CppToolsSettings::commentsSettings() const
{ {
return d->m_completionSettingsPage->commentsSettings(); return d->m_commentsSettings;
}
void CppToolsSettings::setCommentsSettings(const CommentsSettings &commentsSettings)
{
if (d->m_commentsSettings == commentsSettings)
return;
d->m_commentsSettings = commentsSettings;
d->m_commentsSettings.toSettings(QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP),
Core::ICore::settings());
} }
...@@ -59,10 +59,9 @@ public: ...@@ -59,10 +59,9 @@ public:
static CppToolsSettings *instance(); static CppToolsSettings *instance();
CppCodeStylePreferences *cppCodeStyle() const; CppCodeStylePreferences *cppCodeStyle() const;
const CommentsSettings &commentsSettings() const;
signals: const CommentsSettings &commentsSettings() const;
void commentsSettingsChanged(const CppTools::CommentsSettings &settings); void setCommentsSettings(const CommentsSettings &commentsSettings);
private: private:
Internal::CppToolsSettingsPrivate *d; Internal::CppToolsSettingsPrivate *d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment