forked from qt-creator/qt-creator
Remove ITextMarkable
There was only a single user (TextEditor::DocumentMarker) which in turn was only used in a single place (BaseTextDocument), so merge the ITextMarkable into BaseTextDocument. Change-Id: I1ca8675f9fc22cb56097b843dc5a0fe76875d3e7 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -192,7 +192,7 @@ void DisassemblerAgent::resetLocation()
|
|||||||
return;
|
return;
|
||||||
if (d->resetLocationScheduled) {
|
if (d->resetLocationScheduled) {
|
||||||
d->resetLocationScheduled = false;
|
d->resetLocationScheduled = false;
|
||||||
d->document->markableInterface()->removeMark(&d->locationMark);
|
d->document->removeMark(&d->locationMark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,9 +331,9 @@ void DisassemblerAgent::updateLocationMarker()
|
|||||||
const DisassemblerLines contents = d->contentsAtCurrentLocation();
|
const DisassemblerLines contents = d->contentsAtCurrentLocation();
|
||||||
int lineNumber = contents.lineForAddress(d->location.address());
|
int lineNumber = contents.lineForAddress(d->location.address());
|
||||||
if (d->location.needsMarker()) {
|
if (d->location.needsMarker()) {
|
||||||
d->document->markableInterface()->removeMark(&d->locationMark);
|
d->document->removeMark(&d->locationMark);
|
||||||
d->locationMark.updateLineNumber(lineNumber);
|
d->locationMark.updateLineNumber(lineNumber);
|
||||||
d->document->markableInterface()->addMark(&d->locationMark);
|
d->document->addMark(&d->locationMark);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Center cursor.
|
// Center cursor.
|
||||||
@@ -354,7 +354,7 @@ void DisassemblerAgent::updateBreakpointMarkers()
|
|||||||
|
|
||||||
const DisassemblerLines contents = d->contentsAtCurrentLocation();
|
const DisassemblerLines contents = d->contentsAtCurrentLocation();
|
||||||
foreach (TextEditor::ITextMark *marker, d->breakpointMarks)
|
foreach (TextEditor::ITextMark *marker, d->breakpointMarks)
|
||||||
d->document->markableInterface()->removeMark(marker);
|
d->document->removeMark(marker);
|
||||||
qDeleteAll(d->breakpointMarks);
|
qDeleteAll(d->breakpointMarks);
|
||||||
d->breakpointMarks.clear();
|
d->breakpointMarks.clear();
|
||||||
foreach (BreakpointModelId id, ids) {
|
foreach (BreakpointModelId id, ids) {
|
||||||
@@ -368,7 +368,7 @@ void DisassemblerAgent::updateBreakpointMarkers()
|
|||||||
marker->setIcon(handler->icon(id));
|
marker->setIcon(handler->icon(id));
|
||||||
marker->setPriority(ITextMark::NormalPriority);
|
marker->setPriority(ITextMark::NormalPriority);
|
||||||
d->breakpointMarks.append(marker);
|
d->breakpointMarks.append(marker);
|
||||||
d->document->markableInterface()->addMark(marker);
|
d->document->addMark(marker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,7 +59,7 @@ public:
|
|||||||
~SourceAgentPrivate();
|
~SourceAgentPrivate();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QPointer<TextEditor::ITextEditor> editor;
|
QPointer<TextEditor::BaseTextEditor> editor;
|
||||||
QPointer<DebuggerEngine> engine;
|
QPointer<DebuggerEngine> engine;
|
||||||
TextEditor::ITextMark *locationMark;
|
TextEditor::ITextMark *locationMark;
|
||||||
QString path;
|
QString path;
|
||||||
@@ -109,23 +109,21 @@ void SourceAgent::setContent(const QString &filePath, const QString &content)
|
|||||||
if (!d->editor) {
|
if (!d->editor) {
|
||||||
QString titlePattern = d->producer + QLatin1String(": ")
|
QString titlePattern = d->producer + QLatin1String(": ")
|
||||||
+ QFileInfo(filePath).fileName();
|
+ QFileInfo(filePath).fileName();
|
||||||
d->editor = qobject_cast<ITextEditor *>(
|
d->editor = qobject_cast<BaseTextEditor *>(
|
||||||
EditorManager::openEditorWithContents(
|
EditorManager::openEditorWithContents(
|
||||||
CppEditor::Constants::CPPEDITOR_ID,
|
CppEditor::Constants::CPPEDITOR_ID,
|
||||||
&titlePattern, content.toUtf8()));
|
&titlePattern, content.toUtf8()));
|
||||||
QTC_ASSERT(d->editor, return);
|
QTC_ASSERT(d->editor, return);
|
||||||
d->editor->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
|
d->editor->document()->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
|
||||||
|
|
||||||
BaseTextEditorWidget *baseTextEdit =
|
BaseTextEditorWidget *baseTextEdit = d->editor->editorWidget();
|
||||||
qobject_cast<BaseTextEditorWidget *>(d->editor->widget());
|
|
||||||
if (baseTextEdit)
|
if (baseTextEdit)
|
||||||
baseTextEdit->setRequestMarkEnabled(true);
|
baseTextEdit->setRequestMarkEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
EditorManager::activateEditor(d->editor);
|
EditorManager::activateEditor(d->editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlainTextEdit *plainTextEdit =
|
QPlainTextEdit *plainTextEdit = d->editor->editorWidget();
|
||||||
qobject_cast<QPlainTextEdit *>(d->editor->widget());
|
|
||||||
QTC_ASSERT(plainTextEdit, return);
|
QTC_ASSERT(plainTextEdit, return);
|
||||||
plainTextEdit->setReadOnly(true);
|
plainTextEdit->setReadOnly(true);
|
||||||
|
|
||||||
@@ -137,7 +135,7 @@ void SourceAgent::updateLocationMarker()
|
|||||||
QTC_ASSERT(d->editor, return);
|
QTC_ASSERT(d->editor, return);
|
||||||
|
|
||||||
if (d->locationMark)
|
if (d->locationMark)
|
||||||
d->editor->textDocument()->markableInterface()->removeMark(d->locationMark);
|
d->editor->baseTextDocument()->removeMark(d->locationMark);
|
||||||
delete d->locationMark;
|
delete d->locationMark;
|
||||||
d->locationMark = 0;
|
d->locationMark = 0;
|
||||||
if (d->engine->stackHandler()->currentFrame().file == d->path) {
|
if (d->engine->stackHandler()->currentFrame().file == d->path) {
|
||||||
@@ -145,8 +143,8 @@ void SourceAgent::updateLocationMarker()
|
|||||||
d->locationMark = new TextEditor::ITextMark(lineNumber);
|
d->locationMark = new TextEditor::ITextMark(lineNumber);
|
||||||
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
|
d->locationMark->setIcon(debuggerCore()->locationMarkIcon());
|
||||||
d->locationMark->setPriority(TextEditor::ITextMark::HighPriority);
|
d->locationMark->setPriority(TextEditor::ITextMark::HighPriority);
|
||||||
d->editor->textDocument()->markableInterface()->addMark(d->locationMark);
|
d->editor->baseTextDocument()->addMark(d->locationMark);
|
||||||
QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(d->editor->widget());
|
QPlainTextEdit *plainTextEdit = d->editor->editorWidget();
|
||||||
QTC_ASSERT(plainTextEdit, return);
|
QTC_ASSERT(plainTextEdit, return);
|
||||||
QTextCursor tc = plainTextEdit->textCursor();
|
QTextCursor tc = plainTextEdit->textCursor();
|
||||||
QTextBlock block = tc.document()->findBlockByNumber(lineNumber - 1);
|
QTextBlock block = tc.document()->findBlockByNumber(lineNumber - 1);
|
||||||
|
@@ -92,6 +92,8 @@ public:
|
|||||||
|
|
||||||
bool m_fileIsReadOnly;
|
bool m_fileIsReadOnly;
|
||||||
int m_autoSaveRevision;
|
int m_autoSaveRevision;
|
||||||
|
|
||||||
|
TextMarks m_marksCache; // Marks not owned
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
|
BaseTextDocumentPrivate::BaseTextDocumentPrivate(BaseTextDocument *q) :
|
||||||
@@ -373,14 +375,6 @@ SyntaxHighlighter *BaseTextDocument::syntaxHighlighter() const
|
|||||||
return d->m_highlighter;
|
return d->m_highlighter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ITextMarkable *BaseTextDocument::markableInterface() const
|
|
||||||
{
|
|
||||||
BaseTextDocumentLayout *documentLayout =
|
|
||||||
qobject_cast<BaseTextDocumentLayout *>(d->m_document->documentLayout());
|
|
||||||
QTC_ASSERT(documentLayout, return 0);
|
|
||||||
return documentLayout->markableInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Saves the document to the file specified by \a fileName. If errors occur,
|
* Saves the document to the file specified by \a fileName. If errors occur,
|
||||||
* \a errorString contains their cause.
|
* \a errorString contains their cause.
|
||||||
@@ -583,7 +577,7 @@ bool BaseTextDocument::reload(QString *errorString)
|
|||||||
bool success = open(errorString, filePath(), filePath());
|
bool success = open(errorString, filePath(), filePath());
|
||||||
|
|
||||||
if (documentLayout)
|
if (documentLayout)
|
||||||
documentLayout->documentReloaded(marks); // readds text marks
|
documentLayout->documentReloaded(marks, this); // re-adds text marks
|
||||||
emit reloadFinished(success);
|
emit reloadFinished(success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -684,6 +678,130 @@ void BaseTextDocument::ensureFinalNewLine(QTextCursor& cursor)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextMarks BaseTextDocument::marks() const
|
||||||
|
{
|
||||||
|
return d->m_marksCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseTextDocument::addMark(ITextMark *mark)
|
||||||
|
{
|
||||||
|
if (mark->baseTextDocument())
|
||||||
|
return false;
|
||||||
|
QTC_ASSERT(mark->lineNumber() >= 1, return false);
|
||||||
|
int blockNumber = mark->lineNumber() - 1;
|
||||||
|
auto documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
||||||
|
QTC_ASSERT(documentLayout, return false);
|
||||||
|
QTextBlock block = d->m_document->findBlockByNumber(blockNumber);
|
||||||
|
|
||||||
|
if (block.isValid()) {
|
||||||
|
TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
|
||||||
|
userData->addMark(mark);
|
||||||
|
d->m_marksCache.append(mark);
|
||||||
|
mark->updateLineNumber(blockNumber + 1);
|
||||||
|
QTC_CHECK(mark->lineNumber() == blockNumber + 1); // Checks that the base class is called
|
||||||
|
mark->updateBlock(block);
|
||||||
|
mark->setBaseTextDocument(this);
|
||||||
|
if (!mark->isVisible())
|
||||||
|
return true;
|
||||||
|
// Update document layout
|
||||||
|
double newMaxWidthFactor = qMax(mark->widthFactor(), documentLayout->maxMarkWidthFactor);
|
||||||
|
bool fullUpdate = newMaxWidthFactor > documentLayout->maxMarkWidthFactor || !documentLayout->hasMarks;
|
||||||
|
documentLayout->hasMarks = true;
|
||||||
|
documentLayout->maxMarkWidthFactor = newMaxWidthFactor;
|
||||||
|
if (fullUpdate)
|
||||||
|
documentLayout->requestUpdate();
|
||||||
|
else
|
||||||
|
documentLayout->requestExtraAreaUpdate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextMarks BaseTextDocument::marksAt(int line) const
|
||||||
|
{
|
||||||
|
QTC_ASSERT(line >= 1, return TextMarks());
|
||||||
|
int blockNumber = line - 1;
|
||||||
|
QTextBlock block = d->m_document->findBlockByNumber(blockNumber);
|
||||||
|
|
||||||
|
if (block.isValid()) {
|
||||||
|
if (TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block))
|
||||||
|
return userData->marks();
|
||||||
|
}
|
||||||
|
return TextMarks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextDocument::removeMarkFromMarksCache(ITextMark *mark)
|
||||||
|
{
|
||||||
|
auto documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
||||||
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
d->m_marksCache.removeAll(mark);
|
||||||
|
|
||||||
|
if (d->m_marksCache.isEmpty()) {
|
||||||
|
documentLayout->hasMarks = false;
|
||||||
|
documentLayout->maxMarkWidthFactor = 1.0;
|
||||||
|
documentLayout->requestUpdate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mark->isVisible())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (documentLayout->maxMarkWidthFactor == 1.0
|
||||||
|
|| mark->widthFactor() == 1.0
|
||||||
|
|| mark->widthFactor() < documentLayout->maxMarkWidthFactor) {
|
||||||
|
// No change in width possible
|
||||||
|
documentLayout->requestExtraAreaUpdate();
|
||||||
|
} else {
|
||||||
|
double maxWidthFactor = 1.0;
|
||||||
|
foreach (const ITextMark *mark, marks()) {
|
||||||
|
if (!mark->isVisible())
|
||||||
|
continue;
|
||||||
|
maxWidthFactor = qMax(mark->widthFactor(), maxWidthFactor);
|
||||||
|
if (maxWidthFactor == documentLayout->maxMarkWidthFactor)
|
||||||
|
break; // Still a mark with the maxMarkWidthFactor
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxWidthFactor != documentLayout->maxMarkWidthFactor) {
|
||||||
|
documentLayout->maxMarkWidthFactor = maxWidthFactor;
|
||||||
|
documentLayout->requestUpdate();
|
||||||
|
} else {
|
||||||
|
documentLayout->requestExtraAreaUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextDocument::removeMark(ITextMark *mark)
|
||||||
|
{
|
||||||
|
QTextBlock block = d->m_document->findBlockByNumber(mark->lineNumber() - 1);
|
||||||
|
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
|
||||||
|
if (!data->removeMark(mark))
|
||||||
|
qDebug() << "Could not find mark" << mark << "on line" << mark->lineNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeMarkFromMarksCache(mark);
|
||||||
|
mark->setBaseTextDocument(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextDocument::updateMark(ITextMark *mark)
|
||||||
|
{
|
||||||
|
Q_UNUSED(mark)
|
||||||
|
auto documentLayout = qobject_cast<BaseTextDocumentLayout*>(d->m_document->documentLayout());
|
||||||
|
QTC_ASSERT(documentLayout, return);
|
||||||
|
documentLayout->requestUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextDocument::moveMark(ITextMark *mark, int previousLine)
|
||||||
|
{
|
||||||
|
QTextBlock block = d->m_document->findBlockByNumber(previousLine - 1);
|
||||||
|
if (TextBlockUserData *data = BaseTextDocumentLayout::testUserData(block)) {
|
||||||
|
if (!data->removeMark(mark))
|
||||||
|
qDebug() << "Could not find mark" << mark << "on line" << previousLine;
|
||||||
|
}
|
||||||
|
removeMarkFromMarksCache(mark);
|
||||||
|
mark->setBaseTextDocument(0);
|
||||||
|
addMark(mark);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#include "basetextdocument.moc"
|
#include "basetextdocument.moc"
|
||||||
|
@@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#include "itexteditor.h"
|
#include "itexteditor.h"
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTextCursor;
|
class QTextCursor;
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
@@ -44,13 +46,14 @@ namespace TextEditor {
|
|||||||
class BaseTextDocumentPrivate;
|
class BaseTextDocumentPrivate;
|
||||||
class ExtraEncodingSettings;
|
class ExtraEncodingSettings;
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
class ITextMarkable;
|
|
||||||
class Indenter;
|
class Indenter;
|
||||||
class StorageSettings;
|
class StorageSettings;
|
||||||
class SyntaxHighlighter;
|
class SyntaxHighlighter;
|
||||||
class TabSettings;
|
class TabSettings;
|
||||||
class TypingSettings;
|
class TypingSettings;
|
||||||
|
|
||||||
|
typedef QList<ITextMark *> TextMarks;
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument
|
class TEXTEDITOR_EXPORT BaseTextDocument : public ITextEditorDocument
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -81,7 +84,13 @@ public:
|
|||||||
QTextCursor indent(const QTextCursor &cursor);
|
QTextCursor indent(const QTextCursor &cursor);
|
||||||
QTextCursor unindent(const QTextCursor &cursor);
|
QTextCursor unindent(const QTextCursor &cursor);
|
||||||
|
|
||||||
ITextMarkable *markableInterface() const;
|
TextMarks marks() const;
|
||||||
|
bool addMark(ITextMark *mark);
|
||||||
|
TextMarks marksAt(int line) const;
|
||||||
|
void removeMark(ITextMark *mark);
|
||||||
|
void updateMark(ITextMark *mark);
|
||||||
|
void moveMark(ITextMark *mark, int previousLine);
|
||||||
|
void removeMarkFromMarksCache(TextEditor::ITextMark *mark);
|
||||||
|
|
||||||
// IDocument implementation.
|
// IDocument implementation.
|
||||||
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
bool save(QString *errorString, const QString &fileName, bool autoSave);
|
||||||
|
@@ -33,165 +33,6 @@
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace TextEditor {
|
|
||||||
namespace Internal {
|
|
||||||
|
|
||||||
class DocumentMarker : public ITextMarkable
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
DocumentMarker(QTextDocument *);
|
|
||||||
~DocumentMarker();
|
|
||||||
|
|
||||||
TextMarks marks() const { return m_marksCache; }
|
|
||||||
|
|
||||||
// ITextMarkable
|
|
||||||
bool addMark(ITextMark *mark);
|
|
||||||
TextMarks marksAt(int line) const;
|
|
||||||
void removeMark(ITextMark *mark);
|
|
||||||
void updateMark(ITextMark *mark);
|
|
||||||
void moveMark(ITextMark *mark, int previousLine);
|
|
||||||
|
|
||||||
void removeMarkFromMarksCache(TextEditor::ITextMark *mark);
|
|
||||||
private:
|
|
||||||
TextMarks m_marksCache; // not owned
|
|
||||||
QTextDocument *document;
|
|
||||||
};
|
|
||||||
|
|
||||||
DocumentMarker::DocumentMarker(QTextDocument *doc)
|
|
||||||
: ITextMarkable(doc), document(doc)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DocumentMarker::~DocumentMarker()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DocumentMarker::addMark(TextEditor::ITextMark *mark)
|
|
||||||
{
|
|
||||||
if (mark->markableInterface())
|
|
||||||
return false;
|
|
||||||
QTC_ASSERT(mark->lineNumber() >= 1, return false);
|
|
||||||
int blockNumber = mark->lineNumber() - 1;
|
|
||||||
BaseTextDocumentLayout *documentLayout =
|
|
||||||
qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
|
|
||||||
QTC_ASSERT(documentLayout, return false);
|
|
||||||
QTextBlock block = document->findBlockByNumber(blockNumber);
|
|
||||||
|
|
||||||
if (block.isValid()) {
|
|
||||||
TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
|
|
||||||
userData->addMark(mark);
|
|
||||||
m_marksCache.append(mark);
|
|
||||||
mark->updateLineNumber(blockNumber + 1);
|
|
||||||
QTC_CHECK(mark->lineNumber() == blockNumber + 1); // Checks that the base class is called
|
|
||||||
mark->updateBlock(block);
|
|
||||||
mark->setMarkableInterface(this);
|
|
||||||
if (!mark->isVisible())
|
|
||||||
return true;
|
|
||||||
// Update document layout
|
|
||||||
double newMaxWidthFactor = qMax(mark->widthFactor(), documentLayout->maxMarkWidthFactor);
|
|
||||||
bool fullUpdate = newMaxWidthFactor > documentLayout->maxMarkWidthFactor || !documentLayout->hasMarks;
|
|
||||||
documentLayout->hasMarks = true;
|
|
||||||
documentLayout->maxMarkWidthFactor = newMaxWidthFactor;
|
|
||||||
if (fullUpdate)
|
|
||||||
documentLayout->requestUpdate();
|
|
||||||
else
|
|
||||||
documentLayout->requestExtraAreaUpdate();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor::TextMarks DocumentMarker::marksAt(int line) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(line >= 1, return TextMarks());
|
|
||||||
int blockNumber = line - 1;
|
|
||||||
QTextBlock block = document->findBlockByNumber(blockNumber);
|
|
||||||
|
|
||||||
if (block.isValid()) {
|
|
||||||
if (TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block))
|
|
||||||
return userData->marks();
|
|
||||||
}
|
|
||||||
return TextMarks();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentMarker::removeMarkFromMarksCache(TextEditor::ITextMark *mark)
|
|
||||||
{
|
|
||||||
BaseTextDocumentLayout *documentLayout =
|
|
||||||
qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
|
|
||||||
QTC_ASSERT(documentLayout, return);
|
|
||||||
m_marksCache.removeAll(mark);
|
|
||||||
|
|
||||||
if (m_marksCache.isEmpty()) {
|
|
||||||
documentLayout->hasMarks = false;
|
|
||||||
documentLayout->maxMarkWidthFactor = 1.0;
|
|
||||||
documentLayout->requestUpdate();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mark->isVisible())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (documentLayout->maxMarkWidthFactor == 1.0
|
|
||||||
|| mark->widthFactor() == 1.0
|
|
||||||
|| mark->widthFactor() < documentLayout->maxMarkWidthFactor) {
|
|
||||||
// No change in width possible
|
|
||||||
documentLayout->requestExtraAreaUpdate();
|
|
||||||
} else {
|
|
||||||
double maxWidthFactor = 1.0;
|
|
||||||
foreach (const ITextMark *mark, marks()) {
|
|
||||||
if (!mark->isVisible())
|
|
||||||
continue;
|
|
||||||
maxWidthFactor = qMax(mark->widthFactor(), maxWidthFactor);
|
|
||||||
if (maxWidthFactor == documentLayout->maxMarkWidthFactor)
|
|
||||||
break; // Still a mark with the maxMarkWidthFactor
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxWidthFactor != documentLayout->maxMarkWidthFactor) {
|
|
||||||
documentLayout->maxMarkWidthFactor = maxWidthFactor;
|
|
||||||
documentLayout->requestUpdate();
|
|
||||||
} else {
|
|
||||||
documentLayout->requestExtraAreaUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentMarker::removeMark(TextEditor::ITextMark *mark)
|
|
||||||
{
|
|
||||||
QTextBlock block = document->findBlockByNumber(mark->lineNumber() - 1);
|
|
||||||
if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) {
|
|
||||||
if (!data->removeMark(mark))
|
|
||||||
qDebug() << "Could not find mark" << mark << "on line" << mark->lineNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
removeMarkFromMarksCache(mark);
|
|
||||||
mark->setMarkableInterface(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentMarker::updateMark(ITextMark *mark)
|
|
||||||
{
|
|
||||||
Q_UNUSED(mark)
|
|
||||||
BaseTextDocumentLayout *documentLayout =
|
|
||||||
qobject_cast<BaseTextDocumentLayout*>(document->documentLayout());
|
|
||||||
QTC_ASSERT(documentLayout, return);
|
|
||||||
documentLayout->requestUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DocumentMarker::moveMark(ITextMark *mark, int previousLine)
|
|
||||||
{
|
|
||||||
QTextBlock block = document->findBlockByNumber(previousLine - 1);
|
|
||||||
if (TextBlockUserData *data = BaseTextDocumentLayout::testUserData(block)) {
|
|
||||||
if (!data->removeMark(mark))
|
|
||||||
qDebug() << "Could not find mark" << mark << "on line" << previousLine;
|
|
||||||
}
|
|
||||||
removeMarkFromMarksCache(mark);
|
|
||||||
mark->setMarkableInterface(0);
|
|
||||||
addMark(mark);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace TextEditor
|
|
||||||
|
|
||||||
CodeFormatterData::~CodeFormatterData()
|
CodeFormatterData::~CodeFormatterData()
|
||||||
{
|
{
|
||||||
@@ -200,10 +41,8 @@ CodeFormatterData::~CodeFormatterData()
|
|||||||
TextBlockUserData::~TextBlockUserData()
|
TextBlockUserData::~TextBlockUserData()
|
||||||
{
|
{
|
||||||
foreach (ITextMark *mrk, m_marks) {
|
foreach (ITextMark *mrk, m_marks) {
|
||||||
TextEditor::Internal::DocumentMarker *documentMarker
|
mrk->baseTextDocument()->removeMarkFromMarksCache(mrk);
|
||||||
= static_cast<TextEditor::Internal::DocumentMarker *>(mrk->markableInterface());
|
mrk->setBaseTextDocument(0);
|
||||||
documentMarker->removeMarkFromMarksCache(mrk);
|
|
||||||
mrk->setMarkableInterface(0);
|
|
||||||
mrk->removedFromEditor();
|
mrk->removedFromEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,11 +392,8 @@ BaseTextDocumentLayout::BaseTextDocumentLayout(QTextDocument *doc)
|
|||||||
lastSaveRevision(0),
|
lastSaveRevision(0),
|
||||||
hasMarks(false),
|
hasMarks(false),
|
||||||
maxMarkWidthFactor(1.0),
|
maxMarkWidthFactor(1.0),
|
||||||
m_requiredWidth(0),
|
m_requiredWidth(0)
|
||||||
m_documentMarker(new Internal::DocumentMarker(doc))
|
{}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseTextDocumentLayout::~BaseTextDocumentLayout()
|
BaseTextDocumentLayout::~BaseTextDocumentLayout()
|
||||||
{
|
{
|
||||||
@@ -702,11 +538,6 @@ void BaseTextDocumentLayout::requestExtraAreaUpdate()
|
|||||||
emit updateExtraArea();
|
emit updateExtraArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
ITextMarkable *BaseTextDocumentLayout::markableInterface()
|
|
||||||
{
|
|
||||||
return m_documentMarker;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseTextDocumentLayout::doFoldOrUnfold(const QTextBlock& block, bool unfold)
|
void BaseTextDocumentLayout::doFoldOrUnfold(const QTextBlock& block, bool unfold)
|
||||||
{
|
{
|
||||||
if (!canFold(block))
|
if (!canFold(block))
|
||||||
@@ -760,7 +591,7 @@ TextMarks BaseTextDocumentLayout::documentClosing()
|
|||||||
return marks;
|
return marks;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextDocumentLayout::documentReloaded(TextMarks marks)
|
void BaseTextDocumentLayout::documentReloaded(TextMarks marks, BaseTextDocument *baseTextDocument)
|
||||||
{
|
{
|
||||||
foreach (ITextMark *mark, marks) {
|
foreach (ITextMark *mark, marks) {
|
||||||
int blockNumber = mark->lineNumber() - 1;
|
int blockNumber = mark->lineNumber() - 1;
|
||||||
@@ -768,14 +599,12 @@ void BaseTextDocumentLayout::documentReloaded(TextMarks marks)
|
|||||||
if (block.isValid()) {
|
if (block.isValid()) {
|
||||||
TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
|
TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
|
||||||
userData->addMark(mark);
|
userData->addMark(mark);
|
||||||
mark->setMarkableInterface(m_documentMarker);
|
mark->setBaseTextDocument(baseTextDocument);
|
||||||
mark->updateBlock(block);
|
mark->updateBlock(block);
|
||||||
} else {
|
} else {
|
||||||
TextEditor::Internal::DocumentMarker *documentMarker
|
baseTextDocument->removeMarkFromMarksCache(mark);
|
||||||
= static_cast<TextEditor::Internal::DocumentMarker *>(m_documentMarker);
|
|
||||||
documentMarker->removeMarkFromMarksCache(mark);
|
|
||||||
mark->removedFromEditor();
|
mark->removedFromEditor();
|
||||||
mark->setMarkableInterface(0);
|
mark->setBaseTextDocument(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
@@ -868,5 +697,3 @@ void BaseTextDocumentLayout::FoldValidator::finalize()
|
|||||||
m_layout->emitDocumentSizeChanged();
|
m_layout->emitDocumentSizeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "basetextdocumentlayout.moc"
|
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include "texteditor_global.h"
|
#include "texteditor_global.h"
|
||||||
|
|
||||||
#include "itexteditor.h"
|
#include "basetexteditor.h"
|
||||||
|
|
||||||
#include <QTextBlockUserData>
|
#include <QTextBlockUserData>
|
||||||
#include <QPlainTextDocumentLayout>
|
#include <QPlainTextDocumentLayout>
|
||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
inline TextMarks documentClosing() {
|
inline TextMarks documentClosing() {
|
||||||
TextMarks marks = m_marks;
|
TextMarks marks = m_marks;
|
||||||
foreach (ITextMark *mrk, m_marks)
|
foreach (ITextMark *mrk, m_marks)
|
||||||
mrk->setMarkableInterface(0);
|
mrk->setBaseTextDocument(0);
|
||||||
m_marks.clear();
|
m_marks.clear();
|
||||||
return marks;
|
return marks;
|
||||||
}
|
}
|
||||||
@@ -205,21 +205,19 @@ public:
|
|||||||
void requestExtraAreaUpdate();
|
void requestExtraAreaUpdate();
|
||||||
|
|
||||||
void emitDocumentSizeChanged() { emit documentSizeChanged(documentSize()); }
|
void emitDocumentSizeChanged() { emit documentSizeChanged(documentSize()); }
|
||||||
ITextMarkable *markableInterface();
|
|
||||||
|
|
||||||
int lastSaveRevision;
|
int lastSaveRevision;
|
||||||
bool hasMarks;
|
bool hasMarks;
|
||||||
double maxMarkWidthFactor;
|
double maxMarkWidthFactor;
|
||||||
|
|
||||||
int m_requiredWidth;
|
int m_requiredWidth;
|
||||||
ITextMarkable *m_documentMarker;
|
|
||||||
|
|
||||||
void setRequiredWidth(int width);
|
void setRequiredWidth(int width);
|
||||||
|
|
||||||
QSizeF documentSize() const;
|
QSizeF documentSize() const;
|
||||||
|
|
||||||
TextMarks documentClosing();
|
TextMarks documentClosing();
|
||||||
void documentReloaded(TextMarks marks);
|
void documentReloaded(TextMarks marks, BaseTextDocument *baseextDocument);
|
||||||
void updateMarksLineNumber();
|
void updateMarksLineNumber();
|
||||||
void updateMarksBlock(const QTextBlock &block);
|
void updateMarksBlock(const QTextBlock &block);
|
||||||
|
|
||||||
|
@@ -67,8 +67,6 @@ namespace Internal {
|
|||||||
typedef QString (QString::*TransformationMethod)() const;
|
typedef QString (QString::*TransformationMethod)() const;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ITextMarkable;
|
|
||||||
|
|
||||||
class BaseTextEditor;
|
class BaseTextEditor;
|
||||||
class FontSettings;
|
class FontSettings;
|
||||||
class BehaviorSettings;
|
class BehaviorSettings;
|
||||||
|
@@ -59,11 +59,10 @@ BaseTextMarkRegistry::BaseTextMarkRegistry(QObject *parent)
|
|||||||
void BaseTextMarkRegistry::add(BaseTextMark *mark)
|
void BaseTextMarkRegistry::add(BaseTextMark *mark)
|
||||||
{
|
{
|
||||||
m_marks[FileName::fromString(mark->fileName())].insert(mark);
|
m_marks[FileName::fromString(mark->fileName())].insert(mark);
|
||||||
ITextEditorDocument *document
|
auto document = qobject_cast<BaseTextDocument*>(DocumentModel::documentForFilePath(mark->fileName()));
|
||||||
= qobject_cast<ITextEditorDocument*>(DocumentModel::documentForFilePath(mark->fileName()));
|
|
||||||
if (!document)
|
if (!document)
|
||||||
return;
|
return;
|
||||||
document->markableInterface()->addMark(mark);
|
document->addMark(mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
|
bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
|
||||||
@@ -73,14 +72,14 @@ bool BaseTextMarkRegistry::remove(BaseTextMark *mark)
|
|||||||
|
|
||||||
void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
|
void BaseTextMarkRegistry::editorOpened(Core::IEditor *editor)
|
||||||
{
|
{
|
||||||
ITextEditorDocument *document = qobject_cast<ITextEditorDocument *>(editor ? editor->document() : 0);
|
auto document = qobject_cast<BaseTextDocument *>(editor ? editor->document() : 0);
|
||||||
if (!document)
|
if (!document)
|
||||||
return;
|
return;
|
||||||
if (!m_marks.contains(FileName::fromString(document->filePath())))
|
if (!m_marks.contains(FileName::fromString(document->filePath())))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (BaseTextMark *mark, m_marks.value(FileName::fromString(document->filePath())))
|
foreach (BaseTextMark *mark, m_marks.value(FileName::fromString(document->filePath())))
|
||||||
document->markableInterface()->addMark(mark);
|
document->addMark(mark);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
|
void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
|
||||||
@@ -96,7 +95,7 @@ void BaseTextMarkRegistry::documentRenamed(IDocument *document, const
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QSet<BaseTextMark *> toBeMoved;
|
QSet<BaseTextMark *> toBeMoved;
|
||||||
foreach (ITextMark *mark, baseTextDocument->markableInterface()->marks())
|
foreach (ITextMark *mark, baseTextDocument->marks())
|
||||||
if (BaseTextMark *baseTextMark = dynamic_cast<BaseTextMark *>(mark))
|
if (BaseTextMark *baseTextMark = dynamic_cast<BaseTextMark *>(mark))
|
||||||
toBeMoved.insert(baseTextMark);
|
toBeMoved.insert(baseTextMark);
|
||||||
|
|
||||||
|
@@ -36,8 +36,6 @@
|
|||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
namespace Internal { class BaseTextMarkRegistry; }
|
namespace Internal { class BaseTextMarkRegistry; }
|
||||||
|
|
||||||
class ITextMarkable;
|
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT BaseTextMark : public TextEditor::ITextMark
|
class TEXTEDITOR_EXPORT BaseTextMark : public TextEditor::ITextMark
|
||||||
{
|
{
|
||||||
friend class Internal::BaseTextMarkRegistry;
|
friend class Internal::BaseTextMarkRegistry;
|
||||||
|
@@ -83,8 +83,6 @@ public:
|
|||||||
virtual QString textAt(int pos, int length) const = 0;
|
virtual QString textAt(int pos, int length) const = 0;
|
||||||
virtual QChar characterAt(int pos) const = 0;
|
virtual QChar characterAt(int pos) const = 0;
|
||||||
|
|
||||||
virtual ITextMarkable *markableInterface() const = 0;
|
|
||||||
|
|
||||||
static QMap<QString, QString> openedTextDocumentContents();
|
static QMap<QString, QString> openedTextDocumentContents();
|
||||||
static QMap<QString, QTextCodec *> openedTextDocumentEncodings();
|
static QMap<QString, QTextCodec *> openedTextDocumentEncodings();
|
||||||
|
|
||||||
|
@@ -28,14 +28,15 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "itextmark.h"
|
#include "itextmark.h"
|
||||||
|
#include "basetextdocument.h"
|
||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
ITextMark::~ITextMark()
|
ITextMark::~ITextMark()
|
||||||
{
|
{
|
||||||
if (m_markableInterface)
|
if (m_baseTextDocument)
|
||||||
m_markableInterface->removeMark(this);
|
m_baseTextDocument->removeMark(this);
|
||||||
m_markableInterface = 0;
|
m_baseTextDocument = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ITextMark::lineNumber() const
|
int ITextMark::lineNumber() const
|
||||||
@@ -59,8 +60,8 @@ void ITextMark::move(int line)
|
|||||||
return;
|
return;
|
||||||
const int previousLine = m_lineNumber;
|
const int previousLine = m_lineNumber;
|
||||||
m_lineNumber = line;
|
m_lineNumber = line;
|
||||||
if (m_markableInterface)
|
if (m_baseTextDocument)
|
||||||
m_markableInterface->moveMark(this, previousLine);
|
m_baseTextDocument->moveMark(this, previousLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITextMark::updateBlock(const QTextBlock &)
|
void ITextMark::updateBlock(const QTextBlock &)
|
||||||
@@ -76,8 +77,8 @@ void ITextMark::setIcon(const QIcon &icon)
|
|||||||
|
|
||||||
void ITextMark::updateMarker()
|
void ITextMark::updateMarker()
|
||||||
{
|
{
|
||||||
if (m_markableInterface)
|
if (m_baseTextDocument)
|
||||||
m_markableInterface->updateMark(this);
|
m_baseTextDocument->updateMark(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITextMark::setPriority(Priority priority)
|
void ITextMark::setPriority(Priority priority)
|
||||||
@@ -98,8 +99,8 @@ bool ITextMark::isVisible() const
|
|||||||
void ITextMark::setVisible(bool visible)
|
void ITextMark::setVisible(bool visible)
|
||||||
{
|
{
|
||||||
m_visible = visible;
|
m_visible = visible;
|
||||||
if (m_markableInterface)
|
if (m_baseTextDocument)
|
||||||
m_markableInterface->updateMark(this);
|
m_baseTextDocument->updateMark(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
double ITextMark::widthFactor() const
|
double ITextMark::widthFactor() const
|
||||||
@@ -130,13 +131,13 @@ void ITextMark::dragToLine(int lineNumber)
|
|||||||
Q_UNUSED(lineNumber);
|
Q_UNUSED(lineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
ITextMarkable *ITextMark::markableInterface() const
|
BaseTextDocument *ITextMark::baseTextDocument() const
|
||||||
{
|
{
|
||||||
return m_markableInterface;
|
return m_baseTextDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITextMark::setMarkableInterface(ITextMarkable *markableInterface)
|
void ITextMark::setBaseTextDocument(BaseTextDocument *baseTextDocument)
|
||||||
{
|
{
|
||||||
m_markableInterface = markableInterface;
|
m_baseTextDocument = baseTextDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -33,11 +33,9 @@
|
|||||||
#include "texteditor_global.h"
|
#include "texteditor_global.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QList>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QIcon;
|
|
||||||
class QPainter;
|
class QPainter;
|
||||||
class QRect;
|
class QRect;
|
||||||
class QTextBlock;
|
class QTextBlock;
|
||||||
@@ -46,13 +44,13 @@ QT_END_NAMESPACE
|
|||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class ITextEditor;
|
class ITextEditor;
|
||||||
class ITextMarkable;
|
class BaseTextDocument;
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT ITextMark
|
class TEXTEDITOR_EXPORT ITextMark
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ITextMark(int line)
|
ITextMark(int line)
|
||||||
: m_markableInterface(0),
|
: m_baseTextDocument(0),
|
||||||
m_lineNumber(line),
|
m_lineNumber(line),
|
||||||
m_priority(NormalPriority),
|
m_priority(NormalPriority),
|
||||||
m_visible(true),
|
m_visible(true),
|
||||||
@@ -89,11 +87,12 @@ public:
|
|||||||
double widthFactor() const;
|
double widthFactor() const;
|
||||||
void setWidthFactor(double factor);
|
void setWidthFactor(double factor);
|
||||||
|
|
||||||
ITextMarkable *markableInterface() const;
|
BaseTextDocument *baseTextDocument() const;
|
||||||
void setMarkableInterface(ITextMarkable *markableInterface);
|
void setBaseTextDocument(BaseTextDocument *baseTextDocument);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(ITextMark)
|
Q_DISABLE_COPY(ITextMark)
|
||||||
ITextMarkable *m_markableInterface;
|
BaseTextDocument *m_baseTextDocument;
|
||||||
int m_lineNumber;
|
int m_lineNumber;
|
||||||
Priority m_priority;
|
Priority m_priority;
|
||||||
bool m_visible;
|
bool m_visible;
|
||||||
@@ -101,23 +100,6 @@ private:
|
|||||||
double m_widthFactor;
|
double m_widthFactor;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QList<ITextMark *> TextMarks;
|
|
||||||
|
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT ITextMarkable : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ITextMarkable(QObject *parent = 0) : QObject(parent) {}
|
|
||||||
|
|
||||||
virtual TextMarks marks() const = 0;
|
|
||||||
virtual bool addMark(ITextMark *mark) = 0;
|
|
||||||
virtual TextMarks marksAt(int line) const = 0;
|
|
||||||
virtual void removeMark(ITextMark *mark) = 0;
|
|
||||||
virtual void updateMark(ITextMark *mark) = 0;
|
|
||||||
virtual void moveMark(ITextMark *mark, int previousLine) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|
||||||
#endif // ITEXTMARK_H
|
#endif // ITEXTMARK_H
|
||||||
|
Reference in New Issue
Block a user