forked from qt-creator/qt-creator
TextEditor: modernize TextDocument
Change-Id: I9ea17165ba4eade89a6119135378793256e13358 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -77,18 +77,14 @@ namespace TextEditor {
|
|||||||
class TextDocumentPrivate
|
class TextDocumentPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TextDocumentPrivate() :
|
TextDocumentPrivate()
|
||||||
m_fontSettingsNeedsApply(false),
|
: m_indenter(new Indenter)
|
||||||
m_highlighter(0),
|
|
||||||
m_completionAssistProvider(0),
|
|
||||||
m_indenter(new Indenter),
|
|
||||||
m_fileIsReadOnly(false),
|
|
||||||
m_autoSaveRevision(-1)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QTextCursor indentOrUnindent(const QTextCursor &textCursor, bool doIndent,
|
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 resetRevisions();
|
||||||
void updateRevisions();
|
void updateRevisions();
|
||||||
|
|
||||||
@@ -100,14 +96,14 @@ public:
|
|||||||
TabSettings m_tabSettings;
|
TabSettings m_tabSettings;
|
||||||
ExtraEncodingSettings m_extraEncodingSettings;
|
ExtraEncodingSettings m_extraEncodingSettings;
|
||||||
FontSettings m_fontSettings;
|
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;
|
QTextDocument m_document;
|
||||||
SyntaxHighlighter *m_highlighter;
|
SyntaxHighlighter *m_highlighter = nullptr;
|
||||||
CompletionAssistProvider *m_completionAssistProvider;
|
CompletionAssistProvider *m_completionAssistProvider = nullptr;
|
||||||
QScopedPointer<Indenter> m_indenter;
|
QScopedPointer<Indenter> m_indenter;
|
||||||
|
|
||||||
bool m_fileIsReadOnly;
|
bool m_fileIsReadOnly = false;
|
||||||
int m_autoSaveRevision;
|
int m_autoSaveRevision = -1;
|
||||||
|
|
||||||
TextMarks m_marksCache; // Marks not owned
|
TextMarks m_marksCache; // Marks not owned
|
||||||
Utils::Guard m_modificationChangedGuard;
|
Utils::Guard m_modificationChangedGuard;
|
||||||
@@ -181,7 +177,7 @@ QTextCursor TextDocumentPrivate::indentOrUnindent(const QTextCursor &textCursor,
|
|||||||
text = block.text();
|
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 spaces = ts.spacesLeftFromPosition(text, indentPosition);
|
||||||
int startColumn = ts.columnAt(text, indentPosition - spaces);
|
int startColumn = ts.columnAt(text, indentPosition - spaces);
|
||||||
int targetColumn = ts.indentedColumn(ts.columnAt(text, indentPosition), doIndent);
|
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()) {
|
for (QTextBlock it = document()->begin(); it.isValid(); it = it.next()) {
|
||||||
TextBlockUserData *userData = TextDocumentLayout::testUserData(it);
|
TextBlockUserData *userData = TextDocumentLayout::testUserData(it);
|
||||||
if (userData)
|
if (userData)
|
||||||
userData->setCodeFormatterData(0);
|
userData->setCodeFormatterData(nullptr);
|
||||||
}
|
}
|
||||||
d->m_indenter.reset(indenter);
|
d->m_indenter.reset(indenter);
|
||||||
}
|
}
|
||||||
@@ -506,7 +502,7 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool
|
|||||||
QTextCursor cursor(&d->m_document);
|
QTextCursor cursor(&d->m_document);
|
||||||
|
|
||||||
// When autosaving, we don't want to modify the document/location under the user's fingers.
|
// 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 savedPosition = 0;
|
||||||
int savedAnchor = 0;
|
int savedAnchor = 0;
|
||||||
int savedVScrollBarValue = 0;
|
int savedVScrollBarValue = 0;
|
||||||
@@ -979,7 +975,7 @@ void TextDocument::removeMark(TextMark *mark)
|
|||||||
|
|
||||||
removeMarkFromMarksCache(mark);
|
removeMarkFromMarksCache(mark);
|
||||||
emit markRemoved(mark);
|
emit markRemoved(mark);
|
||||||
mark->setBaseTextDocument(0);
|
mark->setBaseTextDocument(nullptr);
|
||||||
updateLayout();
|
updateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1003,7 +999,7 @@ void TextDocument::moveMark(TextMark *mark, int previousLine)
|
|||||||
qDebug() << "Could not find mark" << mark << "on line" << previousLine;
|
qDebug() << "Could not find mark" << mark << "on line" << previousLine;
|
||||||
}
|
}
|
||||||
removeMarkFromMarksCache(mark);
|
removeMarkFromMarksCache(mark);
|
||||||
mark->setBaseTextDocument(0);
|
mark->setBaseTextDocument(nullptr);
|
||||||
addMark(mark);
|
addMark(mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ public:
|
|||||||
void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
|
void autoIndent(const QTextCursor &cursor, QChar typedChar = QChar::Null);
|
||||||
void autoReindent(const QTextCursor &cursor);
|
void autoReindent(const QTextCursor &cursor);
|
||||||
QTextCursor indent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
|
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,
|
QTextCursor unindent(const QTextCursor &cursor, bool blockSelection = false, int column = 0,
|
||||||
int *offset = 0);
|
int *offset = nullptr);
|
||||||
|
|
||||||
TextMarks marks() const;
|
TextMarks marks() const;
|
||||||
bool addMark(TextMark *mark);
|
bool addMark(TextMark *mark);
|
||||||
|
|||||||
Reference in New Issue
Block a user