diff options
author | hjk <hjk121@nokiamail.com> | 2014-07-30 12:33:12 +0200 |
---|---|---|
committer | hjk <hjk121@nokiamail.com> | 2014-07-30 15:17:50 +0200 |
commit | 068462e52d1d244273711899b8a00f72c1105833 (patch) | |
tree | 51634836abd4171b5ceefc8629554f9d40257bc3 | |
parent | d90bd09499874bb090bfd12a3d59e0fdec4ad6da (diff) | |
download | qt-creator-068462e52d1d244273711899b8a00f72c1105833.tar.gz |
TextEditor: Replace PlainTextDocument by Base + a setup function
Change-Id: I1088062d0b74fd0dd69e92c55cc8bb80da61ae2d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
-rw-r--r-- | src/plugins/android/androidmanifestdocument.cpp | 8 | ||||
-rw-r--r-- | src/plugins/android/androidmanifestdocument.h | 6 | ||||
-rw-r--r-- | src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp | 15 | ||||
-rw-r--r-- | src/plugins/designer/formwindowfile.cpp | 1 | ||||
-rw-r--r-- | src/plugins/designer/formwindowfile.h | 5 | ||||
-rw-r--r-- | src/plugins/qnx/bardescriptoreditorwidget.cpp | 9 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.cpp | 14 | ||||
-rw-r--r-- | src/plugins/texteditor/basetextdocument.h | 2 | ||||
-rw-r--r-- | src/plugins/texteditor/plaintexteditor.cpp | 12 | ||||
-rw-r--r-- | src/plugins/texteditor/plaintexteditor.h | 9 | ||||
-rw-r--r-- | src/plugins/texteditor/plaintexteditorfactory.cpp | 4 |
11 files changed, 45 insertions, 40 deletions
diff --git a/src/plugins/android/androidmanifestdocument.cpp b/src/plugins/android/androidmanifestdocument.cpp index 10f5894801..27a0c4799e 100644 --- a/src/plugins/android/androidmanifestdocument.cpp +++ b/src/plugins/android/androidmanifestdocument.cpp @@ -33,17 +33,15 @@ #include <coreplugin/editormanager/ieditor.h> -#include <QDir> -#include <QDomDocument> +#include <QFileInfo> using namespace Android; using namespace Android::Internal; - AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget) - : TextEditor::PlainTextDocument(), - m_editorWidget(editorWidget) + : m_editorWidget(editorWidget) { + setupAsPlainTextDocument(); setId(Constants::ANDROID_MANIFEST_EDITOR_ID); setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); connect(editorWidget, SIGNAL(guiChanged()), diff --git a/src/plugins/android/androidmanifestdocument.h b/src/plugins/android/androidmanifestdocument.h index 3fa3369941..e741f5208a 100644 --- a/src/plugins/android/androidmanifestdocument.h +++ b/src/plugins/android/androidmanifestdocument.h @@ -30,14 +30,14 @@ #ifndef ANDROIDMANIFESTDOCUMENT_H #define ANDROIDMANIFESTDOCUMENT_H -#include <coreplugin/textdocument.h> -#include <texteditor/plaintexteditor.h> +#include <texteditor/basetexteditor.h> namespace Android { namespace Internal { + class AndroidManifestEditorWidget; -class AndroidManifestDocument : public TextEditor::PlainTextDocument +class AndroidManifestDocument : public TextEditor::BaseTextDocument { public: explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget); diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp index 400879a8c4..ffaa7c6679 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp +++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp @@ -32,7 +32,9 @@ #include "cpptoolsplugin.h" #include "cpptoolstestcase.h" -#include <texteditor/plaintexteditor.h> +#include <coreplugin/coreconstants.h> + +#include <texteditor/basetexteditor.h> #include <utils/fileutils.h> @@ -100,7 +102,10 @@ public: QVERIFY(ast); // Open file - TextEditor::BaseTextEditorWidget editorWidget(new TextEditor::PlainTextDocument); + auto textDocument = new TextEditor::BaseTextDocument; + textDocument->setupAsPlainTextDocument(); + textDocument->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); + TextEditor::BaseTextEditorWidget editorWidget(textDocument); editorWidget.setupAsPlainEditor(); QString error; editorWidget.open(&error, document->fileName(), document->fileName()); @@ -111,7 +116,7 @@ public: cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, cursorPosition); editorWidget.setTextCursor(cursor); - QTextDocument *textDocument = editorWidget.document(); + QTextDocument *qtextDocument = editorWidget.document(); CppRefactoringFilePtr cppRefactoringFile = CppRefactoringChanges::file(&editorWidget, document); @@ -126,11 +131,11 @@ public: Utils::ChangeSet change = formatter.format(ast); // ChangeSet may be empty. // Apply change - QTextCursor changeCursor(textDocument); + QTextCursor changeCursor(qtextDocument); change.apply(&changeCursor); // Compare - QCOMPARE(textDocument->toPlainText(), expectedSource); + QCOMPARE(qtextDocument->toPlainText(), expectedSource); } }; diff --git a/src/plugins/designer/formwindowfile.cpp b/src/plugins/designer/formwindowfile.cpp index 24d2da9b45..ae28fbce8c 100644 --- a/src/plugins/designer/formwindowfile.cpp +++ b/src/plugins/designer/formwindowfile.cpp @@ -56,6 +56,7 @@ FormWindowFile::FormWindowFile(QDesignerFormWindowInterface *form, QObject *pare m_formWindow(form), m_isModified(false) { + setupAsPlainTextDocument(); setMimeType(QLatin1String(Designer::Constants::FORM_MIMETYPE)); setParent(parent); setId(Core::Id(Designer::Constants::K_DESIGNER_XML_EDITOR_ID)); diff --git a/src/plugins/designer/formwindowfile.h b/src/plugins/designer/formwindowfile.h index 939a0756e5..52060dd749 100644 --- a/src/plugins/designer/formwindowfile.h +++ b/src/plugins/designer/formwindowfile.h @@ -30,19 +30,18 @@ #ifndef FORMWINDOWFILE_H #define FORMWINDOWFILE_H -#include <texteditor/plaintexteditor.h> +#include <texteditor/basetextdocument.h> #include <QPointer> QT_BEGIN_NAMESPACE class QDesignerFormWindowInterface; -class QFile; QT_END_NAMESPACE namespace Designer { namespace Internal { -class FormWindowFile : public TextEditor::PlainTextDocument +class FormWindowFile : public TextEditor::BaseTextDocument { Q_OBJECT diff --git a/src/plugins/qnx/bardescriptoreditorwidget.cpp b/src/plugins/qnx/bardescriptoreditorwidget.cpp index 7a2645bff6..2692f297f6 100644 --- a/src/plugins/qnx/bardescriptoreditorwidget.cpp +++ b/src/plugins/qnx/bardescriptoreditorwidget.cpp @@ -41,12 +41,14 @@ #include "bardescriptoreditorpackageinformationwidget.h" #include "bardescriptoreditorpermissionswidget.h" +#include <coreplugin/coreconstants.h> #include <coreplugin/icore.h> #include <projectexplorer/panelswidget.h> #include <projectexplorer/propertiespanel.h> #include <projectexplorer/task.h> #include <projectexplorer/taskhub.h> -#include <texteditor/plaintexteditor.h> +#include <texteditor/basetextdocument.h> +#include <texteditor/basetexteditor.h> #include <texteditor/texteditorsettings.h> #include <texteditor/texteditorconstants.h> #include <texteditor/normalindenter.h> @@ -166,8 +168,11 @@ void BarDescriptorEditorWidget::initAssetsPage() void BarDescriptorEditorWidget::initSourcePage() { - auto doc = new TextEditor::PlainTextDocument; + auto doc = new TextEditor::BaseTextDocument; + doc->setupAsPlainTextDocument(); + 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->setupAsPlainEditor(); addWidget(m_xmlSourceWidget); diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp index e2ac75a1f8..adf51216dc 100644 --- a/src/plugins/texteditor/basetextdocument.cpp +++ b/src/plugins/texteditor/basetextdocument.cpp @@ -40,6 +40,7 @@ #include "tabsettings.h" #include "texteditorconstants.h" #include "typingsettings.h" +#include <texteditor/generichighlighter/highlighter.h> #include <QApplication> #include <QDir> @@ -49,6 +50,7 @@ #include <QStringList> #include <QTextCodec> +#include <coreplugin/coreconstants.h> #include <coreplugin/icore.h> #include <coreplugin/progressmanager/progressmanager.h> #include <utils/qtcassert.h> @@ -80,6 +82,7 @@ public: public slots: void onModificationChanged(bool modified); + void updateTabSettings(); public: QString m_defaultPath; @@ -197,6 +200,12 @@ void BaseTextDocumentPrivate::onModificationChanged(bool modified) updateRevisions(); } +void BaseTextDocumentPrivate::updateTabSettings() +{ + if (Highlighter *highlighter = qobject_cast<Highlighter *>(m_highlighter)) + highlighter->setTabSettings(m_tabSettings); +} + /////////////////////////////////////////////////////////////////////// // @@ -318,6 +327,11 @@ void BaseTextDocument::triggerPendingUpdates() applyFontSettings(); } +void BaseTextDocument::setupAsPlainTextDocument() +{ + connect(this, SIGNAL(tabSettingsChanged()), d, SLOT(updateTabSettings())); +} + void BaseTextDocument::applyFontSettings() { d->m_fontSettingsNeedsApply = false; diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h index 437c843270..038491525f 100644 --- a/src/plugins/texteditor/basetextdocument.h +++ b/src/plugins/texteditor/basetextdocument.h @@ -128,6 +128,8 @@ public: virtual void triggerPendingUpdates(); + void setupAsPlainTextDocument(); + public slots: void setTabSettings(const TextEditor::TabSettings &tabSettings); void setFontSettings(const TextEditor::FontSettings &fontSettings); diff --git a/src/plugins/texteditor/plaintexteditor.cpp b/src/plugins/texteditor/plaintexteditor.cpp index aef2e551cd..84fa34c1fd 100644 --- a/src/plugins/texteditor/plaintexteditor.cpp +++ b/src/plugins/texteditor/plaintexteditor.cpp @@ -74,16 +74,4 @@ IEditor *PlainTextEditor::duplicate() return newWidget->editor(); } -PlainTextDocument::PlainTextDocument() -{ - setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); - connect(this, SIGNAL(tabSettingsChanged()), this, SLOT(updateTabSettings())); -} - -void PlainTextDocument::updateTabSettings() -{ - if (Highlighter *highlighter = qobject_cast<Highlighter *>(syntaxHighlighter())) - highlighter->setTabSettings(tabSettings()); -} - } // namespace TextEditor diff --git a/src/plugins/texteditor/plaintexteditor.h b/src/plugins/texteditor/plaintexteditor.h index 0b8dbcd971..3ef7af810c 100644 --- a/src/plugins/texteditor/plaintexteditor.h +++ b/src/plugins/texteditor/plaintexteditor.h @@ -43,15 +43,6 @@ public: Core::IEditor *duplicate(); }; -class TEXTEDITOR_EXPORT PlainTextDocument : public BaseTextDocument -{ - Q_OBJECT -public: - PlainTextDocument(); -private slots: - void updateTabSettings(); -}; - } // namespace TextEditor #endif // PLAINTEXTEDITOR_H diff --git a/src/plugins/texteditor/plaintexteditorfactory.cpp b/src/plugins/texteditor/plaintexteditorfactory.cpp index e2b11cdd2f..df66afae50 100644 --- a/src/plugins/texteditor/plaintexteditorfactory.cpp +++ b/src/plugins/texteditor/plaintexteditorfactory.cpp @@ -61,7 +61,9 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent) Core::IEditor *PlainTextEditorFactory::createEditor() { - auto doc = new PlainTextDocument; + auto doc = new BaseTextDocument; + doc->setupAsPlainTextDocument(); + doc->setId(Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); doc->setIndenter(new NormalIndenter); auto widget = new BaseTextEditorWidget(doc); widget->setupAsPlainEditor(); |