Commit d2ec7d80 authored by hjk's avatar hjk

TextEditor: Merge the two sets of *EditorWidget constructors

Change-Id: I45d87d0be722ac36d64af222f03f8cb76242c9df
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 2c5231b4
......@@ -1423,9 +1423,10 @@ int PermissionsModel::rowCount(const QModelIndex &parent) const
AndroidManifestTextEditorWidget::AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent)
: TextEditor::BaseTextEditorWidget(new AndroidManifestDocument(parent), parent),
: TextEditor::BaseTextEditorWidget(parent),
m_parent(parent)
{
setTextDocument(TextEditor::BaseTextDocumentPtr(new AndroidManifestDocument(parent)));
setupAsPlainEditor();
textDocument()->setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
}
......
......@@ -62,8 +62,8 @@ JavaEditor::JavaEditor(JavaEditorWidget *editor)
Core::IEditor *JavaEditor::duplicate()
{
JavaEditorWidget *ret = new JavaEditorWidget(
qobject_cast<JavaEditorWidget*>(editorWidget()));
JavaEditorWidget *ret = new JavaEditorWidget;
ret->setTextDocument(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
}
......@@ -72,13 +72,7 @@ Core::IEditor *JavaEditor::duplicate()
// JavaEditorWidget
//
JavaEditorWidget::JavaEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new JavaDocument(), parent)
{
}
JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other)
: BaseTextEditorWidget(other)
JavaEditorWidget::JavaEditorWidget()
{
}
......
......@@ -56,14 +56,10 @@ class JavaEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
JavaEditorWidget(QWidget *parent = 0);
JavaEditorWidget(JavaEditorWidget *other);
JavaEditorWidget();
protected:
TextEditor::BaseTextEditor *createEditor();
private:
JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity
};
class JavaDocument : public TextEditor::BaseTextDocument
......
......@@ -49,6 +49,7 @@ JavaEditorFactory::JavaEditorFactory()
Core::IEditor *JavaEditorFactory::createEditor()
{
JavaEditorWidget *editor = new JavaEditorWidget;
editor->setTextDocument(TextEditor::BaseTextDocumentPtr(new JavaDocument));
TextEditor::TextEditorSettings::initializeEditor(editor);
return editor->editor();
}
......@@ -70,8 +70,8 @@ CMakeEditor::CMakeEditor(CMakeEditorWidget *editor)
Core::IEditor *CMakeEditor::duplicate()
{
CMakeEditorWidget *ret = new CMakeEditorWidget(
qobject_cast<CMakeEditorWidget *>(editorWidget()));
CMakeEditorWidget *ret = new CMakeEditorWidget;
ret->setTextDocument(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
}
......@@ -150,19 +150,7 @@ QString CMakeEditor::contextHelpId() const
// CMakeEditor
//
CMakeEditorWidget::CMakeEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new CMakeDocument(), parent)
{
ctor();
}
CMakeEditorWidget::CMakeEditorWidget(CMakeEditorWidget *other)
: BaseTextEditorWidget(other)
{
ctor();
}
void CMakeEditorWidget::ctor()
CMakeEditorWidget::CMakeEditorWidget()
{
setCodeFoldingSupported(true);
}
......
......@@ -66,8 +66,7 @@ class CMakeEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
CMakeEditorWidget(QWidget *parent = 0);
CMakeEditorWidget(CMakeEditorWidget *other);
CMakeEditorWidget();
bool save(const QString &fileName = QString());
......@@ -76,10 +75,6 @@ public:
protected:
TextEditor::BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *e);
private:
CMakeEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
};
class CMakeDocument : public TextEditor::BaseTextDocument
......
......@@ -72,7 +72,8 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
Core::IEditor *CMakeEditorFactory::createEditor()
{
CMakeEditorWidget *rc = new CMakeEditorWidget();
TextEditor::TextEditorSettings::initializeEditor(rc);
return rc->editor();
CMakeEditorWidget *widget = new CMakeEditorWidget;
widget->setTextDocument(TextEditor::BaseTextDocumentPtr(new CMakeDocument));
TextEditor::TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......@@ -175,20 +175,10 @@ CppEditorWidgetPrivate::CppEditorWidgetPrivate(CppEditorWidget *q)
{
}
CppEditorWidget::CppEditorWidget(QWidget *parent)
: TextEditor::BaseTextEditorWidget(new CPPEditorDocument(), parent)
{
ctor();
}
CppEditorWidget::CppEditorWidget(CppEditorWidget *other)
: TextEditor::BaseTextEditorWidget(other)
{
ctor();
}
void CppEditorWidget::ctor()
CppEditorWidget::CppEditorWidget(TextEditor::BaseTextDocumentPtr doc)
: TextEditor::BaseTextEditorWidget(0)
{
setTextDocument(doc);
d.reset(new CppEditorWidgetPrivate(this));
qRegisterMetaType<SemanticInfo>("CppTools::SemanticInfo");
......@@ -781,8 +771,7 @@ void CppEditorWidget::keyPressEvent(QKeyEvent *e)
Core::IEditor *CPPEditor::duplicate()
{
CppEditorWidget *newEditor = new CppEditorWidget(
qobject_cast<CppEditorWidget *>(editorWidget()));
CppEditorWidget *newEditor = new CppEditorWidget(editorWidget()->textDocumentPtr());
CppEditorPlugin::instance()->initializeEditor(newEditor);
return newEditor->editor();
}
......
......@@ -77,8 +77,7 @@ public:
static QString identifierUnderCursor(QTextCursor *macroCursor);
public:
CppEditorWidget(QWidget *parent = 0);
CppEditorWidget(CppEditorWidget *other);
CppEditorWidget(TextEditor::BaseTextDocumentPtr doc);
~CppEditorWidget();
CPPEditorDocument *cppEditorDocument() const;
......@@ -154,9 +153,6 @@ private slots:
private:
static bool openCppEditorAt(const Link &, bool inNextSplit = false);
CppEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
unsigned editorRevision() const;
bool isOutdated() const;
......
......@@ -97,7 +97,7 @@ CppEditorFactory::CppEditorFactory(CppEditorPlugin *owner) :
IEditor *CppEditorFactory::createEditor()
{
CppEditorWidget *editor = new CppEditorWidget();
CppEditorWidget *editor = new CppEditorWidget(BaseTextDocumentPtr(new CPPEditorDocument));
m_owner->initializeEditor(editor);
return editor->editor();
}
......
......@@ -102,9 +102,10 @@ public:
QVERIFY(ast);
// Open file
auto textDocument = new TextEditor::BaseTextDocument;
TextEditor::BaseTextDocumentPtr textDocument(new TextEditor::BaseTextDocument);
textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
TextEditor::BaseTextEditorWidget editorWidget(textDocument, 0);
TextEditor::BaseTextEditorWidget editorWidget(0);
editorWidget.setTextDocument(textDocument);
editorWidget.setupAsPlainEditor();
QString error;
editorWidget.open(&error, document->fileName(), document->fileName());
......
......@@ -37,14 +37,14 @@
namespace Designer {
namespace Internal {
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent) :
TextEditor::BaseTextEditorWidget(new FormWindowFile(form), parent),
m_designerEditor(new FormWindowEditor(this))
DesignerXmlEditorWidget::DesignerXmlEditorWidget(QDesignerFormWindowInterface *form)
{
TextEditor::BaseTextDocumentPtr doc(new FormWindowFile(form));
setTextDocument(doc);
m_designerEditor = new FormWindowEditor(this);
setupAsPlainEditor();
setReadOnly(true);
configureMimeType(textDocument()->mimeType());
configureMimeType(doc->mimeType());
}
TextEditor::BaseTextEditor *DesignerXmlEditorWidget::createEditor()
......
......@@ -57,8 +57,7 @@ class DesignerXmlEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form,
QWidget *parent = 0);
explicit DesignerXmlEditorWidget(QDesignerFormWindowInterface *form);
FormWindowEditor *designerEditor() const;
Internal::FormWindowFile *formWindowFile() const;
......
......@@ -663,7 +663,7 @@ Command *FormEditorW::addToolAction(QAction *a, const Context &context, Id id,
return command;
}
EditorData FormEditorW::createEditor(QWidget *parent)
EditorData FormEditorW::createEditor()
{
if (Designer::Constants::Internal::debug)
qDebug() << "FormEditorW::createEditor";
......@@ -683,7 +683,7 @@ EditorData FormEditorW::createEditor(QWidget *parent)
qdesigner_internal::FormWindowBase::setupDefaultAction(form);
#endif
data.widgetHost = new SharedTools::WidgetHost( /* parent */ 0, form);
DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form, parent);
DesignerXmlEditorWidget *xmlEditor = new DesignerXmlEditorWidget(form);
TextEditor::TextEditorSettings::initializeEditor(xmlEditor);
data.formWindowEditor = xmlEditor->designerEditor();
connect(data.formWindowEditor->document(), SIGNAL(filePathChanged(QString,QString)),
......
......@@ -111,7 +111,7 @@ public:
// Deletes an existing instance if there is one.
static void deleteInstance();
EditorData createEditor(QWidget *parent = 0);
EditorData createEditor();
inline QDesignerFormEditorInterface *designerEditor() const { return m_formeditor; }
inline QWidget * const*designerSubWindows() const { return m_designerSubWindows; }
......
......@@ -101,8 +101,9 @@ private:
};
DescriptionEditorWidget::DescriptionEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new BaseTextDocument, parent)
: BaseTextEditorWidget(parent)
{
setTextDocument(BaseTextDocumentPtr(new BaseTextDocument));
DisplaySettings settings = displaySettings();
settings.m_textWrapping = false;
settings.m_displayLineNumbers = false;
......
......@@ -36,8 +36,9 @@
namespace DiffEditor {
SelectableTextEditorWidget::SelectableTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent)
: BaseTextEditorWidget(parent)
{
setTextDocument(TextEditor::BaseTextDocumentPtr(new TextEditor::BaseTextDocument));
setFrameStyle(QFrame::NoFrame);
}
......
......@@ -64,7 +64,8 @@ ProjectFilesFactory::ProjectFilesFactory(Manager *manager)
Core::IEditor *ProjectFilesFactory::createEditor()
{
auto widget = new ProjectFilesEditorWidget(new BaseTextDocument, 0);
auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(BaseTextDocumentPtr(new BaseTextDocument));
TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......@@ -85,7 +86,8 @@ ProjectFilesEditor::ProjectFilesEditor(ProjectFilesEditorWidget *editor)
Core::IEditor *ProjectFilesEditor::duplicate()
{
auto widget = new ProjectFilesEditorWidget(editorWidget());
auto widget = new ProjectFilesEditorWidget;
widget->setTextDocument(editorWidget()->textDocumentPtr());
TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......@@ -96,13 +98,7 @@ Core::IEditor *ProjectFilesEditor::duplicate()
//
////////////////////////////////////////////////////////////////////////////////////////
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextDocument *doc, QWidget *parent)
: BaseTextEditorWidget(doc, parent)
{
}
ProjectFilesEditorWidget::ProjectFilesEditorWidget(BaseTextEditorWidget *other)
: BaseTextEditorWidget(other)
ProjectFilesEditorWidget::ProjectFilesEditorWidget()
{
}
......
......@@ -39,8 +39,6 @@ namespace GenericProjectManager {
namespace Internal {
class Manager;
class ProjectFilesEditor;
class ProjectFilesEditorWidget;
class ProjectFilesFactory: public Core::IEditorFactory
{
......@@ -52,25 +50,24 @@ public:
Core::IEditor *createEditor();
};
class ProjectFilesEditor : public TextEditor::BaseTextEditor
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
public:
ProjectFilesEditor(ProjectFilesEditorWidget *editorWidget);
ProjectFilesEditorWidget();
Core::IEditor *duplicate();
TextEditor::BaseTextEditor *createEditor();
};
class ProjectFilesEditorWidget : public TextEditor::BaseTextEditorWidget
class ProjectFilesEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
ProjectFilesEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
ProjectFilesEditorWidget(BaseTextEditorWidget *other);
ProjectFilesEditor(ProjectFilesEditorWidget *editorWidget);
TextEditor::BaseTextEditor *createEditor();
Core::IEditor *duplicate();
};
} // namespace Internal
......
......@@ -140,20 +140,10 @@ void Document::addRange(const QTextCursor &cursor, GLSL::Scope *scope)
_cursors.append(c);
}
GlslEditorWidget::GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
: TextEditor::BaseTextEditorWidget(doc, parent)
GlslEditorWidget::GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc)
{
ctor();
}
setTextDocument(doc);
GlslEditorWidget::GlslEditorWidget(GlslEditorWidget *other)
: TextEditor::BaseTextEditorWidget(other)
{
ctor();
}
void GlslEditorWidget::ctor()
{
m_outlineCombo = 0;
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
......@@ -215,8 +205,7 @@ bool GlslEditorWidget::isOutdated() const
Core::IEditor *GlslEditor::duplicate()
{
GlslEditorWidget *newEditor = new GlslEditorWidget(
qobject_cast<GlslEditorWidget *>(editorWidget()));
GlslEditorWidget *newEditor = new GlslEditorWidget(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(newEditor);
return newEditor->editor();
}
......
......@@ -86,8 +86,7 @@ class GlslEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
GlslEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
GlslEditorWidget(GlslEditorWidget *other);
GlslEditorWidget(const TextEditor::BaseTextDocumentPtr &doc);
int editorRevision() const;
bool isOutdated() const;
......@@ -107,8 +106,6 @@ protected:
TextEditor::BaseTextEditor *createEditor();
private:
GlslEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
void setSelectedElements();
QString wordUnderCursor() const;
......
......@@ -66,10 +66,10 @@ GLSLEditorFactory::GLSLEditorFactory(QObject *parent)
Core::IEditor *GLSLEditorFactory::createEditor()
{
auto doc = new TextEditor::BaseTextDocument;
TextEditor::BaseTextDocumentPtr doc(new TextEditor::BaseTextDocument);
doc->setId(C_GLSLEDITOR_ID);
doc->setIndenter(new GLSLIndenter);
GlslEditorWidget *rc = new GlslEditorWidget(doc, 0);
GlslEditorWidget *rc = new GlslEditorWidget(doc);
TextEditor::TextEditorSettings::initializeEditor(rc);
return rc->editor();
}
......@@ -58,7 +58,7 @@ PythonEditor::PythonEditor(PythonEditorWidget *editorWidget)
Core::IEditor *PythonEditor::duplicate()
{
PythonEditorWidget *widget = new PythonEditorWidget(qobject_cast<PythonEditorWidget *>(editorWidget()));
PythonEditorWidget *widget = new PythonEditorWidget(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(widget);
return widget->editor();
}
......
......@@ -60,10 +60,10 @@ EditorFactory::EditorFactory(QObject *parent)
Core::IEditor *EditorFactory::createEditor()
{
auto doc = new BaseTextDocument;
BaseTextDocumentPtr doc(new BaseTextDocument);
doc->setId(Constants::C_PYTHONEDITOR_ID);
doc->setIndenter(new PythonIndenter);
PythonEditorWidget *widget = new PythonEditorWidget(doc, 0);
PythonEditorWidget *widget = new PythonEditorWidget(doc);
TextEditor::TextEditorSettings::initializeEditor(widget);
return widget->editor();
......
......@@ -47,25 +47,14 @@
namespace PythonEditor {
namespace Internal {
PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent)
: TextEditor::BaseTextEditorWidget(doc, parent)
{
ctor();
}
PythonEditorWidget::PythonEditorWidget(PythonEditorWidget *other)
: TextEditor::BaseTextEditorWidget(other)
{
ctor();
}
void PythonEditorWidget::ctor()
PythonEditorWidget::PythonEditorWidget(TextEditor::BaseTextDocumentPtr doc)
{
setTextDocument(doc);
setParenthesesMatchingEnabled(true);
setMarksVisible(true);
setCodeFoldingSupported(true);
new PythonHighlighter(textDocument());
new PythonHighlighter(doc.data());
}
TextEditor::BaseTextEditor *PythonEditorWidget::createEditor()
......
......@@ -40,15 +40,10 @@ class PythonEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
PythonEditorWidget(TextEditor::BaseTextDocument *doc, QWidget *parent);
PythonEditorWidget(PythonEditorWidget *other);
PythonEditorWidget(TextEditor::BaseTextDocumentPtr doc);
protected:
TextEditor::BaseTextEditor *createEditor();
private:
PythonEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
};
} // namespace Internal
......
......@@ -64,8 +64,8 @@ ProFileEditor::ProFileEditor(ProFileEditorWidget *editor)
Core::IEditor *ProFileEditor::duplicate()
{
ProFileEditorWidget *ret = new ProFileEditorWidget(
qobject_cast<ProFileEditorWidget*>(editorWidget()));
ProFileEditorWidget *ret = new ProFileEditorWidget;
ret->setTextDocument(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(ret);
return ret->editor();
}
......@@ -74,12 +74,7 @@ Core::IEditor *ProFileEditor::duplicate()
// ProFileEditorWidget
//
ProFileEditorWidget::ProFileEditorWidget(QWidget *parent)
: BaseTextEditorWidget(new ProFileDocument(), parent)
{}
ProFileEditorWidget::ProFileEditorWidget(ProFileEditorWidget *other)
: BaseTextEditorWidget(other)
ProFileEditorWidget::ProFileEditorWidget()
{}
static bool isValidFileNameChar(const QChar &c)
......
......@@ -55,17 +55,13 @@ class ProFileEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
ProFileEditorWidget(QWidget *parent = 0);
ProFileEditorWidget(ProFileEditorWidget *other);
ProFileEditorWidget();
protected:
virtual Link findLinkAt(const QTextCursor &, bool resolveTarget = true,
bool inNextSplit = false);
TextEditor::BaseTextEditor *createEditor();
void contextMenuEvent(QContextMenuEvent *);
private:
ProFileEditorWidget(BaseTextEditorWidget *); // avoid stupidity
};
class ProFileDocument : public TextEditor::BaseTextDocument
......
......@@ -66,6 +66,7 @@ ProFileEditorFactory::ProFileEditorFactory(QmakeManager *manager) :
Core::IEditor *ProFileEditorFactory::createEditor()
{
ProFileEditorWidget *editor = new ProFileEditorWidget;
editor->setTextDocument(TextEditor::BaseTextDocumentPtr(new ProFileDocument));
TextEditor::TextEditorSettings::initializeEditor(editor);
return editor->editor();
}
......@@ -97,21 +97,12 @@ using namespace QmlJSTools;
namespace QmlJSEditor {
namespace Internal {
QmlJSTextEditorWidget::QmlJSTextEditorWidget(QWidget *parent) :
TextEditor::BaseTextEditorWidget(new QmlJSEditorDocument, parent)
QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc)
: TextEditor::BaseTextEditorWidget(0)
{
ctor();
}
setTextDocument(doc);
QmlJSTextEditorWidget::QmlJSTextEditorWidget(QmlJSTextEditorWidget *other)
: TextEditor::BaseTextEditorWidget(other)
{
ctor();
}
void QmlJSTextEditorWidget::ctor()
{
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(textDocument());
m_qmlJsEditorDocument = static_cast<QmlJSEditorDocument *>(doc.data());
m_outlineCombo = 0;
m_contextPane = 0;
m_findReferences = new FindReferences(this);
......@@ -177,8 +168,7 @@ QModelIndex QmlJSTextEditorWidget::outlineModelIndex()
IEditor *QmlJSEditor::duplicate()
{
QmlJSTextEditorWidget *newEditor = new QmlJSTextEditorWidget(
qobject_cast<QmlJSTextEditorWidget *>(editorWidget()));
QmlJSTextEditorWidget *newEditor = new QmlJSTextEditorWidget(editorWidget()->textDocumentPtr());
TextEditor::TextEditorSettings::initializeEditor(newEditor);
return newEditor->editor();
}
......
......@@ -74,8 +74,7 @@ class QmlJSTextEditorWidget : public TextEditor::BaseTextEditorWidget
Q_OBJECT
public:
QmlJSTextEditorWidget(QWidget *parent = 0);
QmlJSTextEditorWidget(QmlJSTextEditorWidget *other);
QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc);
~QmlJSTextEditorWidget();
QmlJSEditorDocument *qmlJsEditorDocument() const;
......@@ -124,8 +123,6 @@ protected:
QString foldReplacementText(const QTextBlock &block) const;
private:
QmlJSTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
void ctor();
bool isClosingBrace(const QList<QmlJS::Token> &tokens) const;
void setSelectedElements();
......
......@@ -28,6 +28,7 @@
****************************************************************************/
#include "qmljseditorfactory.h"