Commit c61652d0 authored by Jarek Kobus's avatar Jarek Kobus Committed by Jarek Kobus
Browse files

Small refactor

Change-Id: I2988ce1c2a73798abccf690a3ed5d4e3a92c91a2
Reviewed-on: http://codereview.qt.nokia.com/517

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent dcf73459
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
......
#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());
}
......@@ -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;
......
......@@ -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());
}
}
......
......@@ -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
......
Supports Markdown
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