forked from qt-creator/qt-creator
		
	Small refactor, preparation for built-in settings
Change-Id: I91de7a01aba37f41398df7b06dbe5af868094379 Reviewed-on: http://codereview.qt.nokia.com/615 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user