From e10b220189a302c89ee14f47290224f2fe528e66 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 15 Feb 2018 08:34:26 +0100 Subject: [PATCH] TextEditor: modernize TextDocument Change-Id: I9ea17165ba4eade89a6119135378793256e13358 Reviewed-by: hjk --- src/plugins/texteditor/textdocument.cpp | 32 +++++++++++-------------- src/plugins/texteditor/textdocument.h | 4 ++-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index 76aa718c1bf..63d29f1dcd7 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -77,18 +77,14 @@ namespace TextEditor { class TextDocumentPrivate { public: - TextDocumentPrivate() : - m_fontSettingsNeedsApply(false), - m_highlighter(0), - m_completionAssistProvider(0), - m_indenter(new Indenter), - m_fileIsReadOnly(false), - m_autoSaveRevision(-1) + TextDocumentPrivate() + : m_indenter(new Indenter) { } QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent, - bool blockSelection = false, int column = 0, int *offset = 0); + bool blockSelection = false, int column = 0, + int *offset = nullptr); void resetRevisions(); void updateRevisions(); @@ -100,14 +96,14 @@ public: TabSettings m_tabSettings; ExtraEncodingSettings m_extraEncodingSettings; FontSettings m_fontSettings; - bool m_fontSettingsNeedsApply; // for applying font settings delayed till an editor becomes visible + bool m_fontSettingsNeedsApply = false; // for applying font settings delayed till an editor becomes visible QTextDocument m_document; - SyntaxHighlighter *m_highlighter; - CompletionAssistProvider *m_completionAssistProvider; + SyntaxHighlighter *m_highlighter = nullptr; + CompletionAssistProvider *m_completionAssistProvider = nullptr; QScopedPointer m_indenter; - bool m_fileIsReadOnly; - int m_autoSaveRevision; + bool m_fileIsReadOnly = false; + int m_autoSaveRevision = -1; TextMarks m_marksCache; // Marks not owned Utils::Guard m_modificationChangedGuard; @@ -181,7 +177,7 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor, text = block.text(); } - int indentPosition = ts.positionAtColumn(text, column, 0, true); + int indentPosition = ts.positionAtColumn(text, column, nullptr, true); int spaces = ts.spacesLeftFromPosition(text, indentPosition); int startColumn = ts.columnAt(text, indentPosition - spaces); int targetColumn = ts.indentedColumn(ts.columnAt(text, indentPosition), doIndent); @@ -449,7 +445,7 @@ void TextDocument::setIndenter(Indenter *indenter) for (QTextBlock it = document()->begin(); it.isValid(); it = it.next()) { TextBlockUserData *userData = TextDocumentLayout::testUserData(it); if (userData) - userData->setCodeFormatterData(0); + userData->setCodeFormatterData(nullptr); } d->m_indenter.reset(indenter); } @@ -506,7 +502,7 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool QTextCursor cursor(&d->m_document); // When autosaving, we don't want to modify the document/location under the user's fingers. - TextEditorWidget *editorWidget = 0; + TextEditorWidget *editorWidget = nullptr; int savedPosition = 0; int savedAnchor = 0; int savedVScrollBarValue = 0; @@ -979,7 +975,7 @@ void TextDocument::removeMark(TextMark *mark) removeMarkFromMarksCache(mark); emit markRemoved(mark); - mark->setBaseTextDocument(0); + mark->setBaseTextDocument(nullptr); updateLayout(); } @@ -1003,7 +999,7 @@ void TextDocument::moveMark(TextMark *mark, int previousLine) qDebug() << "Could not find mark" << mark << "on line" << previousLine; } removeMarkFromMarksCache(mark); - mark->setBaseTextDocument(0); + mark->setBaseTextDocument(nullptr); addMark(mark); } diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index 89b2d413f05..8a4e05a4f7d 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -89,9 +89,9 @@ public: void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null); void autoReindent(const QTextCursor &cursor); QTextCursor indent(const QTextCursor &cursor, bool blockSelection = false, int column = 0, - int *offset = 0); + int *offset = nullptr); QTextCursor unindent(const QTextCursor &cursor, bool blockSelection = false, int column = 0, - int *offset = 0); + int *offset = nullptr); TextMarks marks() const; bool addMark(TextMark *mark);