From f5b0bd32b20fc1e37f95b412252b597b9936dda7 Mon Sep 17 00:00:00 2001
From: hjk <hjk121@nokiamail.com>
Date: Thu, 31 Jul 2014 14:44:42 +0200
Subject: [PATCH] TextEditor: Remove one stack of EditorWidget constructors

There are conceptually only two: one that operates a new document,
and one that shares one. Being explicit makes moving data over to
the Editor hierarchy easier. Convenience can be re-added there,
later.

Change-Id: I9b34ff26628c99ffff01201dcf99332d5e7253e9
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
---
 .../cpppointerdeclarationformatter_test.cpp   |  2 +-
 src/plugins/diffeditor/diffeditor.cpp         |  2 +-
 .../diffeditor/selectabletexteditorwidget.cpp |  3 ++-
 .../genericprojectfileseditor.cpp             | 19 +++++++++----------
 .../genericprojectfileseditor.h               |  7 ++-----
 src/plugins/glsleditor/glsleditor.cpp         | 10 ++--------
 src/plugins/glsleditor/glsleditor.h           |  3 +--
 src/plugins/glsleditor/glsleditorfactory.cpp  |  6 +++++-
 .../pythoneditor/pythoneditorfactory.cpp      |  8 +++++++-
 .../pythoneditor/pythoneditorwidget.cpp       |  7 ++-----
 src/plugins/pythoneditor/pythoneditorwidget.h |  2 +-
 src/plugins/texteditor/basetexteditor.cpp     |  7 -------
 src/plugins/texteditor/basetexteditor.h       |  3 +--
 .../texteditor/plaintexteditorfactory.cpp     |  2 +-
 .../texteditor/snippets/snippeteditor.cpp     |  3 ++-
 src/plugins/vcsbase/vcsbaseeditor.cpp         |  2 +-
 16 files changed, 38 insertions(+), 48 deletions(-)

diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
index 03619884bcc..b0781dac351 100644
--- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
+++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp
@@ -104,7 +104,7 @@ public:
         // Open file
         auto textDocument = new TextEditor::BaseTextDocument;
         textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
-        TextEditor::BaseTextEditorWidget editorWidget(textDocument);
+        TextEditor::BaseTextEditorWidget editorWidget(textDocument, 0);
         editorWidget.setupAsPlainEditor();
         QString error;
         editorWidget.open(&error, document->fileName(), document->fileName());
diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp
index 34d75a2bbcd..3b1bb16a8ad 100644
--- a/src/plugins/diffeditor/diffeditor.cpp
+++ b/src/plugins/diffeditor/diffeditor.cpp
@@ -101,7 +101,7 @@ private:
 };
 
 DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
-    : BaseTextEditorWidget(parent)
+    : BaseTextEditorWidget(new BaseTextDocument, parent)
 {
     DisplaySettings settings = displaySettings();
     settings.m_textWrapping = false;
diff --git a/src/plugins/diffeditor/selectabletexteditorwidget.cpp b/src/plugins/diffeditor/selectabletexteditorwidget.cpp
index 91e31b0e8c8..cc906cd154e 100644
--- a/src/plugins/diffeditor/selectabletexteditorwidget.cpp
+++ b/src/plugins/diffeditor/selectabletexteditorwidget.cpp
@@ -28,6 +28,7 @@
 ****************************************************************************/
 
 #include "selectabletexteditorwidget.h"
+#include <texteditor/basetextdocument.h>
 
 #include <QPainter>
 #include <QTextBlock>
@@ -35,7 +36,7 @@
 namespace DiffEditor {
 
 SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
-    : BaseTextEditorWidget(parent)
+    : BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent)
 {
     setFrameStyle(QFrame::NoFrame);
 }
diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp
index 05f285e67c9..143e2fa927f 100644
--- a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp
+++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp
@@ -64,9 +64,9 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
 
 Core::IEditor *ProjectFilesFactory::createEditor()
 {
-    ProjectFilesEditorWidget *ed = new ProjectFilesEditorWidget();
-    TextEditorSettings::initializeEditor(ed);
-    return ed->editor();
+    auto widget = new ProjectFilesEditorWidget(new BaseTextDocument, 0);
+    TextEditorSettings::initializeEditor(widget);
+    return widget->editor();
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -85,10 +85,9 @@ ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
 
 Core::IEditor *ProjectFilesEditor::duplicate()
 {
-    ProjectFilesEditorWidget *editor = new ProjectFilesEditorWidget(
-                qobject_cast<ProjectFilesEditorWidget *>(editorWidget()));
-    TextEditorSettings::initializeEditor(editor);
-    return editor->editor();
+    auto widget = new ProjectFilesEditorWidget(editorWidget());
+    TextEditorSettings::initializeEditor(widget);
+    return widget->editor();
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////
@@ -97,12 +96,12 @@ Core::IEditor *ProjectFilesEditor::duplicate()
 //
 ////////////////////////////////////////////////////////////////////////////////////////
 
-ProjectFilesEditorWidget::ProjectFilesEditorWidget(QWidget *parent)
-    : BaseTextEditorWidget(parent)
+ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextDocument *doc, QWidget *parent)
+    : BaseTextEditorWidget(doc, parent)
 {
 }
 
-ProjectFilesEditorWidget::ProjectFilesEditorWidget(ProjectFilesEditorWidget *other)
+ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextEditorWidget *other)
     : BaseTextEditorWidget(other)
 {
 }
diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.h b/src/plugins/genericprojectmanager/genericprojectfileseditor.h
index 8c74f26dbcf..755161abe08 100644
--- a/src/plugins/genericprojectmanager/genericprojectfileseditor.h
+++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.h
@@ -67,13 +67,10 @@ class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
     Q_OBJECT
 
 public:
-    ProjectFilesEditorWidget(QWidget *parent = 0);
-    ProjectFilesEditorWidget(ProjectFilesEditorWidget *other);
+    ProjectFilesEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
+    ProjectFilesEditorWidget(BaseTextEditorWidget *other);
 
     TextEditor::BaseTextEditor *createEditor();
-
-private:
-    ProjectFilesEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
 };
 
 } // namespace Internal
diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp
index 4509c005122..9bc953cc053 100644
--- a/src/plugins/glsleditor/glsleditor.cpp
+++ b/src/plugins/glsleditor/glsleditor.cpp
@@ -140,11 +140,9 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
     _cursors.append(c);
 }
 
-GlslEditorWidget::GlslEditorWidget(QWidget *parent)
-    : TextEditor::BaseTextEditorWidget(parent)
+GlslEditorWidget::GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
+    : TextEditor::BaseTextEditorWidget(doc, parent)
 {
-    baseTextDocument()->setId(GLSLEditor::Constants::C_GLSLEDITOR_ID);
-    baseTextDocument()->setIndenter(new GLSLIndenter());
     ctor();
 }
 
@@ -180,10 +178,6 @@ void GlslEditorWidget::ctor()
 //    }
 }
 
-GlslEditorWidget::~GlslEditorWidget()
-{
-}
-
 int GlslEditorWidget::editorRevision() const
 {
     //return document()->revision();
diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h
index 64f67d5c78c..39f185a7549 100644
--- a/src/plugins/glsleditor/glsleditor.h
+++ b/src/plugins/glsleditor/glsleditor.h
@@ -86,9 +86,8 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
     Q_OBJECT
 
 public:
-    GlslEditorWidget(QWidget *parent = 0);
+    GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
     GlslEditorWidget(GlslEditorWidget *other);
-    ~GlslEditorWidget();
 
     int editorRevision() const;
     bool isOutdated() const;
diff --git a/src/plugins/glsleditor/glsleditorfactory.cpp b/src/plugins/glsleditor/glsleditorfactory.cpp
index b66d83052c3..5393d1834e0 100644
--- a/src/plugins/glsleditor/glsleditorfactory.cpp
+++ b/src/plugins/glsleditor/glsleditorfactory.cpp
@@ -32,6 +32,7 @@
 #include "glsleditor.h"
 #include "glsleditorconstants.h"
 #include "glsleditorplugin.h"
+#include "glslindenter.h"
 
 #include <extensionsystem/pluginmanager.h>
 #include <extensionsystem/pluginspec.h>
@@ -65,7 +66,10 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
 
 Core::IEditor *GLSLEditorFactory::createEditor()
 {
-    GlslEditorWidget *rc = new GlslEditorWidget();
+    auto doc = new TextEditor::BaseTextDocument;
+    doc->setId(C_GLSLEDITOR_ID);
+    doc->setIndenter(new GLSLIndenter);
+    GlslEditorWidget *rc = new GlslEditorWidget(doc, 0);
     TextEditor::TextEditorSettings::initializeEditor(rc);
     return rc->editor();
 }
diff --git a/src/plugins/pythoneditor/pythoneditorfactory.cpp b/src/plugins/pythoneditor/pythoneditorfactory.cpp
index 483309899c1..8a3c19e2328 100644
--- a/src/plugins/pythoneditor/pythoneditorfactory.cpp
+++ b/src/plugins/pythoneditor/pythoneditorfactory.cpp
@@ -31,6 +31,7 @@
 #include "pythoneditorconstants.h"
 #include "pythoneditorwidget.h"
 #include "pythoneditorplugin.h"
+#include "tools/pythonindenter.h"
 
 #include <coreplugin/icore.h>
 #include <coreplugin/editormanager/editormanager.h>
@@ -39,6 +40,8 @@
 
 #include <QDebug>
 
+using namespace TextEditor;
+
 namespace PythonEditor {
 namespace Internal {
 
@@ -57,7 +60,10 @@ EditorFactory::EditorFactory(QObject *parent)
 
 Core::IEditor *EditorFactory::createEditor()
 {
-    PythonEditorWidget *widget = new PythonEditorWidget();
+    auto doc = new BaseTextDocument;
+    doc->setId(Constants::C_PYTHONEDITOR_ID);
+    doc->setIndenter(new PythonIndenter);
+    PythonEditorWidget *widget = new PythonEditorWidget(doc, 0);
     TextEditor::TextEditorSettings::initializeEditor(widget);
 
     return widget->editor();
diff --git a/src/plugins/pythoneditor/pythoneditorwidget.cpp b/src/plugins/pythoneditor/pythoneditorwidget.cpp
index 495ba2158d9..2fcf5a2c6e1 100644
--- a/src/plugins/pythoneditor/pythoneditorwidget.cpp
+++ b/src/plugins/pythoneditor/pythoneditorwidget.cpp
@@ -35,7 +35,6 @@
 
 #include "pythoneditorwidget.h"
 #include "tools/pythonhighlighter.h"
-#include "tools/pythonindenter.h"
 #include "pythoneditor.h"
 #include "pythoneditorconstants.h"
 
@@ -48,11 +47,9 @@
 namespace PythonEditor {
 namespace Internal {
 
-PythonEditorWidget::PythonEditorWidget(QWidget *parent)
-    : TextEditor::BaseTextEditorWidget(parent)
+PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
+    : TextEditor::BaseTextEditorWidget(doc, parent)
 {
-    baseTextDocument()->setId(Constants::C_PYTHONEDITOR_ID);
-    baseTextDocument()->setIndenter(new PythonIndenter());
     ctor();
 }
 
diff --git a/src/plugins/pythoneditor/pythoneditorwidget.h b/src/plugins/pythoneditor/pythoneditorwidget.h
index 37b1d46405c..c182e195add 100644
--- a/src/plugins/pythoneditor/pythoneditorwidget.h
+++ b/src/plugins/pythoneditor/pythoneditorwidget.h
@@ -40,7 +40,7 @@ class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
     Q_OBJECT
 
 public:
-    PythonEditorWidget(QWidget *parent = 0);
+    PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
     PythonEditorWidget(PythonEditorWidget *other);
 
 protected:
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index cdad9c23923..a4276f1a4c2 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -455,13 +455,6 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt)
 
 static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
 
-BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
-    : QPlainTextEdit(parent)
-{
-    d = new BaseTextEditorWidgetPrivate(this);
-    d->ctor(QSharedPointer<BaseTextDocument>(new BaseTextDocument));
-}
-
 BaseTextEditorWidget::BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
     : QPlainTextEdit(parent)
 {
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 21b1457a03e..acd15505f4a 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -225,8 +225,7 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit
     Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn)
 
 public:
-    BaseTextEditorWidget(QWidget *parent = 0);
-    BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
+    BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent);
     BaseTextEditorWidget(BaseTextEditorWidget *other);
     ~BaseTextEditorWidget();
 
diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp
index 2bcbc2a0fcf..6266e75db8e 100644
--- a/src/plugins/texteditor/plaintexteditorfactory.cpp
+++ b/src/plugins/texteditor/plaintexteditorfactory.cpp
@@ -64,7 +64,7 @@ Core::IEditor *PlainTextEditorFactory::createEditor()
     auto doc = new BaseTextDocument;
     doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
     doc->setIndenter(new NormalIndenter);
-    auto widget = new BaseTextEditorWidget(doc);
+    auto widget = new BaseTextEditorWidget(doc, 0);
     widget->setupAsPlainEditor();
     TextEditorSettings::initializeEditor(widget);
     connect(widget, SIGNAL(configured(Core::IEditor*)),
diff --git a/src/plugins/texteditor/snippets/snippeteditor.cpp b/src/plugins/texteditor/snippets/snippeteditor.cpp
index 72e7665f308..140468be449 100644
--- a/src/plugins/texteditor/snippets/snippeteditor.cpp
+++ b/src/plugins/texteditor/snippets/snippeteditor.cpp
@@ -49,7 +49,8 @@ SnippetEditor::SnippetEditor(SnippetEditorWidget *editor)
     setContext(Core::Context(Constants::SNIPPET_EDITOR_ID, Constants::C_TEXTEDITOR));
 }
 
-SnippetEditorWidget::SnippetEditorWidget(QWidget *parent) : BaseTextEditorWidget(parent)
+SnippetEditorWidget::SnippetEditorWidget(QWidget *parent)
+    : BaseTextEditorWidget(new BaseTextDocument, parent)
 {
     baseTextDocument()->setId(Constants::SNIPPET_EDITOR_ID);
     setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp
index 1aca147ab17..f2407f3d194 100644
--- a/src/plugins/vcsbase/vcsbaseeditor.cpp
+++ b/src/plugins/vcsbase/vcsbaseeditor.cpp
@@ -648,7 +648,7 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox()
 */
 
 VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent)
-  : BaseTextEditorWidget(parent),
+  : BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent),
     d(new Internal::VcsBaseEditorWidgetPrivate(this, type))
 {
     viewport()->setMouseTracking(true);
-- 
GitLab