diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp index 9eaa74b63763340558432823065539103b43aeb8..e1da129b47a8fbd1dc527891762bccb18f91ac95 100644 --- a/src/plugins/android/androidmanifesteditorwidget.cpp +++ b/src/plugins/android/androidmanifesteditorwidget.cpp @@ -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)); } diff --git a/src/plugins/android/javaeditor.cpp b/src/plugins/android/javaeditor.cpp index f9d22aec970f0800d59a515162929d6ae6ed9afb..2e4a72eb39e428620aec4ed48eb6728325681ea3 100644 --- a/src/plugins/android/javaeditor.cpp +++ b/src/plugins/android/javaeditor.cpp @@ -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() { } diff --git a/src/plugins/android/javaeditor.h b/src/plugins/android/javaeditor.h index 8e8fc6a5d13beeaf8da2c230b22baf7a5eb59f25..fd5e216e9d7c56b6e7e3e22a7386ecb52501856b 100644 --- a/src/plugins/android/javaeditor.h +++ b/src/plugins/android/javaeditor.h @@ -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 diff --git a/src/plugins/android/javaeditorfactory.cpp b/src/plugins/android/javaeditorfactory.cpp index be9bee9dccb8cc1bfd5b6625425e39900ace4f2b..3a634467f23213cbab14989a01483c861b150466 100644 --- a/src/plugins/android/javaeditorfactory.cpp +++ b/src/plugins/android/javaeditorfactory.cpp @@ -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(); } diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index b46772758cf679f82129d3b853c2bffe41de4f64..52e5de75eccc81b51a4abfb4e673d3ecaba8f2c8 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -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); } diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.h b/src/plugins/cmakeprojectmanager/cmakeeditor.h index 3f213de84f15b4ba65ea29572369e8ba2934d3d9..fee92e1971a545957f74913d0e3b9ce8ca7027a8 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.h +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.h @@ -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 diff --git a/src/plugins/cmakeprojectmanager/cmakeeditorfactory.cpp b/src/plugins/cmakeprojectmanager/cmakeeditorfactory.cpp index 74fc4699f2d15392594de5f3f99a3ab8796130fd..d6a6f96570f2bc0cc70a6cb5c2e44e807903d4a8 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditorfactory.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditorfactory.cpp @@ -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(); } diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 6a7e830e61b746a734f83b81f7cfb57298a8bb1c..1d42d9bae3099665402befe6fba59ae8bb57d498 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -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(); } diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index d938762916764d7d2401ef01a7d1848d83493470..91de8e456f00d8bc0886d065f0d94ac577456df2 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -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; diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp index e174d67893bd8a65e4e7e9d0cc2393042e1e5b44..e060fe402d73e1d28435e54a6ce0286de744eae6 100644 --- a/src/plugins/cppeditor/cppeditorplugin.cpp +++ b/src/plugins/cppeditor/cppeditorplugin.cpp @@ -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(); } diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp index b0781dac35196e8e2062195756bcf072d2e67057..8877b1c41f73e3e6afcef87d8e8c0d669adc8364 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp +++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp @@ -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()); diff --git a/src/plugins/designer/designerxmleditorwidget.cpp b/src/plugins/designer/designerxmleditorwidget.cpp index f209a98cebcc19f2a8be75ff8f4622c36e0c5bba..a3357ead0cbd208bc704defed47fe7df1d0c8cdf 100644 --- a/src/plugins/designer/designerxmleditorwidget.cpp +++ b/src/plugins/designer/designerxmleditorwidget.cpp @@ -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() diff --git a/src/plugins/designer/designerxmleditorwidget.h b/src/plugins/designer/designerxmleditorwidget.h index 43855f25e20da33e71210aec89ae4f92101abbed..975510b80724a46b582ef3f29018f7424dece04c 100644 --- a/src/plugins/designer/designerxmleditorwidget.h +++ b/src/plugins/designer/designerxmleditorwidget.h @@ -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; diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index 193f7159fb389bf8fc158483ba48c78b69163bdb..d4b680d5e072089e71f0113c4b5a0102119c896b 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -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)), diff --git a/src/plugins/designer/formeditorw.h b/src/plugins/designer/formeditorw.h index 94bc2b1cb9cb2522baeddda0044b3d5813c53b9e..3f03c932fa854a9e1e562f91d59cc6cfed62ea71 100644 --- a/src/plugins/designer/formeditorw.h +++ b/src/plugins/designer/formeditorw.h @@ -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; } diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp index ddd064a66388e344d8740bf5d12d8118fdb7c126..3b98173c94c3865ff8099d2381549ceff86a489a 100644 --- a/src/plugins/diffeditor/diffeditor.cpp +++ b/src/plugins/diffeditor/diffeditor.cpp @@ -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; diff --git a/src/plugins/diffeditor/selectabletexteditorwidget.cpp b/src/plugins/diffeditor/selectabletexteditorwidget.cpp index cc906cd154e597943bfe80cc8a08a88171cdeb4d..53e03b3c1f2efb9c6ef561f79ed3284258c43b38 100644 --- a/src/plugins/diffeditor/selectabletexteditorwidget.cpp +++ b/src/plugins/diffeditor/selectabletexteditorwidget.cpp @@ -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); } diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp index 143e2fa927f5d794985da290ee029c25ccc14d59..1f2b4ba6cb3d69b18e1c64943a5ec4228ddc42a3 100644 --- a/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp +++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.cpp @@ -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() { } diff --git a/src/plugins/genericprojectmanager/genericprojectfileseditor.h b/src/plugins/genericprojectmanager/genericprojectfileseditor.h index 755161abe08ff44dd0b8ee145ecb2324ecf70ccc..803e3bf9a72e70b2f3e574603a27f3949cec089a 100644 --- a/src/plugins/genericprojectmanager/genericprojectfileseditor.h +++ b/src/plugins/genericprojectmanager/genericprojectfileseditor.h @@ -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 diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp index 844adcfb021bc9e5702395c235c3264ad83b3d05..15398b928bfc6ceb7b016853bafb70b8bfd50154 100644 --- a/src/plugins/glsleditor/glsleditor.cpp +++ b/src/plugins/glsleditor/glsleditor.cpp @@ -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(); } diff --git a/src/plugins/glsleditor/glsleditor.h b/src/plugins/glsleditor/glsleditor.h index 380a7be537f58fa14fdeb28831ff6820176d0579..4e54005350df1eb0cd8b06b3f7ae128fb98a84dd 100644 --- a/src/plugins/glsleditor/glsleditor.h +++ b/src/plugins/glsleditor/glsleditor.h @@ -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; diff --git a/src/plugins/glsleditor/glsleditorfactory.cpp b/src/plugins/glsleditor/glsleditorfactory.cpp index 5393d1834e0384340c1bc4ca329eedc05e084923..a492c6758b82bae5935bd08c28bae3dd8105ede5 100644 --- a/src/plugins/glsleditor/glsleditorfactory.cpp +++ b/src/plugins/glsleditor/glsleditorfactory.cpp @@ -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(); } diff --git a/src/plugins/pythoneditor/pythoneditor.cpp b/src/plugins/pythoneditor/pythoneditor.cpp index 196091d480770bfcd751e6c059182a3186b48c82..f7a85c828b0257289afbe592a7d293b9455f2480 100644 --- a/src/plugins/pythoneditor/pythoneditor.cpp +++ b/src/plugins/pythoneditor/pythoneditor.cpp @@ -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(); } diff --git a/src/plugins/pythoneditor/pythoneditorfactory.cpp b/src/plugins/pythoneditor/pythoneditorfactory.cpp index 8a3c19e23282e16382bfdd0b097f1e8a919d5a6b..25089e6fb0d09fc8bc5b98cf2c9baf838bcf34b4 100644 --- a/src/plugins/pythoneditor/pythoneditorfactory.cpp +++ b/src/plugins/pythoneditor/pythoneditorfactory.cpp @@ -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(); diff --git a/src/plugins/pythoneditor/pythoneditorwidget.cpp b/src/plugins/pythoneditor/pythoneditorwidget.cpp index 08e1f35258a12806c5433d58b40eb9c7cca78322..4a8d1edf59e2162fddbe8eba77fb92bdd44d96eb 100644 --- a/src/plugins/pythoneditor/pythoneditorwidget.cpp +++ b/src/plugins/pythoneditor/pythoneditorwidget.cpp @@ -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() diff --git a/src/plugins/pythoneditor/pythoneditorwidget.h b/src/plugins/pythoneditor/pythoneditorwidget.h index c182e195adda4eb2de66bae8aecd6fae8027f2c3..e121d68f90b443c032c7217b65a6a750999857de 100644 --- a/src/plugins/pythoneditor/pythoneditorwidget.h +++ b/src/plugins/pythoneditor/pythoneditorwidget.h @@ -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 diff --git a/src/plugins/qmakeprojectmanager/profileeditor.cpp b/src/plugins/qmakeprojectmanager/profileeditor.cpp index 31b2e4b477f41a56f0ab00c0f70aeadc993d4164..68822ac301fdbe37dd5668fea0000f04d11501df 100644 --- a/src/plugins/qmakeprojectmanager/profileeditor.cpp +++ b/src/plugins/qmakeprojectmanager/profileeditor.cpp @@ -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) diff --git a/src/plugins/qmakeprojectmanager/profileeditor.h b/src/plugins/qmakeprojectmanager/profileeditor.h index d586cc49b43bf751c42afa14188e7755772d5dde..caa92e2f2642c3d8107bce2986201160990cdde3 100644 --- a/src/plugins/qmakeprojectmanager/profileeditor.h +++ b/src/plugins/qmakeprojectmanager/profileeditor.h @@ -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 diff --git a/src/plugins/qmakeprojectmanager/profileeditorfactory.cpp b/src/plugins/qmakeprojectmanager/profileeditorfactory.cpp index 223d067957d2cf0adc0b7eb9cc16c9f80dff4fd2..8dee30c4999102ef3fc67de81ac36f42f74c88ae 100644 --- a/src/plugins/qmakeprojectmanager/profileeditorfactory.cpp +++ b/src/plugins/qmakeprojectmanager/profileeditorfactory.cpp @@ -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(); } diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp index f10a5f280f700fec525ea31b9f7d7639ecd288a6..6ce3e637ceb560e8d8bba49eb0e247622bc957b3 100644 --- a/src/plugins/qmljseditor/qmljseditor.cpp +++ b/src/plugins/qmljseditor/qmljseditor.cpp @@ -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(); } diff --git a/src/plugins/qmljseditor/qmljseditor.h b/src/plugins/qmljseditor/qmljseditor.h index 9dc4e206d611a0c2ef64907480a45c608810c23f..f67c5e4f5f6a3a455e3ed121d33cccd5006bcc78 100644 --- a/src/plugins/qmljseditor/qmljseditor.h +++ b/src/plugins/qmljseditor/qmljseditor.h @@ -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(); diff --git a/src/plugins/qmljseditor/qmljseditorfactory.cpp b/src/plugins/qmljseditor/qmljseditorfactory.cpp index f0bbfb975786cb6625b2df2b8997bce37575998d..6b76c10c7f2a02f6ed47faac50fbcd2a9fac74ed 100644 --- a/src/plugins/qmljseditor/qmljseditorfactory.cpp +++ b/src/plugins/qmljseditor/qmljseditorfactory.cpp @@ -28,6 +28,7 @@ ****************************************************************************/ #include "qmljseditorfactory.h" +#include "qmljseditordocument.h" #include "qmljseditoreditable.h" #include "qmljseditor.h" #include "qmljseditorconstants.h" @@ -64,7 +65,7 @@ QmlJSEditorFactory::QmlJSEditorFactory(QObject *parent) Core::IEditor *QmlJSEditorFactory::createEditor() { - QmlJSTextEditorWidget *rc = new QmlJSTextEditorWidget(); + QmlJSTextEditorWidget *rc = new QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr(new QmlJSEditorDocument)); TextEditor::TextEditorSettings::initializeEditor(rc); return rc->editor(); } diff --git a/src/plugins/qnx/bardescriptoreditorwidget.cpp b/src/plugins/qnx/bardescriptoreditorwidget.cpp index 20c7eb6a9d6210313f7780e88a54b7971b3d43ab..efda173dc400223bb3c5a8389edcf3833cc0d488 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.cpp +++ b/src/plugins/qnx/bardescriptoreditorwidget.cpp @@ -54,6 +54,7 @@ #include <texteditor/normalindenter.h> #include <utils/qtcassert.h> +using namespace TextEditor; using namespace Qnx; using namespace Qnx::Internal; @@ -168,11 +169,12 @@ void BarDescriptorEditorWidget::initAssetsPage() void BarDescriptorEditorWidget::initSourcePage() { - auto doc = new TextEditor::BaseTextDocument; + BaseTextDocumentPtr doc(new BaseTextDocument); doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); // FIXME: This looks odd. doc->setIndenter(new TextEditor::NormalIndenter); - m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(doc, this); + m_xmlSourceWidget = new TextEditor::BaseTextEditorWidget(this); + m_xmlSourceWidget->setTextDocument(doc); m_xmlSourceWidget->setupAsPlainEditor(); addWidget(m_xmlSourceWidget); diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index 437c8432708e0c321f76e42a53415326e24b0144..71c1d428b07474e1499950c316332a23eaa42a12 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -38,6 +38,7 @@ #include <QList> #include <QMap> +#include <QSharedPointer> QT_BEGIN_NAMESPACE class QTextCursor; @@ -147,6 +148,8 @@ private: BaseTextDocumentPrivate *d; }; +typedef QSharedPointer<BaseTextDocument> BaseTextDocumentPtr; + } // namespace TextEditor #endif // BASETEXTDOCUMENT_H diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 73b18572097edd7ce1d4625ac9b4f584f9dd9926..60ff90a47eb100f9ab7c8f28fbab23c24d44e471 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -566,17 +566,15 @@ QString BaseTextEditorWidget::convertToPlainText(const QString &txt) static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext"; -BaseTextEditorWidget::BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent) +BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent) : QPlainTextEdit(parent) { d = new BaseTextEditorWidgetPrivate(this); - d->ctor(QSharedPointer<BaseTextDocument>(doc)); } -BaseTextEditorWidget::BaseTextEditorWidget(BaseTextEditorWidget *other) +void BaseTextEditorWidget::setTextDocument(const QSharedPointer<BaseTextDocument> &doc) { - d = new BaseTextEditorWidgetPrivate(this); - d->ctor(other->d->m_document); + d->ctor(doc); } void BaseTextEditorWidgetPrivate::ctor(const QSharedPointer<BaseTextDocument> &doc) @@ -1000,6 +998,11 @@ BaseTextDocument *BaseTextEditorWidget::textDocument() const return d->m_document.data(); } +BaseTextDocumentPtr BaseTextEditorWidget::textDocumentPtr() const +{ + return d->m_document; +} + void BaseTextEditorWidgetPrivate::editorContentsChange(int position, int charsRemoved, int charsAdded) { if (m_animator) @@ -2806,7 +2809,7 @@ AutoCompleter *BaseTextEditor::autoCompleter() const void BaseTextEditorWidgetPrivate::setupDocumentSignals() { QTextDocument *doc = m_document->document(); - q->setDocument(doc); + q->QPlainTextEdit::setDocument(doc); q->setCursorWidth(2); // Applies to the document layout BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(doc->documentLayout()); @@ -7096,7 +7099,8 @@ void BaseTextEditorWidget::setupAsPlainEditor() IEditor *BaseTextEditor::duplicate() { - auto newWidget = new BaseTextEditorWidget(editorWidget()); + auto newWidget = new BaseTextEditorWidget(0); + newWidget->setTextDocument(editorWidget()->textDocumentPtr()); newWidget->setupAsPlainEditor(); TextEditorSettings::initializeEditor(newWidget); auto editor = newWidget->editor(); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 10108e2b8e052743c5e8a7aa83cf3709ecf5384a..bfb118fc6f902c4522aeedd889a442b801047afd 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -212,11 +212,13 @@ class TEXTEDITOR_EXPORT BaseTextEditorWidget : public QPlainTextEdit Q_PROPERTY(int verticalBlockSelectionLastColumn READ verticalBlockSelectionLastColumn) public: - BaseTextEditorWidget(BaseTextDocument *doc, QWidget *parent); - BaseTextEditorWidget(BaseTextEditorWidget *other); + BaseTextEditorWidget(QWidget *parent = 0); ~BaseTextEditorWidget(); + void setTextDocument(const BaseTextDocumentPtr &doc); + BaseTextDocument *textDocument() const; + BaseTextDocumentPtr textDocumentPtr() const; // IEditor virtual bool open(QString *errorString, const QString &fileName, const QString &realFileName); diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp index 6266e75db8e0f7b43f86f5916ed479d39174c235..f14dce268529858a13c3dcbb6abacd24755378bc 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.cpp +++ b/src/plugins/texteditor/plaintexteditorfactory.cpp @@ -61,10 +61,11 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent) Core::IEditor *PlainTextEditorFactory::createEditor() { - auto doc = new BaseTextDocument; + BaseTextDocumentPtr doc(new BaseTextDocument); doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); doc->setIndenter(new NormalIndenter); - auto widget = new BaseTextEditorWidget(doc, 0); + auto widget = new BaseTextEditorWidget(0); + widget->setTextDocument(doc); 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 08ff2a88f2211618d3de4bb1468bd00e398f621c..d59be8a5b43220205b68ad404308dcdc16287d1b 100644 --- a/src/plugins/texteditor/snippets/snippeteditor.cpp +++ b/src/plugins/texteditor/snippets/snippeteditor.cpp @@ -50,9 +50,11 @@ SnippetEditor::SnippetEditor(SnippetEditorWidget *editor) } SnippetEditorWidget::SnippetEditorWidget(QWidget *parent) - : BaseTextEditorWidget(new BaseTextDocument, parent) + : BaseTextEditorWidget(parent) { - textDocument()->setId(Constants::SNIPPET_EDITOR_ID); + BaseTextDocumentPtr doc(new BaseTextDocument); + doc->setId(Constants::SNIPPET_EDITOR_ID); + setTextDocument(doc); setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); setHighlightCurrentLine(false); setLineNumbersVisible(false); diff --git a/src/plugins/vcsbase/vcsbaseeditor.cpp b/src/plugins/vcsbase/vcsbaseeditor.cpp index 54d5a87a13964083db392d403b35977bc2eb689f..4cce8c946c11192453a45a03fa18567b842c81a6 100644 --- a/src/plugins/vcsbase/vcsbaseeditor.cpp +++ b/src/plugins/vcsbase/vcsbaseeditor.cpp @@ -90,6 +90,8 @@ \sa VcsBase::VcsBaseEditorWidget */ +using namespace TextEditor; + namespace VcsBase { /*! @@ -649,12 +651,14 @@ QComboBox *VcsBaseEditorWidgetPrivate::entriesComboBox() */ VcsBaseEditorWidget::VcsBaseEditorWidget(const VcsBaseEditorParameters *type, QWidget *parent) - : BaseTextEditorWidget(new TextEditor::BaseTextDocument, parent), + : BaseTextEditorWidget(parent), d(new Internal::VcsBaseEditorWidgetPrivate(this, type)) { + BaseTextDocumentPtr doc(new BaseTextDocument); + doc->setId(type->id); + doc->setMimeType(QLatin1String(d->m_parameters->mimeType)); + setTextDocument(doc); viewport()->setMouseTracking(true); - textDocument()->setId(type->id); - textDocument()->setMimeType(QLatin1String(d->m_parameters->mimeType)); } void VcsBaseEditorWidget::setDiffFilePattern(const QRegExp &pattern)