Commit 8390a321 authored by hjk's avatar hjk

Settings: Simplify some user code

This is still way too much boiler plate code for the task at hand.

Change-Id: Ia03bff3d6947ea6372e3f5d0217c116728742b74
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
parent 0b225af8
......@@ -108,14 +108,11 @@ void NavigationWidgetFactory::saveSettings(int position, QWidget *widget)
NavigationWidget *pw = qobject_cast<NavigationWidget *>(widget);
QTC_ASSERT(pw, return);
QSettings *settings = Core::ICore::settings();
QTC_ASSERT(settings, return);
// .beginGroup is not used - to prevent simultaneous access
QString group = settingsPrefix(position);
// save settings
settings->setValue(group, pw->flatMode());
// Save settings
Core::ICore::settings()->setValue(group, pw->flatMode());
}
void NavigationWidgetFactory::restoreSettings(int position, QWidget *widget)
......@@ -123,14 +120,11 @@ void NavigationWidgetFactory::restoreSettings(int position, QWidget *widget)
NavigationWidget *pw = qobject_cast<NavigationWidget *>(widget);
QTC_ASSERT(pw, return);
QSettings *settings = Core::ICore::settings();
QTC_ASSERT(settings, return);
// .beginGroup is not used - to prevent simultaneous access
QString group = settingsPrefix(position);
// load settings
pw->setFlatMode(settings->value(group, false).toBool());
// Load settings
pw->setFlatMode(Core::ICore::settings()->value(group, false).toBool());
}
} // namespace Internal
......
......@@ -107,14 +107,12 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
m_widget = new QWidget(parent);
m_page->setupUi(m_widget);
QSettings *settings = Core::ICore::settings();
Q_UNUSED(settings) // Windows
fillLanguageBox();
m_page->colorButton->setColor(StyleHelper::requestedBaseColor());
m_page->reloadBehavior->setCurrentIndex(EditorManager::instance()->reloadSetting());
if (HostOsInfo::isAnyUnixHost()) {
QSettings *settings = Core::ICore::settings();
const QStringList availableTerminals = ConsoleProcess::availableTerminalEmulators();
const QString currentTerminal = ConsoleProcess::terminalEmulator(settings, false);
const QString currentTerminalExplicit = ConsoleProcess::terminalEmulator(settings, true);
......@@ -128,6 +126,7 @@ QWidget *GeneralSettings::createPage(QWidget *parent)
}
if (HostOsInfo::isAnyUnixHost() && !HostOsInfo::isMacHost()) {
QSettings *settings = Core::ICore::settings();
m_page->externalFileBrowserEdit->setText(UnixUtils::fileBrowser(settings));
} else {
m_page->externalFileBrowserLabel->hide();
......
......@@ -52,11 +52,8 @@ CodePasterSettingsPage::CodePasterSettingsPage()
setDisplayCategory(QCoreApplication::translate("CodePaster",
Constants::CPASTER_SETTINGS_TR_CATEGORY));
m_settings = Core::ICore::settings();
if (m_settings) {
const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
m_host = m_settings->value(keyRoot + QLatin1String(serverKeyC), QString()).toString();
}
const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
m_host = Core::ICore::settings()->value(keyRoot + QLatin1String(serverKeyC), QString()).toString();
}
QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
......@@ -83,12 +80,11 @@ QWidget *CodePasterSettingsPage::createPage(QWidget *parent)
void CodePasterSettingsPage::apply()
{
if (!m_settings)
return;
m_settings->beginGroup(QLatin1String(settingsGroupC));
m_settings->setValue(QLatin1String(serverKeyC), m_host);
m_settings->endGroup();
QSettings *settings = Core::ICore::settings();
const QString keyRoot = QLatin1String(settingsGroupC) + QLatin1Char('/');
settings->beginGroup(QLatin1String(settingsGroupC));
settings->setValue(QLatin1String(serverKeyC), m_host);
settings->endGroup();
}
void CodePasterSettingsPage::serverChanged(const QString &host)
......
......@@ -55,7 +55,6 @@ public slots:
void serverChanged(const QString &host);
private:
QSettings *m_settings;
QString m_host;
};
......
......@@ -590,18 +590,15 @@ void CppCodeStyleSettingsPage::apply()
CppCodeStylePreferences *originalCppCodeStylePreferences = CppToolsSettings::instance()->cppCodeStyle();
if (originalCppCodeStylePreferences->codeStyleSettings() != m_pageCppCodeStylePreferences->codeStyleSettings()) {
originalCppCodeStylePreferences->setCodeStyleSettings(m_pageCppCodeStylePreferences->codeStyleSettings());
if (s)
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
}
if (originalCppCodeStylePreferences->tabSettings() != m_pageCppCodeStylePreferences->tabSettings()) {
originalCppCodeStylePreferences->setTabSettings(m_pageCppCodeStylePreferences->tabSettings());
if (s)
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
}
if (originalCppCodeStylePreferences->currentDelegate() != m_pageCppCodeStylePreferences->currentDelegate()) {
originalCppCodeStylePreferences->setCurrentDelegate(m_pageCppCodeStylePreferences->currentDelegate());
if (s)
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
originalCppCodeStylePreferences->toSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
}
}
}
......
......@@ -172,7 +172,7 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
// 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), Core::ICore::settings());
d->m_globalCodeStyle->fromSettings(QLatin1String(CppTools::Constants::CPP_SETTINGS_ID), s);
// legacy handling start (Qt Creator Version < 2.4)
const bool legacyTransformed =
......
......@@ -233,8 +233,7 @@ bool CvsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
if (!ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.cvs/CVS.mimetypes.xml"), errorMessage))
return false;
if (QSettings *settings = ICore::settings())
m_settings.fromSettings(settings);
m_settings.fromSettings(ICore::settings());
addAutoReleasedObject(new SettingsPage);
......@@ -1299,8 +1298,7 @@ void CvsPlugin::setSettings(const CvsSettings &s)
{
if (s != m_settings) {
m_settings = s;
if (QSettings *settings = ICore::settings())
m_settings.toSettings(settings);
m_settings.toSettings(ICore::settings());
cvsVersionControl()->emitConfigurationChanged();
}
}
......
......@@ -552,8 +552,6 @@ QWidget *DebuggerMainWindow::createContents(IMode *mode)
void DebuggerMainWindow::writeSettings() const
{
QSettings *settings = ICore::settings();
QTC_ASSERT(settings, return);
settings->beginGroup(QLatin1String("DebugMode.CppMode"));
QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
while (it.hasNext()) {
......@@ -574,8 +572,6 @@ void DebuggerMainWindow::writeSettings() const
void DebuggerMainWindow::readSettings()
{
QSettings *settings = ICore::settings();
QTC_ASSERT(settings, return);
d->m_dockWidgetActiveStateCpp.clear();
d->m_dockWidgetActiveStateQmlCpp.clear();
......
......@@ -37,61 +37,40 @@
using namespace Designer::Internal;
static inline QSettings *coreSettings()
{
if (Core::ICore::instance())
return Core::ICore::settings();
return 0;
}
void SettingsManager::beginGroup(const QString &prefix)
{
QSettings *settings = coreSettings();
QTC_ASSERT(settings, return);
settings->beginGroup(addPrefix(prefix));
Core::ICore::settings()->beginGroup(addPrefix(prefix));
}
void SettingsManager::endGroup()
{
QSettings *settings = coreSettings();
QTC_ASSERT(settings, return);
settings->endGroup();
Core::ICore::settings()->endGroup();
}
bool SettingsManager::contains(const QString &key) const
{
const QSettings *settings = coreSettings();
QTC_ASSERT(settings, return false);
return settings->contains(addPrefix(key));
return Core::ICore::settings()->contains(addPrefix(key));
}
void SettingsManager::setValue(const QString &key, const QVariant &value)
{
QSettings *settings = coreSettings();
QTC_ASSERT(settings, return);
settings->setValue(addPrefix(key), value);
Core::ICore::settings()->setValue(addPrefix(key), value);
}
QVariant SettingsManager::value(const QString &key, const QVariant &defaultValue) const
{
const QSettings *settings = coreSettings();
QTC_ASSERT(settings, return QVariant());
return settings->value(addPrefix(key), defaultValue);
return Core::ICore::settings()->value(addPrefix(key), defaultValue);
}
void SettingsManager::remove(const QString &key)
{
QSettings *settings = coreSettings();
QTC_ASSERT(settings, return);
settings->remove(addPrefix(key));
Core::ICore::settings()->remove(addPrefix(key));
}
QString SettingsManager::addPrefix(const QString &name) const
{
const QSettings *settings = coreSettings();
QTC_ASSERT(settings, return name);
QString result = name;
if (settings->group().isEmpty())
if (Core::ICore::settings()->group().isEmpty())
result.prepend(QLatin1String("Designer"));
return result;
}
......@@ -521,11 +521,9 @@ void SearchResultWindow::handleExpandCollapseToolButton(bool checked)
void SearchResultWindow::readSettings()
{
QSettings *s = Core::ICore::settings();
if (s) {
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
d->m_expandCollapseAction->setChecked(s->value(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_initiallyExpand).toBool());
s->endGroup();
}
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
d->m_expandCollapseAction->setChecked(s->value(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_initiallyExpand).toBool());
s->endGroup();
}
/*!
......@@ -535,11 +533,9 @@ void SearchResultWindow::readSettings()
void SearchResultWindow::writeSettings()
{
QSettings *s = Core::ICore::settings();
if (s) {
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
s->setValue(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_expandCollapseAction->isChecked());
s->endGroup();
}
s->beginGroup(QLatin1String(SETTINGSKEYSECTIONNAME));
s->setValue(QLatin1String(SETTINGSKEYEXPANDRESULTS), d->m_expandCollapseAction->isChecked());
s->endGroup();
}
/*!
......
......@@ -1274,37 +1274,35 @@ void ProjectExplorerPlugin::savePersistentSettings()
}
QSettings *s = Core::ICore::settings();
if (s) {
s->setValue(QLatin1String("ProjectExplorer/StartupSession"), d->m_session->activeSession());
s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files"));
QStringList fileNames;
QStringList displayNames;
QList<QPair<QString, QString> >::const_iterator it, end;
end = d->m_recentProjects.constEnd();
for (it = d->m_recentProjects.constBegin(); it != end; ++it) {
fileNames << (*it).first;
displayNames << (*it).second;
}
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/FileNames"), fileNames);
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/DisplayNames"), displayNames);
s->setValue(QLatin1String("ProjectExplorer/Settings/BuildBeforeDeploy"), d->m_projectExplorerSettings.buildBeforeDeploy);
s->setValue(QLatin1String("ProjectExplorer/Settings/DeployBeforeRun"), d->m_projectExplorerSettings.deployBeforeRun);
s->setValue(QLatin1String("ProjectExplorer/Settings/SaveBeforeBuild"), d->m_projectExplorerSettings.saveBeforeBuild);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowCompilerOutput"), d->m_projectExplorerSettings.showCompilerOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowRunOutput"), d->m_projectExplorerSettings.showRunOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowDebugOutput"), d->m_projectExplorerSettings.showDebugOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/CleanOldAppOutput"), d->m_projectExplorerSettings.cleanOldAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/MergeStdErrAndStdOut"), d->m_projectExplorerSettings.mergeStdErrAndStdOut);
s->setValue(QLatin1String("ProjectExplorer/Settings/WrapAppOutput"), d->m_projectExplorerSettings.wrapAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/UseJom"), d->m_projectExplorerSettings.useJom);
s->setValue(QLatin1String("ProjectExplorer/Settings/AutoRestoreLastSession"), d->m_projectExplorerSettings.autorestoreLastSession);
s->setValue(QLatin1String("ProjectExplorer/Settings/PromptToStopRunControl"), d->m_projectExplorerSettings.prompToStopRunControl);
s->setValue(QLatin1String("ProjectExplorer/Settings/MaxAppOutputLines"), d->m_projectExplorerSettings.maxAppOutputLines);
s->setValue(QLatin1String("ProjectExplorer/Settings/EnvironmentId"), d->m_projectExplorerSettings.environmentId.toByteArray());
}
s->setValue(QLatin1String("ProjectExplorer/StartupSession"), d->m_session->activeSession());
s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files"));
QStringList fileNames;
QStringList displayNames;
QList<QPair<QString, QString> >::const_iterator it, end;
end = d->m_recentProjects.constEnd();
for (it = d->m_recentProjects.constBegin(); it != end; ++it) {
fileNames << (*it).first;
displayNames << (*it).second;
}
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/FileNames"), fileNames);
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/DisplayNames"), displayNames);
s->setValue(QLatin1String("ProjectExplorer/Settings/BuildBeforeDeploy"), d->m_projectExplorerSettings.buildBeforeDeploy);
s->setValue(QLatin1String("ProjectExplorer/Settings/DeployBeforeRun"), d->m_projectExplorerSettings.deployBeforeRun);
s->setValue(QLatin1String("ProjectExplorer/Settings/SaveBeforeBuild"), d->m_projectExplorerSettings.saveBeforeBuild);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowCompilerOutput"), d->m_projectExplorerSettings.showCompilerOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowRunOutput"), d->m_projectExplorerSettings.showRunOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowDebugOutput"), d->m_projectExplorerSettings.showDebugOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/CleanOldAppOutput"), d->m_projectExplorerSettings.cleanOldAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/MergeStdErrAndStdOut"), d->m_projectExplorerSettings.mergeStdErrAndStdOut);
s->setValue(QLatin1String("ProjectExplorer/Settings/WrapAppOutput"), d->m_projectExplorerSettings.wrapAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/UseJom"), d->m_projectExplorerSettings.useJom);
s->setValue(QLatin1String("ProjectExplorer/Settings/AutoRestoreLastSession"), d->m_projectExplorerSettings.autorestoreLastSession);
s->setValue(QLatin1String("ProjectExplorer/Settings/PromptToStopRunControl"), d->m_projectExplorerSettings.prompToStopRunControl);
s->setValue(QLatin1String("ProjectExplorer/Settings/MaxAppOutputLines"), d->m_projectExplorerSettings.maxAppOutputLines);
s->setValue(QLatin1String("ProjectExplorer/Settings/EnvironmentId"), d->m_projectExplorerSettings.environmentId.toByteArray());
}
void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
......
......@@ -196,13 +196,11 @@ void QmlJSCodeStyleSettingsPage::apply()
TextEditor::SimpleCodeStylePreferences *originalTabPreferences = QmlJSToolsSettings::globalCodeStyle();
if (originalTabPreferences->tabSettings() != m_pageTabPreferences->tabSettings()) {
originalTabPreferences->setTabSettings(m_pageTabPreferences->tabSettings());
if (s)
originalTabPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
originalTabPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
}
if (originalTabPreferences->currentDelegate() != m_pageTabPreferences->currentDelegate()) {
originalTabPreferences->setCurrentDelegate(m_pageTabPreferences->currentDelegate());
if (s)
originalTabPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
originalTabPreferences->toSettings(QLatin1String(QmlJSTools::Constants::QML_JS_SETTINGS_ID), s);
}
}
}
......
......@@ -131,7 +131,7 @@ bool BlackBerryConfiguration::refresh()
void BlackBerryConfiguration::loadCertificates()
{
QSettings *settings = Core::ICore::instance()->settings();
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->beginGroup(CertificateGroup);
......@@ -158,7 +158,7 @@ void BlackBerryConfiguration::loadCertificates()
void BlackBerryConfiguration::loadNdkSettings()
{
QSettings *settings = Core::ICore::instance()->settings();
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
setNdkPath(settings->value(NDKLocationKey).toString());
......@@ -167,7 +167,7 @@ void BlackBerryConfiguration::loadNdkSettings()
void BlackBerryConfiguration::saveCertificates()
{
QSettings *settings = Core::ICore::instance()->settings();
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->beginGroup(CertificateGroup);
......@@ -194,7 +194,7 @@ void BlackBerryConfiguration::saveNdkSettings()
if (m_config.ndkPath.isEmpty())
return;
QSettings *settings = Core::ICore::instance()->settings();
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->setValue(NDKLocationKey, m_config.ndkPath);
settings->endGroup();
......@@ -396,7 +396,7 @@ void BlackBerryConfiguration::saveSettings()
void BlackBerryConfiguration::clearNdkSettings()
{
QSettings *settings = Core::ICore::instance()->settings();
QSettings *settings = Core::ICore::settings();
settings->beginGroup(SettingsGroup);
settings->remove(NDKLocationKey);
settings->endGroup();
......
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