Commit c98e7c2b authored by Jarek Kobus's avatar Jarek Kobus Committed by Jarek Kobus

Small refactor, preparation for built-in settings

Change-Id: I91de7a01aba37f41398df7b06dbe5af868094379
Reviewed-on: http://codereview.qt.nokia.com/615Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@nokia.com>
parent 12bd8803
......@@ -250,25 +250,20 @@ void CppCodeStylePreferencesWidget::setPreferences(CppTools::CppCodeStylePrefere
m_tabPreferences = tabPreferences;
m_ui->tabPreferencesWidget->setTabPreferences(tabPreferences);
connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
this, SLOT(slotSettingsChanged()));
this, SLOT(updatePreview()));
// code preferences
m_cppCodeStylePreferences = codeStylePreferences;
m_ui->fallbackWidget->setFallbackPreferences(codeStylePreferences);
m_ui->fallbackContainer->setVisible(!m_ui->fallbackWidget->isHidden());
connect(m_cppCodeStylePreferences, SIGNAL(settingsChanged(CppTools::CppCodeStyleSettings)),
connect(m_cppCodeStylePreferences, SIGNAL(currentSettingsChanged(CppTools::CppCodeStyleSettings)),
this, SLOT(setCppCodeStyleSettings(CppTools::CppCodeStyleSettings)));
connect(m_cppCodeStylePreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*)));
connect(this, SIGNAL(cppCodeStyleSettingsChanged(CppTools::CppCodeStyleSettings)),
m_cppCodeStylePreferences, SLOT(setSettings(CppTools::CppCodeStyleSettings)));
connect(m_cppCodeStylePreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
setCppCodeStyleSettings(m_cppCodeStylePreferences->settings(), false);
slotCurrentFallbackChanged(m_cppCodeStylePreferences->currentFallback(), false);
connect(m_cppCodeStylePreferences, SIGNAL(currentSettingsChanged(CppTools::CppCodeStyleSettings)),
this, SLOT(slotSettingsChanged()));
slotCurrentPreferencesChanged(m_cppCodeStylePreferences->currentPreferences(), false);
updatePreview();
}
......@@ -322,12 +317,13 @@ void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSe
updatePreview();
}
void CppCodeStylePreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback, bool preview)
void CppCodeStylePreferencesWidget::slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences, bool preview)
{
m_ui->contentGroupBox->setEnabled(!fallback);
m_ui->bracesGroupBox->setEnabled(!fallback);
m_ui->switchGroupBox->setEnabled(!fallback);
m_ui->alignmentGroupBox->setEnabled(!fallback);
const bool enable = !preferences->isReadOnly() && m_cppCodeStylePreferences->isFallbackEnabled(m_cppCodeStylePreferences->currentFallback());
m_ui->contentGroupBox->setEnabled(enable);
m_ui->bracesGroupBox->setEnabled(enable);
m_ui->switchGroupBox->setEnabled(enable);
m_ui->alignmentGroupBox->setEnabled(enable);
if (preview)
updatePreview();
}
......@@ -370,12 +366,13 @@ void CppCodeStylePreferencesWidget::slotCppCodeStyleSettingsChanged()
{
if (m_blockUpdates)
return;
emit cppCodeStyleSettingsChanged(cppCodeStyleSettings());
updatePreview();
}
void CppCodeStylePreferencesWidget::slotSettingsChanged()
{
if (m_cppCodeStylePreferences) {
CppCodeStylePreferences *current = qobject_cast<CppCodeStylePreferences *>(m_cppCodeStylePreferences->currentPreferences());
if (current)
current->setSettings(cppCodeStyleSettings());
}
updatePreview();
}
......@@ -485,13 +482,23 @@ QWidget *CppCodeStyleSettingsPage::createPage(QWidget *parent)
TextEditor::TabPreferences *originalTabPreferences
= CppToolsSettings::instance()->tabPreferences();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabPreferences->fallbacks(), m_widget);
QList<TextEditor::IFallbackPreferences *> originalTabFallbacks = originalTabPreferences->fallbacks();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabFallbacks, m_widget);
for (int i = 0; i < originalTabFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalTabFallbacks.at(i);
m_pageTabPreferences->setFallbackEnabled(fallback, originalTabPreferences->isFallbackEnabled(fallback));
}
m_pageTabPreferences->setSettings(originalTabPreferences->settings());
m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
CppCodeStylePreferences *originalCodeStylePreferences
= CppToolsSettings::instance()->cppCodeStylePreferences();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(originalCodeStylePreferences->fallbacks(), m_widget);
QList<TextEditor::IFallbackPreferences *> originalCodeStyleFallbacks = originalCodeStylePreferences->fallbacks();
m_pageCppCodeStylePreferences = new CppCodeStylePreferences(originalCodeStyleFallbacks, m_widget);
for (int i = 0; i < originalCodeStyleFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalCodeStyleFallbacks.at(i);
m_pageCppCodeStylePreferences->setFallbackEnabled(fallback, originalCodeStylePreferences->isFallbackEnabled(fallback));
}
m_pageCppCodeStylePreferences->setSettings(originalCodeStylePreferences->settings());
m_pageCppCodeStylePreferences->setCurrentFallback(originalCodeStylePreferences->currentFallback());
m_widget->setPreferences(m_pageCppCodeStylePreferences, m_pageTabPreferences);
......
......@@ -47,13 +47,10 @@ private slots:
void decorateEditors(const TextEditor::FontSettings &fontSettings);
void setVisualizeWhitespace(bool on);
void slotCppCodeStyleSettingsChanged();
void slotSettingsChanged();
void updatePreview();
void setCppCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings, bool preview = true);
void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *, bool preview = true);
void slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *, bool preview = true);
signals:
void cppCodeStyleSettingsChanged(const CppTools::CppCodeStyleSettings &);
private:
CppCodeStyleSettings cppCodeStyleSettings() const;
......
......@@ -37,10 +37,12 @@ CppToolsSettings::CppToolsSettings(QObject *parent)
if (const QSettings *s = Core::ICore::instance()->settings()) {
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
TextEditor::TabPreferences *tabPrefs = textEditorSettings->tabPreferences();
m_d->m_tabPreferences
= new TextEditor::TabPreferences(QList<TextEditor::IFallbackPreferences *>()
<< textEditorSettings->tabPreferences(), this);
m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences());
<< tabPrefs, this);
m_d->m_tabPreferences->setCurrentFallback(tabPrefs);
m_d->m_tabPreferences->setFallbackEnabled(tabPrefs, false);
m_d->m_tabPreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s);
m_d->m_tabPreferences->setDisplayName(tr("Global C++", "Settings"));
m_d->m_tabPreferences->setId(idKey);
......
......@@ -95,6 +95,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
QList<TabPreferences *> tabFallbacks;
tabFallbacks << textEditorSettings->tabPreferences();
m_d->m_tabPreferences = new TabPreferences(tabFallbacks, this);
m_d->m_tabPreferences->setFallbackEnabled(textEditorSettings->tabPreferences(), false);
m_d->m_tabPreferences->setDisplayName(tr("Project", "Settings"));
m_d->m_tabPreferences->setId(kId);
......@@ -108,11 +109,14 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
itTab.next();
const QString languageId = itTab.key();
TabPreferences *originalPreferences = itTab.value();
QList<IFallbackPreferences *> fallbacks;
fallbacks << originalPreferences->fallbacks();
fallbacks << originalPreferences;
fallbacks << tabPreferences();
TabPreferences *preferences = new TabPreferences(
QList<IFallbackPreferences *>()
<< originalPreferences->fallbacks()
<< originalPreferences
<< tabPreferences(), this);
fallbacks, this);
for (int i = 0; i < fallbacks.count(); i++)
preferences->setFallbackEnabled(fallbacks.at(i), false);
preferences->setId(languageId + QLatin1String("Project"));
preferences->setCurrentFallback(originalPreferences);
m_d->m_languageTabPreferences.insert(languageId, preferences);
......@@ -127,6 +131,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate)
ICodeStylePreferencesFactory *factory = manager->factory(languageId);
IFallbackPreferences *preferences = factory->createPreferences(
QList<IFallbackPreferences *>() << originalPreferences);
preferences->setFallbackEnabled(originalPreferences, false);
preferences->setId(languageId + QLatin1String("Project"));
preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName()));
preferences->setCurrentFallback(originalPreferences);
......
......@@ -161,7 +161,12 @@ QWidget *QmlJSCodeStyleSettingsPage::createPage(QWidget *parent)
TextEditor::TabPreferences *originalTabPreferences
= QmlJSToolsSettings::instance()->tabPreferences();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabPreferences->fallbacks(), m_widget);
QList<TextEditor::IFallbackPreferences *> originalTabFallbacks = originalTabPreferences->fallbacks();
m_pageTabPreferences = new TextEditor::TabPreferences(originalTabFallbacks, m_widget);
for (int i = 0; i < originalTabFallbacks.count(); i++) {
TextEditor::IFallbackPreferences *fallback = originalTabFallbacks.at(i);
m_pageTabPreferences->setFallbackEnabled(fallback, originalTabPreferences->isFallbackEnabled(fallback));
}
m_pageTabPreferences->setSettings(originalTabPreferences->settings());
m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
m_widget->setTabPreferences(m_pageTabPreferences);
......
......@@ -35,10 +35,12 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent)
if (const QSettings *s = Core::ICore::instance()->settings()) {
TextEditor::TextEditorSettings *textEditorSettings = TextEditor::TextEditorSettings::instance();
TextEditor::TabPreferences *tabPrefs = textEditorSettings->tabPreferences();
m_d->m_tabPreferences
= new TextEditor::TabPreferences(QList<TextEditor::IFallbackPreferences *>()
<< textEditorSettings->tabPreferences(), this);
m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences());
<< tabPrefs, this);
m_d->m_tabPreferences->setCurrentFallback(tabPrefs);
m_d->m_tabPreferences->setFallbackEnabled(tabPrefs, false);
m_d->m_tabPreferences->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s);
m_d->m_tabPreferences->setDisplayName(tr("Global Qt Quick", "Settings"));
m_d->m_tabPreferences->setId(idKey);
......
......@@ -14,14 +14,17 @@ class IFallbackPreferencesPrivate
{
public:
IFallbackPreferencesPrivate()
: m_currentFallback(0)
: m_currentFallback(0),
m_readOnly(false)
{}
QList<IFallbackPreferences *> m_fallbacks;
QMap<QString, IFallbackPreferences *> m_idToFallback;
QMap<IFallbackPreferences *, bool> m_fallbackToEnabled;
IFallbackPreferences *m_currentFallback;
QString m_id;
QString m_displayName;
bool m_readOnly;
};
}
......@@ -65,6 +68,35 @@ void IFallbackPreferences::setDisplayName(const QString &name)
d->m_displayName = name;
}
bool IFallbackPreferences::isReadOnly() const
{
return d->m_readOnly;
}
void IFallbackPreferences::setReadOnly(bool on)
{
d->m_readOnly = on;
}
bool IFallbackPreferences::isFallbackEnabled(IFallbackPreferences *fallback) const
{
return d->m_fallbackToEnabled.value(fallback, true);
}
void IFallbackPreferences::setFallbackEnabled(IFallbackPreferences *fallback, bool on)
{
if (fallback && !d->m_fallbacks.contains(fallback)) {
// warning
return;
}
d->m_fallbackToEnabled[fallback] = on;
}
IFallbackPreferences *IFallbackPreferences::clone() const
{
return 0;
}
QVariant IFallbackPreferences::currentValue() const
{
return currentPreferences()->value();
......@@ -100,13 +132,18 @@ void IFallbackPreferences::setCurrentFallback(IFallbackPreferences *fallback)
if (d->m_currentFallback) {
disconnect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
disconnect(d->m_currentFallback, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)));
}
d->m_currentFallback = fallback;
if (d->m_currentFallback) {
connect(d->m_currentFallback, SIGNAL(currentValueChanged(QVariant)),
this, SIGNAL(currentValueChanged(QVariant)));
connect(d->m_currentFallback, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)),
this, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences *)));
}
emit currentFallbackChanged(d->m_currentFallback);
emit currentPreferencesChanged(currentPreferences());
emit currentValueChanged(currentValue());
}
......
......@@ -21,6 +21,7 @@ class TabSettings;
class TEXTEDITOR_EXPORT IFallbackPreferences : public QObject
{
Q_OBJECT
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
public:
explicit IFallbackPreferences(const QList<IFallbackPreferences *> &fallbacks, QObject *parentObject = 0);
virtual ~IFallbackPreferences();
......@@ -31,6 +32,14 @@ public:
QString displayName() const;
void setDisplayName(const QString &name);
bool isReadOnly() const;
void setReadOnly(bool on);
bool isFallbackEnabled(IFallbackPreferences *fallback) const;
void setFallbackEnabled(IFallbackPreferences *fallback, bool on);
virtual IFallbackPreferences *clone() const;
virtual QVariant value() const = 0;
virtual void setValue(const QVariant &) = 0;
......@@ -56,6 +65,7 @@ signals:
void valueChanged(const QVariant &);
void currentValueChanged(const QVariant &);
void currentFallbackChanged(TextEditor::IFallbackPreferences *currentFallback);
void currentPreferencesChanged(TextEditor::IFallbackPreferences *currentPreferences);
protected:
virtual QString settingsSuffix() const = 0;
......
......@@ -13,6 +13,7 @@ TabPreferencesWidget::TabPreferencesWidget(QWidget *parent) :
{
m_ui->setupUi(this);
m_ui->fallbackWidget->setLabelText(tr("Tab settings:"));
m_ui->tabSettingsWidget->setEnabled(false);
}
TabPreferencesWidget::~TabPreferencesWidget()
......@@ -29,33 +30,44 @@ void TabPreferencesWidget::setTabPreferences(TabPreferences *tabPreferences)
if (m_tabPreferences) {
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_tabPreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
disconnect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
m_tabPreferences, SLOT(setSettings(TextEditor::TabSettings)));
m_ui->tabSettingsWidget->setEnabled(true);
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
}
m_tabPreferences = tabPreferences;
m_ui->fallbackWidget->setFallbackPreferences(tabPreferences);
// fillup new
if (m_tabPreferences) {
slotCurrentFallbackChanged(m_tabPreferences->currentFallback());
slotCurrentPreferencesChanged(m_tabPreferences->currentPreferences());
m_ui->tabSettingsWidget->setSettings(m_tabPreferences->currentSettings());
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_tabPreferences, SIGNAL(currentPreferencesChanged(TextEditor::IFallbackPreferences*)),
this, SLOT(slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences*)));
connect(m_ui->tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)),
m_tabPreferences, SLOT(setSettings(TextEditor::TabSettings)));
m_ui->tabSettingsWidget->setSettings(m_tabPreferences->currentSettings());
this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings)));
} else {
m_ui->tabSettingsWidget->setEnabled(false);
}
}
void TabPreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
void TabPreferencesWidget::slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences)
{
m_ui->tabSettingsWidget->setEnabled(!fallback);
m_ui->tabSettingsWidget->setEnabled(!preferences->isReadOnly() && m_tabPreferences->isFallbackEnabled(m_tabPreferences->currentFallback()));
}
void TabPreferencesWidget::slotTabSettingsChanged(const TextEditor::TabSettings &settings)
{
if (!m_tabPreferences)
return;
TabPreferences *current = qobject_cast<TabPreferences *>(m_tabPreferences->currentPreferences());
if (!current)
return;
current->setSettings(settings);
}
QString TabPreferencesWidget::searchKeywords() const
......
......@@ -9,6 +9,7 @@
namespace TextEditor {
class TabSettings;
class TabPreferences;
class IFallbackPreferences;
......@@ -34,7 +35,8 @@ protected:
void changeEvent(QEvent *e);
private slots:
void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback);
void slotCurrentPreferencesChanged(TextEditor::IFallbackPreferences *preferences);
void slotTabSettingsChanged(const TextEditor::TabSettings &settings);
private:
Ui::TabPreferencesWidget *m_ui;
......
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