summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Kobus <jkobus@trolltech.com>2011-06-20 16:23:40 +0200
committerJarek Kobus <jaroslaw.kobus@nokia.com>2011-06-20 17:00:01 +0200
commitc61652d0655b0782044bbf9fb18226954d5e427a (patch)
tree20a44eb6d9a19a64442fdd1c1d99f64de8d45981
parentdcf7345931f2e0222c3c788178a9bf76a19ef594 (diff)
downloadqt-creator-c61652d0655b0782044bbf9fb18226954d5e427a.tar.gz
Small refactor
Change-Id: I2988ce1c2a73798abccf690a3ed5d4e3a92c91a2 Reviewed-on: http://codereview.qt.nokia.com/517 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
-rw-r--r--src/plugins/projectexplorer/editorconfiguration.cpp7
-rw-r--r--src/plugins/texteditor/behaviorsettingspage.cpp33
-rw-r--r--src/plugins/texteditor/behaviorsettingspage.h3
-rw-r--r--src/plugins/texteditor/fallbackselectorwidget.h2
-rw-r--r--src/plugins/texteditor/tabpreferences.cpp20
-rw-r--r--src/plugins/texteditor/tabpreferences.h6
-rw-r--r--src/plugins/texteditor/tabpreferenceswidget.cpp17
-rw-r--r--src/plugins/texteditor/texteditorconstants.h2
8 files changed, 58 insertions, 32 deletions
diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp
index 544b67c0f2..089b6936d6 100644
--- a/src/plugins/projectexplorer/editorconfiguration.cpp
+++ b/src/plugins/projectexplorer/editorconfiguration.cpp
@@ -91,9 +91,10 @@ struct EditorConfigurationPrivate
EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
{
- QList<IFallbackPreferences *> fallbacks;
- fallbacks << TextEditorSettings::instance()->tabPreferences();
- m_d->m_tabPreferences = new TabPreferences(fallbacks, this);
+ TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
+ QList<TabPreferences *> tabFallbacks;
+ tabFallbacks << textEditorSettings->tabPreferences();
+ m_d->m_tabPreferences = new TabPreferences(tabFallbacks, this);
m_d->m_tabPreferences->setDisplayName(tr("Project", "Settings"));
m_d->m_tabPreferences->setId(kId);
diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp
index 2c29ac3180..7ff561b280 100644
--- a/src/plugins/texteditor/behaviorsettingspage.cpp
+++ b/src/plugins/texteditor/behaviorsettingspage.cpp
@@ -38,6 +38,7 @@
#include "extraencodingsettings.h"
#include "ui_behaviorsettingspage.h"
#include "tabpreferences.h"
+#include "texteditorconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/coreconstants.h>
@@ -46,8 +47,6 @@
#include <QtCore/QSettings>
#include <QtCore/QTextCodec>
-static const char *idKey = "Global";
-
using namespace TextEditor;
struct BehaviorSettingsPage::BehaviorSettingsPagePrivate
@@ -77,9 +76,7 @@ BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate
void BehaviorSettingsPage::BehaviorSettingsPagePrivate::init()
{
if (const QSettings *s = Core::ICore::instance()->settings()) {
- TabSettings ts;
- ts.fromSettings(m_parameters.settingsPrefix, s);
- m_tabPreferences->setSettings(ts);
+ m_tabPreferences->fromSettings(m_parameters.settingsPrefix, s);
m_storageSettings.fromSettings(m_parameters.settingsPrefix, s);
m_behaviorSettings.fromSettings(m_parameters.settingsPrefix, s);
m_extraEncodingSettings.fromSettings(m_parameters.settingsPrefix, s);
@@ -93,7 +90,7 @@ BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters
{
m_d->m_tabPreferences = new TabPreferences(QList<IFallbackPreferences *>(), this);
m_d->m_tabPreferences->setDisplayName(tr("Global", "Settings"));
- m_d->m_tabPreferences->setId(idKey);
+ m_d->m_tabPreferences->setId(Constants::GLOBAL_SETTINGS_ID);
m_d->init();
}
@@ -117,7 +114,9 @@ QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
QWidget *w = new QWidget(parent);
m_d->m_page = new Ui::BehaviorSettingsPage;
m_d->m_page->setupUi(w);
- m_d->m_pageTabPreferences = new TabPreferences(QList<IFallbackPreferences *>(), w);
+ m_d->m_pageTabPreferences = new TabPreferences(m_d->m_tabPreferences->fallbacks(), w);
+ m_d->m_pageTabPreferences->setSettings(m_d->m_tabPreferences->settings());
+ m_d->m_pageTabPreferences->setCurrentFallback(m_d->m_tabPreferences->currentFallback());
m_d->m_page->behaviorWidget->setTabPreferences(m_d->m_pageTabPreferences);
settingsToUI();
@@ -133,20 +132,25 @@ void BehaviorSettingsPage::apply()
if (!m_d->m_page) // page was never shown
return;
- TabSettings newTabSettings;
StorageSettings newStorageSettings;
BehaviorSettings newBehaviorSettings;
ExtraEncodingSettings newExtraEncodingSettings;
- settingsFromUI(&newTabSettings, &newStorageSettings, &newBehaviorSettings,
+ settingsFromUI(&newStorageSettings, &newBehaviorSettings,
&newExtraEncodingSettings);
QSettings *s = Core::ICore::instance()->settings();
- if (newTabSettings != m_d->m_tabPreferences->settings()) {
- m_d->m_tabPreferences->setSettings(newTabSettings);
+ if (m_d->m_tabPreferences->settings() != m_d->m_pageTabPreferences->settings()) {
+ m_d->m_tabPreferences->setSettings(m_d->m_pageTabPreferences->settings());
+ if (s)
+ m_d->m_tabPreferences->toSettings(m_d->m_parameters.settingsPrefix, s);
+ }
+
+ if (m_d->m_tabPreferences->currentFallback() != m_d->m_pageTabPreferences->currentFallback()) {
+ m_d->m_tabPreferences->setCurrentFallback(m_d->m_pageTabPreferences->currentFallback());
if (s)
- m_d->m_tabPreferences->settings().toSettings(m_d->m_parameters.settingsPrefix, s);
+ m_d->m_tabPreferences->toSettings(m_d->m_parameters.settingsPrefix, s);
}
if (newStorageSettings != m_d->m_storageSettings) {
@@ -179,12 +183,10 @@ void BehaviorSettingsPage::apply()
}
}
-void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings,
- StorageSettings *storageSettings,
+void BehaviorSettingsPage::settingsFromUI(StorageSettings *storageSettings,
BehaviorSettings *behaviorSettings,
ExtraEncodingSettings *extraEncodingSettings) const
{
- *tabSettings = m_d->m_pageTabPreferences->settings();
m_d->m_page->behaviorWidget->assignedStorageSettings(storageSettings);
m_d->m_page->behaviorWidget->assignedBehaviorSettings(behaviorSettings);
m_d->m_page->behaviorWidget->assignedExtraEncodingSettings(extraEncodingSettings);
@@ -192,7 +194,6 @@ void BehaviorSettingsPage::settingsFromUI(TabSettings *tabSettings,
void BehaviorSettingsPage::settingsToUI()
{
- m_d->m_pageTabPreferences->setSettings(m_d->m_tabPreferences->settings());
m_d->m_page->behaviorWidget->setAssignedStorageSettings(m_d->m_storageSettings);
m_d->m_page->behaviorWidget->setAssignedBehaviorSettings(m_d->m_behaviorSettings);
m_d->m_page->behaviorWidget->setAssignedExtraEncodingSettings(m_d->m_extraEncodingSettings);
diff --git a/src/plugins/texteditor/behaviorsettingspage.h b/src/plugins/texteditor/behaviorsettingspage.h
index 0f7467178b..3c394fe28c 100644
--- a/src/plugins/texteditor/behaviorsettingspage.h
+++ b/src/plugins/texteditor/behaviorsettingspage.h
@@ -83,8 +83,7 @@ signals:
void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &);
private:
- void settingsFromUI(TabSettings *tabSettings,
- StorageSettings *storageSettings,
+ void settingsFromUI(StorageSettings *storageSettings,
BehaviorSettings *behaviorSettings,
ExtraEncodingSettings *extraEncodingSettings) const;
void settingsToUI();
diff --git a/src/plugins/texteditor/fallbackselectorwidget.h b/src/plugins/texteditor/fallbackselectorwidget.h
index 21e141976a..795112b660 100644
--- a/src/plugins/texteditor/fallbackselectorwidget.h
+++ b/src/plugins/texteditor/fallbackselectorwidget.h
@@ -24,7 +24,7 @@ class TEXTEDITOR_EXPORT FallbackSelectorWidget : public QWidget
public:
explicit FallbackSelectorWidget(QWidget *parent = 0);
- void setFallbackPreferences(TextEditor::IFallbackPreferences *tabPreferences);
+ void setFallbackPreferences(TextEditor::IFallbackPreferences *fallbackPreferences);
QString searchKeywords() const;
void setFallbacksVisible(bool on);
diff --git a/src/plugins/texteditor/tabpreferences.cpp b/src/plugins/texteditor/tabpreferences.cpp
index a471830e4e..bb3d439def 100644
--- a/src/plugins/texteditor/tabpreferences.cpp
+++ b/src/plugins/texteditor/tabpreferences.cpp
@@ -1,5 +1,6 @@
#include "tabpreferences.h"
#include "tabsettings.h"
+#include "texteditorconstants.h"
using namespace TextEditor;
@@ -7,6 +8,15 @@ static const char *settingsSuffixKey = "TabPreferences";
static const char *currentFallbackKey = "CurrentFallback";
+static QList<IFallbackPreferences *> toFallbackList(
+ const QList<TabPreferences *> &fallbacks)
+{
+ QList<IFallbackPreferences *> fallbackList;
+ for (int i = 0; i < fallbacks.count(); i++)
+ fallbackList << fallbacks.at(i);
+ return fallbackList;
+}
+
TabPreferences::TabPreferences(
const QList<IFallbackPreferences *> &fallbacks, QObject *parent)
: IFallbackPreferences(fallbacks, parent)
@@ -15,6 +25,14 @@ TabPreferences::TabPreferences(
this, SLOT(slotCurrentValueChanged(QVariant)));
}
+TabPreferences::TabPreferences(
+ const QList<TabPreferences *> &fallbacks, QObject *parent)
+ : IFallbackPreferences(toFallbackList(fallbacks), parent)
+{
+ connect(this, SIGNAL(currentValueChanged(QVariant)),
+ this, SLOT(slotCurrentValueChanged(QVariant)));
+}
+
QVariant TabPreferences::value() const
{
QVariant v;
@@ -83,6 +101,6 @@ void TabPreferences::toMap(const QString &prefix, QVariantMap *map) const
void TabPreferences::fromMap(const QString &prefix, const QVariantMap &map)
{
m_data.fromMap(prefix, map);
- setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), QLatin1String("Global")).toString());
+ setCurrentFallback(map.value(prefix + QLatin1String(currentFallbackKey), Constants::GLOBAL_SETTINGS_ID).toString());
}
diff --git a/src/plugins/texteditor/tabpreferences.h b/src/plugins/texteditor/tabpreferences.h
index 42b63e2cbf..37a2b7b4c4 100644
--- a/src/plugins/texteditor/tabpreferences.h
+++ b/src/plugins/texteditor/tabpreferences.h
@@ -14,12 +14,16 @@ public:
const QList<IFallbackPreferences *> &fallbacks,
QObject *parentObject = 0);
+ explicit TabPreferences(
+ const QList<TabPreferences *> &fallbacks,
+ QObject *parentObject = 0);
+
virtual QVariant value() const;
virtual void setValue(const QVariant &);
TabSettings settings() const;
- // tracks parent hierarchy until currentParentSettings is null
+ // tracks parent fallbacks until null and extracts settings from it
TabSettings currentSettings() const;
virtual void toMap(const QString &prefix, QVariantMap *map) const;
diff --git a/src/plugins/texteditor/tabpreferenceswidget.cpp b/src/plugins/texteditor/tabpreferenceswidget.cpp
index a18edbc2f5..32ed8e1069 100644
--- a/src/plugins/texteditor/tabpreferenceswidget.cpp
+++ b/src/plugins/texteditor/tabpreferenceswidget.cpp
@@ -27,12 +27,13 @@ void TabPreferencesWidget::setTabPreferences(TabPreferences *tabPreferences)
// cleanup old
if (m_tabPreferences) {
- disconnect(m_tabPreferences, SIGNAL(settingsChanged(TabSettings)),
- m_ui->tabSettingsWidget, SLOT(setSettings(TabSettings)));
- disconnect(m_tabPreferences, SIGNAL(currentFallbackChanged(IFallbackPreferences*)),
- this, SLOT(slotCurrentFallbackChanged(IFallbackPreferences*)));
- disconnect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TabSettings)),
- m_tabPreferences, SLOT(setSettings(TabSettings)));
+ disconnect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
+ m_ui->tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
+ disconnect(m_tabPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
+ this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
+ disconnect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
+ m_tabPreferences, SLOT(setSettings(TextEditor::TabSettings)));
+
m_ui->tabSettingsWidget->setEnabled(true);
}
m_tabPreferences = tabPreferences;
@@ -41,14 +42,14 @@ void TabPreferencesWidget::setTabPreferences(TabPreferences *tabPreferences)
if (m_tabPreferences) {
slotCurrentFallbackChanged(m_tabPreferences->currentFallback());
- connect(m_tabPreferences, SIGNAL(settingsChanged(TextEditor::TabSettings)),
+ connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
m_ui->tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings)));
connect(m_tabPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
connect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
m_tabPreferences, SLOT(setSettings(TextEditor::TabSettings)));
- m_ui->tabSettingsWidget->setSettings(m_tabPreferences->settings());
+ m_ui->tabSettingsWidget->setSettings(m_tabPreferences->currentSettings());
}
}
diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h
index 4a8c4592b8..b355235dec 100644
--- a/src/plugins/texteditor/texteditorconstants.h
+++ b/src/plugins/texteditor/texteditorconstants.h
@@ -148,6 +148,8 @@ const char * const TEXT_EDITOR_SNIPPETS_SETTINGS = "F.SnippetsSettings";
const char * const SNIPPET_EDITOR_ID = "TextEditor.SnippetEditor";
const char * const TEXT_SNIPPET_GROUP_ID = "Text";
+const char * const GLOBAL_SETTINGS_ID = "Global";
+
} // namespace Constants
} // namespace TextEditor