From 9454fe56896c62769daec394ae60dea3c37a96ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lindeijer?= <thorbjorn.lindeijer@nokia.com>
Date: Mon, 12 Apr 2010 15:53:17 +0200
Subject: [PATCH] Create a single parent options page for the Text Editor
 category

Trying to clean up a little.
---
 .../cpptools/completionsettingspage.cpp       | 16 ------
 src/plugins/cpptools/completionsettingspage.h |  7 +--
 .../texteditor/behaviorsettingspage.cpp       | 17 +-----
 src/plugins/texteditor/behaviorsettingspage.h | 15 +----
 .../texteditor/displaysettingspage.cpp        | 17 +-----
 src/plugins/texteditor/displaysettingspage.h  | 12 +---
 src/plugins/texteditor/fontsettingspage.cpp   | 33 ++---------
 src/plugins/texteditor/fontsettingspage.h     |  9 +--
 src/plugins/texteditor/texteditor.pro         |  6 +-
 .../texteditor/texteditoroptionspage.cpp      | 56 ++++++++++++++++++
 .../texteditor/texteditoroptionspage.h        | 57 +++++++++++++++++++
 src/plugins/texteditor/texteditorsettings.cpp | 12 +---
 12 files changed, 134 insertions(+), 123 deletions(-)
 create mode 100644 src/plugins/texteditor/texteditoroptionspage.cpp
 create mode 100644 src/plugins/texteditor/texteditoroptionspage.h

diff --git a/src/plugins/cpptools/completionsettingspage.cpp b/src/plugins/cpptools/completionsettingspage.cpp
index 8a3b93a0613..e001313e10a 100644
--- a/src/plugins/cpptools/completionsettingspage.cpp
+++ b/src/plugins/cpptools/completionsettingspage.cpp
@@ -31,7 +31,6 @@
 #include "ui_completionsettingspage.h"
 
 #include <coreplugin/icore.h>
-#include <texteditor/texteditorconstants.h>
 #include <extensionsystem/pluginmanager.h>
 
 #include <QtCore/QTextStream>
@@ -60,21 +59,6 @@ QString CompletionSettingsPage::displayName() const
     return tr("Completion");
 }
 
-QString CompletionSettingsPage::category() const
-{
-    return QLatin1String(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
-}
-
-QString CompletionSettingsPage::displayCategory() const
-{
-    return QCoreApplication::translate("Text Editor", TextEditor::Constants::TEXT_EDITOR_SETTINGS_TR_CATEGORY);
-}
-
-QIcon CompletionSettingsPage::categoryIcon() const
-{
-    return QIcon(QLatin1String(TextEditor::Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON));
-}
-
 QWidget *CompletionSettingsPage::createPage(QWidget *parent)
 {
     QWidget *w = new QWidget(parent);
diff --git a/src/plugins/cpptools/completionsettingspage.h b/src/plugins/cpptools/completionsettingspage.h
index ab41757fe5e..fe9b8477c39 100644
--- a/src/plugins/cpptools/completionsettingspage.h
+++ b/src/plugins/cpptools/completionsettingspage.h
@@ -30,7 +30,7 @@
 #ifndef COMPLETIONSETTINGSPAGE_H
 #define COMPLETIONSETTINGSPAGE_H
 
-#include <coreplugin/dialogs/ioptionspage.h>
+#include <texteditor/texteditoroptionspage.h>
 
 #include "cppcodecompletion.h"
 
@@ -41,7 +41,7 @@ QT_END_NAMESPACE
 namespace CppTools {
 namespace Internal {
 
-class CompletionSettingsPage : public Core::IOptionsPage
+class CompletionSettingsPage : public TextEditor::TextEditorOptionsPage
 {
     Q_OBJECT
 
@@ -51,9 +51,6 @@ public:
 
     QString id() const;
     QString displayName() const;
-    QString category() const;
-    QString displayCategory() const;
-    QIcon categoryIcon() const;
 
     QWidget *createPage(QWidget *parent);
     void apply();
diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp
index caaebfd1fcc..9595415fb09 100644
--- a/src/plugins/texteditor/behaviorsettingspage.cpp
+++ b/src/plugins/texteditor/behaviorsettingspage.cpp
@@ -68,7 +68,7 @@ BehaviorSettingsPage::BehaviorSettingsPagePrivate::BehaviorSettingsPagePrivate
 
 BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters &p,
                                            QObject *parent)
-  : Core::IOptionsPage(parent),
+  : TextEditorOptionsPage(parent),
     m_d(new BehaviorSettingsPagePrivate(p))
 {
 }
@@ -88,21 +88,6 @@ QString BehaviorSettingsPage::displayName() const
     return m_d->m_parameters.displayName;
 }
 
-QString BehaviorSettingsPage::category() const
-{
-    return m_d->m_parameters.category;
-}
-
-QString BehaviorSettingsPage::displayCategory() const
-{
-    return m_d->m_parameters.displayCategory;
-}
-
-QIcon BehaviorSettingsPage::categoryIcon() const
-{
-    return m_d->m_parameters.categoryIcon;
-}
-
 QWidget *BehaviorSettingsPage::createPage(QWidget *parent)
 {
     QWidget *w = new QWidget(parent);
diff --git a/src/plugins/texteditor/behaviorsettingspage.h b/src/plugins/texteditor/behaviorsettingspage.h
index 71c9c6a5ec6..8d2040bc684 100644
--- a/src/plugins/texteditor/behaviorsettingspage.h
+++ b/src/plugins/texteditor/behaviorsettingspage.h
@@ -32,9 +32,7 @@
 
 #include "texteditor_global.h"
 
-#include <coreplugin/dialogs/ioptionspage.h>
-
-#include <QtCore/QObject>
+#include "texteditoroptionspage.h"
 
 namespace TextEditor {
 
@@ -46,13 +44,10 @@ struct BehaviorSettingsPageParameters
 {
     QString id;
     QString displayName;
-    QString category;
-    QString displayCategory;
-    QIcon categoryIcon;
     QString settingsPrefix;
 };
 
-class BehaviorSettingsPage : public Core::IOptionsPage
+class BehaviorSettingsPage : public TextEditorOptionsPage
 {
     Q_OBJECT
 
@@ -63,20 +58,16 @@ public:
     // IOptionsPage
     QString id() const;
     QString displayName() const;
-    QString category() const;
-    QString displayCategory() const;
-    QIcon categoryIcon() const;
 
     QWidget *createPage(QWidget *parent);
     void apply();
     void finish() { }
+    bool matches(const QString &s) const;
 
     const TabSettings &tabSettings() const;
     const StorageSettings &storageSettings() const;
     const BehaviorSettings &behaviorSettings() const;
 
-    virtual bool matches(const QString &s) const;
-
 signals:
     void tabSettingsChanged(const TextEditor::TabSettings &);
     void storageSettingsChanged(const TextEditor::StorageSettings &);
diff --git a/src/plugins/texteditor/displaysettingspage.cpp b/src/plugins/texteditor/displaysettingspage.cpp
index 86551c337d3..3ae03513c94 100644
--- a/src/plugins/texteditor/displaysettingspage.cpp
+++ b/src/plugins/texteditor/displaysettingspage.cpp
@@ -59,7 +59,7 @@ DisplaySettingsPage::DisplaySettingsPagePrivate::DisplaySettingsPagePrivate
 
 DisplaySettingsPage::DisplaySettingsPage(const DisplaySettingsPageParameters &p,
                                          QObject *parent)
-  : Core::IOptionsPage(parent),
+  : TextEditorOptionsPage(parent),
     m_d(new DisplaySettingsPagePrivate(p))
 {
 }
@@ -79,21 +79,6 @@ QString DisplaySettingsPage::displayName() const
     return m_d->m_parameters.displayName;
 }
 
-QString DisplaySettingsPage::category() const
-{
-    return m_d->m_parameters.category;
-}
-
-QString DisplaySettingsPage::displayCategory() const
-{
-    return m_d->m_parameters.displayCategory;
-}
-
-QIcon DisplaySettingsPage::categoryIcon() const
-{
-    return m_d->m_parameters.categoryIcon;
-}
-
 QWidget *DisplaySettingsPage::createPage(QWidget *parent)
 {
     QWidget *w = new QWidget(parent);
diff --git a/src/plugins/texteditor/displaysettingspage.h b/src/plugins/texteditor/displaysettingspage.h
index dce289ad10b..2ba246a042a 100644
--- a/src/plugins/texteditor/displaysettingspage.h
+++ b/src/plugins/texteditor/displaysettingspage.h
@@ -32,9 +32,7 @@
 
 #include "texteditor_global.h"
 
-#include <coreplugin/dialogs/ioptionspage.h>
-
-#include <QtCore/QObject>
+#include "texteditoroptionspage.h"
 
 namespace TextEditor {
 
@@ -44,13 +42,10 @@ struct DisplaySettingsPageParameters
 {
     QString id;
     QString displayName;
-    QString category;
-    QString displayCategory;
-    QIcon categoryIcon;
     QString settingsPrefix;
 };
 
-class DisplaySettingsPage : public Core::IOptionsPage
+class DisplaySettingsPage : public TextEditorOptionsPage
 {
     Q_OBJECT
 
@@ -61,9 +56,6 @@ public:
     // IOptionsPage
     QString id() const;
     QString displayName() const;
-    QString category() const;
-    QString displayCategory() const;
-    QIcon categoryIcon() const;
 
     QWidget *createPage(QWidget *parent);
     void apply();
diff --git a/src/plugins/texteditor/fontsettingspage.cpp b/src/plugins/texteditor/fontsettingspage.cpp
index b8a7cfd8dcd..b89b7e109a0 100644
--- a/src/plugins/texteditor/fontsettingspage.cpp
+++ b/src/plugins/texteditor/fontsettingspage.cpp
@@ -117,17 +117,14 @@ class FontSettingsPagePrivate
 public:
     FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
                             const QString &id,
-                            const QString &name,
-                            const QString &category,
-                            const QString &trCategory);
+                            const QString &displayName,
+                            const QString &category);
     ~FontSettingsPagePrivate();
 
 public:
     const QString m_id;
     const QString m_displayName;
     const QString m_settingsGroup;
-    const QString m_category;
-    const QString m_displayCategory;
 
     TextEditor::FormatDescriptions m_descriptions;
     FontSettings m_value;
@@ -178,13 +175,10 @@ static QString createColorSchemeFileName(const QString &pattern)
 FontSettingsPagePrivate::FontSettingsPagePrivate(const TextEditor::FormatDescriptions &fd,
                                                  const QString &id,
                                                  const QString &displayName,
-                                                 const QString &category,
-                                                 const QString &trCategory) :
+                                                 const QString &category) :
     m_id(id),
     m_displayName(displayName),
     m_settingsGroup(Utils::settingsKey(category)),
-    m_category(category),
-    m_displayCategory(trCategory),
     m_descriptions(fd),
     m_schemeListModel(new SchemeListModel),
     m_refreshingSchemeList(false)
@@ -313,11 +307,9 @@ QColor FormatDescription::background() const
 //  ------------ FontSettingsPage
 FontSettingsPage::FontSettingsPage(const FormatDescriptions &fd,
                                    const QString &id,
-                                   const QString &category,
-                                   const QString &trCategory,
                                    QObject *parent) :
-    Core::IOptionsPage(parent),
-    d_ptr(new FontSettingsPagePrivate(fd, id, tr("Font && Colors"), category, trCategory))
+    TextEditorOptionsPage(parent),
+    d_ptr(new FontSettingsPagePrivate(fd, id, tr("Font && Colors"), category()))
 {
 }
 
@@ -336,21 +328,6 @@ QString FontSettingsPage::displayName() const
     return d_ptr->m_displayName;
 }
 
-QString FontSettingsPage::category() const
-{
-    return d_ptr->m_category;
-}
-
-QString FontSettingsPage::displayCategory() const
-{
-    return d_ptr->m_displayCategory;
-}
-
-QIcon FontSettingsPage::categoryIcon() const
-{
-    return QIcon(QLatin1String(Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON));
-}
-
 QWidget *FontSettingsPage::createPage(QWidget *parent)
 {
     QWidget *w = new QWidget(parent);
diff --git a/src/plugins/texteditor/fontsettingspage.h b/src/plugins/texteditor/fontsettingspage.h
index 9f84a0c9ecf..d7255579780 100644
--- a/src/plugins/texteditor/fontsettingspage.h
+++ b/src/plugins/texteditor/fontsettingspage.h
@@ -34,7 +34,7 @@
 
 #include "fontsettings.h"
 
-#include <coreplugin/dialogs/ioptionspage.h>
+#include "texteditoroptionspage.h"
 
 #include <QtCore/QString>
 
@@ -77,24 +77,19 @@ private:
 
 typedef QList<FormatDescription> FormatDescriptions;
 
-class TEXTEDITOR_EXPORT FontSettingsPage : public Core::IOptionsPage
+class TEXTEDITOR_EXPORT FontSettingsPage : public TextEditorOptionsPage
 {
     Q_OBJECT
 
 public:
     FontSettingsPage(const FormatDescriptions &fd,
                      const QString &id,
-                     const QString &category,
-                     const QString &trCategory,
                      QObject *parent = 0);
 
     ~FontSettingsPage();
 
     QString id() const;
     QString displayName() const;
-    QString category() const;
-    QString displayCategory() const;
-    QIcon categoryIcon() const;
 
     QWidget *createPage(QWidget *parent);
     void apply();
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index 2ce222b55c6..47221c88add 100644
--- a/src/plugins/texteditor/texteditor.pro
+++ b/src/plugins/texteditor/texteditor.pro
@@ -32,7 +32,8 @@ SOURCES += texteditorplugin.cpp \
     colorscheme.cpp \
     colorschemeedit.cpp \
     itexteditor.cpp \
-    texteditoroverlay.cpp
+    texteditoroverlay.cpp \
+    texteditoroptionspage.cpp
 
 HEADERS += texteditorplugin.h \
     textfilewizard.h \
@@ -67,7 +68,8 @@ HEADERS += texteditorplugin.h \
     findincurrentfile.h \
     colorscheme.h \
     colorschemeedit.h \
-    texteditoroverlay.h
+    texteditoroverlay.h \
+    texteditoroptionspage.h
 
 
 FORMS += behaviorsettingspage.ui \
diff --git a/src/plugins/texteditor/texteditoroptionspage.cpp b/src/plugins/texteditor/texteditoroptionspage.cpp
new file mode 100644
index 00000000000..300203db15f
--- /dev/null
+++ b/src/plugins/texteditor/texteditoroptionspage.cpp
@@ -0,0 +1,56 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#include "texteditoroptionspage.h"
+
+#include "texteditorconstants.h"
+
+#include <QCoreApplication>
+
+using namespace TextEditor;
+
+TextEditorOptionsPage::TextEditorOptionsPage(QObject *parent) :
+    Core::IOptionsPage(parent)
+{
+}
+
+QString TextEditorOptionsPage::category() const
+{
+    return QLatin1String(Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
+}
+
+QString TextEditorOptionsPage::displayCategory() const
+{
+    return QCoreApplication::translate("TextEditor", Constants::TEXT_EDITOR_SETTINGS_TR_CATEGORY);
+}
+
+QIcon TextEditorOptionsPage::categoryIcon() const
+{
+    return QIcon(QLatin1String(Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON));
+}
diff --git a/src/plugins/texteditor/texteditoroptionspage.h b/src/plugins/texteditor/texteditoroptionspage.h
new file mode 100644
index 00000000000..c9aef8012eb
--- /dev/null
+++ b/src/plugins/texteditor/texteditoroptionspage.h
@@ -0,0 +1,57 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** Commercial Usage
+**
+** Licensees holding valid Qt Commercial licenses may use this file in
+** accordance with the Qt Commercial License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Nokia.
+**
+** GNU Lesser General Public License Usage
+**
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at http://qt.nokia.com/contact.
+**
+**************************************************************************/
+
+#ifndef TEXTEDITOROPTIONSPAGE_H
+#define TEXTEDITOROPTIONSPAGE_H
+
+#include <coreplugin/dialogs/ioptionspage.h>
+
+#include "texteditor_global.h"
+
+namespace TextEditor {
+
+/**
+ * An abstract options page in the Text Editor category.
+ */
+class TEXTEDITOR_EXPORT TextEditorOptionsPage : public Core::IOptionsPage
+{
+    Q_OBJECT
+
+public:
+    explicit TextEditorOptionsPage(QObject *parent = 0);
+
+    // IOptionsPage
+    QString category() const;
+    QString displayCategory() const;
+    QIcon categoryIcon() const;
+};
+
+} // namespace TextEditor
+
+#endif // TEXTEDITOROPTIONSPAGE_H
diff --git a/src/plugins/texteditor/texteditorsettings.cpp b/src/plugins/texteditor/texteditorsettings.cpp
index 3ca0410e33a..de018d407fe 100644
--- a/src/plugins/texteditor/texteditorsettings.cpp
+++ b/src/plugins/texteditor/texteditorsettings.cpp
@@ -102,22 +102,15 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
     formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_FILE), tr("Diff File"), Qt::darkBlue));
     formatDescriptions.append(FormatDescription(QLatin1String(C_DIFF_LOCATION), tr("Diff Location"), Qt::blue));
 
-    const QString category = QLatin1String(Constants::TEXT_EDITOR_SETTINGS_CATEGORY);
-    const QString displayCategory = QCoreApplication::translate("TextEditor", Constants::TEXT_EDITOR_SETTINGS_TR_CATEGORY);
-    const QIcon categoryIcon = QIcon(QLatin1String(Constants::TEXT_EDITOR_SETTINGS_CATEGORY_ICON));
-
     m_fontSettingsPage = new FontSettingsPage(formatDescriptions,
                                               QLatin1String("A.FontSettings"),
-                                              category, displayCategory, this);
+                                              this);
     pm->addObject(m_fontSettingsPage);
 
     // Add the GUI used to configure the tab, storage and interaction settings
     TextEditor::BehaviorSettingsPageParameters behaviorSettingsPageParameters;
     behaviorSettingsPageParameters.id = QLatin1String("B.BehaviourSettings");
     behaviorSettingsPageParameters.displayName = tr("Behavior");
-    behaviorSettingsPageParameters.category = category;
-    behaviorSettingsPageParameters.displayCategory = displayCategory;
-    behaviorSettingsPageParameters.categoryIcon = categoryIcon;
     behaviorSettingsPageParameters.settingsPrefix = QLatin1String("text");
     m_behaviorSettingsPage = new BehaviorSettingsPage(behaviorSettingsPageParameters, this);
     pm->addObject(m_behaviorSettingsPage);
@@ -125,9 +118,6 @@ TextEditorSettings::TextEditorSettings(QObject *parent)
     TextEditor::DisplaySettingsPageParameters displaySettingsPageParameters;
     displaySettingsPageParameters.id = QLatin1String("D.DisplaySettings"),
     displaySettingsPageParameters.displayName = tr("Display");
-    displaySettingsPageParameters.category = category;
-    displaySettingsPageParameters.displayCategory = displayCategory;
-    displaySettingsPageParameters.categoryIcon = categoryIcon;
     displaySettingsPageParameters.settingsPrefix = QLatin1String("text");
     m_displaySettingsPage = new DisplaySettingsPage(displaySettingsPageParameters, this);
     pm->addObject(m_displaySettingsPage);
-- 
GitLab