OSDN Git Service

Avoid a lot of updates when CppCodeStyleSettingsPage is created
authorcon <qtc-committer@nokia.com>
Tue, 21 Jun 2011 16:03:44 +0000 (18:03 +0200)
committerEike Ziller <eike.ziller@nokia.com>
Wed, 22 Jun 2011 08:08:39 +0000 (10:08 +0200)
This helps to reduce the lag when typing in the preference's filter
edit.

Task-number: QTCREATORBUG-5065
Change-Id: I26634a47b21df1402a53037864bb0c334eba8078
Reviewed-on: http://codereview.qt.nokia.com/572
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
src/plugins/cpptools/cppcodestylesettingsfactory.cpp
src/plugins/cpptools/cppcodestylesettingspage.cpp
src/plugins/cpptools/cppcodestylesettingspage.h

index 9385627..b794ace 100644 (file)
@@ -38,8 +38,7 @@ QWidget *CppCodeStylePreferencesFactory::createEditor(TextEditor::IFallbackPrefe
         return 0;
     Internal::CppCodeStylePreferencesWidget *widget = new Internal::CppCodeStylePreferencesWidget(parent);
     widget->layout()->setMargin(0);
-    widget->setCppCodeStylePreferences(cppPreferences);
-    widget->setTabPreferences(tabPreferences);
+    widget->setPreferences(cppPreferences, tabPreferences);
     return widget;
 }
 
index 8087545..f1330dc 100644 (file)
@@ -179,7 +179,8 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent)
     : QWidget(parent),
       m_tabPreferences(0),
       m_cppCodeStylePreferences(0),
-      m_ui(new Ui::CppCodeStyleSettingsPage)
+      m_ui(new Ui::CppCodeStyleSettingsPage),
+      m_blockUpdates(false)
 {
     m_ui->setupUi(this);
     m_ui->categoryTab->setProperty("_q_custom_style_disabled", true);
@@ -242,19 +243,18 @@ CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget()
     delete m_ui;
 }
 
-void CppCodeStylePreferencesWidget::setTabPreferences(TextEditor::TabPreferences *preferences)
+void CppCodeStylePreferencesWidget::setPreferences(CppTools::CppCodeStylePreferences *codeStylePreferences,
+                                                   TextEditor::TabPreferences *tabPreferences)
 {
-    m_tabPreferences = preferences;
-    m_ui->tabPreferencesWidget->setTabPreferences(preferences);
+    // tab preferences
+    m_tabPreferences = tabPreferences;
+    m_ui->tabPreferencesWidget->setTabPreferences(tabPreferences);
     connect(m_tabPreferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)),
             this, SLOT(slotSettingsChanged()));
-    updatePreview();
-}
 
-void CppCodeStylePreferencesWidget::setCppCodeStylePreferences(CppCodeStylePreferences *preferences)
-{
-    m_cppCodeStylePreferences = preferences;
-    m_ui->fallbackWidget->setFallbackPreferences(preferences);
+    // 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)),
@@ -264,11 +264,12 @@ void CppCodeStylePreferencesWidget::setCppCodeStylePreferences(CppCodeStylePrefe
     connect(this, SIGNAL(cppCodeStyleSettingsChanged(CppTools::CppCodeStyleSettings)),
             m_cppCodeStylePreferences, SLOT(setSettings(CppTools::CppCodeStyleSettings)));
 
-    setCppCodeStyleSettings(m_cppCodeStylePreferences->settings());
-    slotCurrentFallbackChanged(m_cppCodeStylePreferences->currentFallback());
+    setCppCodeStyleSettings(m_cppCodeStylePreferences->settings(), false);
+    slotCurrentFallbackChanged(m_cppCodeStylePreferences->currentFallback(), false);
 
     connect(m_cppCodeStylePreferences, SIGNAL(currentSettingsChanged(CppTools::CppCodeStyleSettings)),
             this, SLOT(slotSettingsChanged()));
+
     updatePreview();
 }
 
@@ -296,9 +297,10 @@ CppCodeStyleSettings CppCodeStylePreferencesWidget::cppCodeStyleSettings() const
     return set;
 }
 
-void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSettings &s)
+void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSettings &s, bool preview)
 {
-    const bool wasBlocked = blockSignals(true);
+    const bool wasBlocked = m_blockUpdates;
+    m_blockUpdates = true;
     m_ui->indentBlockBraces->setChecked(s.indentBlockBraces);
     m_ui->indentBlockBody->setChecked(s.indentBlockBody);
     m_ui->indentClassBraces->setChecked(s.indentClassBraces);
@@ -315,19 +317,19 @@ void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSe
     m_ui->indentCaseBreak->setChecked(s.indentControlFlowRelativeToSwitchLabels);
     m_ui->extraPaddingConditions->setChecked(s.extraPaddingForConditionsIfConfusingAlign);
     m_ui->alignAssignments->setChecked(s.alignAssignments);
-    blockSignals(wasBlocked);
-
-    updatePreview();
+    m_blockUpdates = wasBlocked;
+    if (preview)
+        updatePreview();
 }
 
-void CppCodeStylePreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback)
+void CppCodeStylePreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback, bool preview)
 {
     m_ui->contentGroupBox->setEnabled(!fallback);
     m_ui->bracesGroupBox->setEnabled(!fallback);
     m_ui->switchGroupBox->setEnabled(!fallback);
     m_ui->alignmentGroupBox->setEnabled(!fallback);
-
-    updatePreview();
+    if (preview)
+        updatePreview();
 }
 
 QString CppCodeStylePreferencesWidget::searchKeywords() const
@@ -366,6 +368,8 @@ QString CppCodeStylePreferencesWidget::searchKeywords() const
 
 void CppCodeStylePreferencesWidget::slotCppCodeStyleSettingsChanged()
 {
+    if (m_blockUpdates)
+        return;
     emit cppCodeStyleSettingsChanged(cppCodeStyleSettings());
     updatePreview();
 }
@@ -484,14 +488,13 @@ QWidget *CppCodeStyleSettingsPage::createPage(QWidget *parent)
     m_pageTabPreferences = new TextEditor::TabPreferences(originalTabPreferences->fallbacks(), m_widget);
     m_pageTabPreferences->setSettings(originalTabPreferences->settings());
     m_pageTabPreferences->setCurrentFallback(originalTabPreferences->currentFallback());
-    m_widget->setTabPreferences(m_pageTabPreferences);
 
     CppCodeStylePreferences *originalCodeStylePreferences
             = CppToolsSettings::instance()->cppCodeStylePreferences();
     m_pageCppCodeStylePreferences = new CppCodeStylePreferences(originalCodeStylePreferences->fallbacks(), m_widget);
     m_pageCppCodeStylePreferences->setSettings(originalCodeStylePreferences->settings());
     m_pageCppCodeStylePreferences->setCurrentFallback(originalCodeStylePreferences->currentFallback());
-    m_widget->setCppCodeStylePreferences(m_pageCppCodeStylePreferences);
+    m_widget->setPreferences(m_pageCppCodeStylePreferences, m_pageTabPreferences);
 
     if (m_searchKeywords.isEmpty())
         m_searchKeywords = m_widget->searchKeywords();
index b332810..5a5326e 100644 (file)
@@ -38,8 +38,8 @@ public:
     explicit CppCodeStylePreferencesWidget(QWidget *parent = 0);
     virtual ~CppCodeStylePreferencesWidget();
 
-    void setTabPreferences(TextEditor::TabPreferences *tabPreferences);
-    void setCppCodeStylePreferences(CppTools::CppCodeStylePreferences *codeStylePreferences);
+    void setPreferences(CppTools::CppCodeStylePreferences *codeStylePreferences,
+                        TextEditor::TabPreferences *tabPreferences);
 
     QString searchKeywords() const;
 
@@ -49,8 +49,8 @@ private slots:
     void slotCppCodeStyleSettingsChanged();
     void slotSettingsChanged();
     void updatePreview();
-    void setCppCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings);
-    void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *);
+    void setCppCodeStyleSettings(const CppTools::CppCodeStyleSettings &settings, bool preview = true);
+    void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *, bool preview = true);
 
 signals:
     void cppCodeStyleSettingsChanged(const CppTools::CppCodeStyleSettings &);
@@ -61,6 +61,7 @@ private:
     CppCodeStylePreferences *m_cppCodeStylePreferences;
     Ui::CppCodeStyleSettingsPage *m_ui;
     QList<TextEditor::SnippetEditorWidget *> m_previews;
+    bool m_blockUpdates;
 };