From 854eecfc19e13862723220d01d0e3eaaee880563 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Date: Thu, 26 Nov 2009 10:18:51 +0100
Subject: [PATCH] Settings: Introduce ProjectExplorerSettingsWidget
 Task-number: QTCREATORBUG-333

---
 .../projectexplorersettingspage.cpp           | 79 ++++++++++++-------
 .../projectexplorersettingspage.h             | 25 +++++-
 2 files changed, 75 insertions(+), 29 deletions(-)

diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.cpp b/src/plugins/projectexplorer/projectexplorersettingspage.cpp
index 58983a872b0..3a4993a661c 100644
--- a/src/plugins/projectexplorer/projectexplorersettingspage.cpp
+++ b/src/plugins/projectexplorer/projectexplorersettingspage.cpp
@@ -34,11 +34,48 @@
 
 #include <QtGui/QLabel>
 
-using namespace ProjectExplorer;
-using namespace ProjectExplorer::Internal;
+namespace ProjectExplorer {
+namespace Internal {
 
-ProjectExplorerSettingsPage::ProjectExplorerSettingsPage() :
-    m_searchKeywords(QLatin1String("jom"))
+ProjectExplorerSettingsWidget::ProjectExplorerSettingsWidget(QWidget *parent) :
+    QWidget(parent)
+{
+    m_ui.setupUi(this);
+#ifndef Q_OS_WIN
+    setJomVisible(false);
+#endif
+}
+
+void ProjectExplorerSettingsWidget::setJomVisible(bool v)
+{
+    m_ui.jomCheckbox->setVisible(v);
+    m_ui.jomLabel->setVisible(v);
+}
+
+ProjectExplorerSettings ProjectExplorerSettingsWidget::settings() const
+{
+    ProjectExplorerSettings pes;
+    pes.buildBeforeRun = m_ui.buildProjectBeforeRunCheckBox->isChecked();
+    pes.saveBeforeBuild = m_ui.saveAllFilesCheckBox->isChecked();
+    pes.showCompilerOutput = m_ui.showCompileOutputCheckBox->isChecked();
+    pes.useJom = m_ui.jomCheckbox->isChecked();
+    return pes;
+}
+
+void ProjectExplorerSettingsWidget::setSettings(const ProjectExplorerSettings  &pes) const
+{
+    m_ui.buildProjectBeforeRunCheckBox->setChecked(pes.buildBeforeRun);
+    m_ui.saveAllFilesCheckBox->setChecked(pes.saveBeforeBuild);
+    m_ui.showCompileOutputCheckBox->setChecked(pes.showCompilerOutput);
+    m_ui.jomCheckbox->setChecked(pes.useJom);
+}
+
+QString ProjectExplorerSettingsWidget::searchKeywords() const
+{
+    return QLatin1String("jom");
+}
+
+ProjectExplorerSettingsPage::ProjectExplorerSettingsPage()
 {
 }
 
@@ -64,33 +101,17 @@ QString ProjectExplorerSettingsPage::trCategory() const
 
 QWidget *ProjectExplorerSettingsPage::createPage(QWidget *parent)
 {
-    QWidget *w = new QWidget(parent);
-    m_ui.setupUi(w);
-    ProjectExplorerSettings pes = ProjectExplorerPlugin::instance()->projectExplorerSettings();
-    m_ui.buildProjectBeforeRunCheckBox->setChecked(pes.buildBeforeRun);
-    m_ui.saveAllFilesCheckBox->setChecked(pes.saveBeforeBuild);
-    m_ui.showCompileOutputCheckBox->setChecked(pes.showCompilerOutput);
-#ifdef Q_OS_WIN
-    m_ui.jomCheckbox->setChecked(pes.useJom);
-#else
-    m_ui.jomCheckbox->setVisible(false);
-    m_ui.jomLabel->setVisible(false);
-#endif
-    return w;
+    m_widget = new ProjectExplorerSettingsWidget(parent);
+    m_widget->setSettings(ProjectExplorerPlugin::instance()->projectExplorerSettings());
+    if (m_searchKeywords.isEmpty())
+        m_searchKeywords = m_widget->searchKeywords();
+    return m_widget;
 }
 
 void ProjectExplorerSettingsPage::apply()
 {
-    ProjectExplorerSettings pes;
-    pes.buildBeforeRun = m_ui.buildProjectBeforeRunCheckBox->isChecked();
-    pes.saveBeforeBuild = m_ui.saveAllFilesCheckBox->isChecked();
-    pes.showCompilerOutput = m_ui.showCompileOutputCheckBox->isChecked();
-#ifdef Q_OS_WIN
-    pes.useJom = m_ui.jomCheckbox->isChecked();
-#else
-    pes.useJom = false;
-#endif
-    ProjectExplorerPlugin::instance()->setProjectExplorerSettings(pes);
+    if (m_widget)
+        ProjectExplorerPlugin::instance()->setProjectExplorerSettings(m_widget->settings());
 }
 
 void ProjectExplorerSettingsPage::finish()
@@ -102,3 +123,7 @@ bool ProjectExplorerSettingsPage::matches(const QString &s) const
 {
     return m_searchKeywords.contains(s, Qt::CaseInsensitive);
 }
+
+}
+}
+
diff --git a/src/plugins/projectexplorer/projectexplorersettingspage.h b/src/plugins/projectexplorer/projectexplorersettingspage.h
index efd28fefa7c..b70ae1eccd8 100644
--- a/src/plugins/projectexplorer/projectexplorersettingspage.h
+++ b/src/plugins/projectexplorer/projectexplorersettingspage.h
@@ -33,9 +33,30 @@
 #include <coreplugin/dialogs/ioptionspage.h>
 #include "ui_projectexplorersettingspage.h"
 
+#include <QtCore/QPointer>
+
 namespace ProjectExplorer {
 namespace Internal {
 
+struct ProjectExplorerSettings;
+
+class ProjectExplorerSettingsWidget : public QWidget {
+    Q_OBJECT
+public:
+    explicit ProjectExplorerSettingsWidget(QWidget *parent = 0);
+
+    ProjectExplorerSettings settings() const;
+    void setSettings(const ProjectExplorerSettings  &s) const;
+
+    QString searchKeywords() const;
+
+
+private:
+    void setJomVisible(bool);
+
+    Ui::ProjectExplorerSettingsPageUi m_ui;
+};
+
 class ProjectExplorerSettingsPage : public Core::IOptionsPage
 {
     Q_OBJECT
@@ -53,8 +74,8 @@ public:
     virtual bool matches(const QString &s) const;
 
 private:
-    const QString m_searchKeywords;
-    Ui::ProjectExplorerSettingsPageUi m_ui;
+    QString m_searchKeywords;
+    QPointer<ProjectExplorerSettingsWidget> m_widget;
 };
 
 } // Internal
-- 
GitLab