diff options
author | Daniel Teske <daniel.teske@nokia.com> | 2012-03-30 11:40:31 +0200 |
---|---|---|
committer | Daniel Teske <daniel.teske@nokia.com> | 2012-04-05 11:59:09 +0200 |
commit | 20efc0a6f684121f6a9faca555d82b65020af0a0 (patch) | |
tree | 4b9df4b8f6fce47c403d5a1640bc3d13f7603be9 /src/plugins/texteditor/basetextdocumentlayout.cpp | |
parent | eb74931dd7ea289600f21585f21ff04bbb7b18e0 (diff) | |
download | qt-creator-20efc0a6f684121f6a9faca555d82b65020af0a0.tar.gz |
Fix reloading removing all BaseTextMarks
It was already broken in 2.4.
Task-number: QTCREATORBUG-7110
Change-Id: I24fae889c67ba5436548b7534d7257b6680a8c81
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Diffstat (limited to 'src/plugins/texteditor/basetextdocumentlayout.cpp')
-rw-r--r-- | src/plugins/texteditor/basetextdocumentlayout.cpp | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/src/plugins/texteditor/basetextdocumentlayout.cpp b/src/plugins/texteditor/basetextdocumentlayout.cpp index 66ac014c9b..5378421834 100644 --- a/src/plugins/texteditor/basetextdocumentlayout.cpp +++ b/src/plugins/texteditor/basetextdocumentlayout.cpp @@ -53,6 +53,7 @@ public: void removeMark(ITextMark *mark); void updateMark(ITextMark *mark); + void removeMarkFromMarksCache(TextEditor::ITextMark *mark); private: double recalculateMaxMarkWidthFactor() const; @@ -72,6 +73,8 @@ 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 = @@ -90,6 +93,7 @@ bool DocumentMarker::addMark(TextEditor::ITextMark *mark) documentLayout->maxMarkWidthFactor = qMax(mark->widthFactor(), documentLayout->maxMarkWidthFactor); documentLayout->requestUpdate(); + mark->setMarkableInterface(this); return true; } return false; @@ -116,26 +120,38 @@ TextEditor::TextMarks DocumentMarker::marksAt(int line) const return TextMarks(); } +void DocumentMarker::removeMarkFromMarksCache(TextEditor::ITextMark *mark) +{ + BaseTextDocumentLayout *documentLayout = + qobject_cast<BaseTextDocumentLayout*>(document->documentLayout()); + QTC_ASSERT(documentLayout, return) + bool needUpdate = m_marksCache.removeOne(mark); + if (m_marksCache.isEmpty()) { + documentLayout->hasMarks = false; + needUpdate = true; + } + + if (needUpdate) { + documentLayout->maxMarkWidthFactor = recalculateMaxMarkWidthFactor(); + updateMark(0); + } +} + void DocumentMarker::removeMark(TextEditor::ITextMark *mark) { BaseTextDocumentLayout *documentLayout = qobject_cast<BaseTextDocumentLayout*>(document->documentLayout()); QTC_ASSERT(documentLayout, return) - bool needUpdate = false; QTextBlock block = document->begin(); while (block.isValid()) { if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) { - needUpdate |= data->removeMark(mark); + data->removeMark(mark); } block = block.next(); } - m_marksCache.removeAll(mark); - - if (needUpdate) { - documentLayout->maxMarkWidthFactor = recalculateMaxMarkWidthFactor(); - updateMark(0); - } + removeMarkFromMarksCache(mark); + mark->setMarkableInterface(0); } void DocumentMarker::updateMark(ITextMark *mark) @@ -159,6 +175,10 @@ TextBlockUserData::~TextBlockUserData() TextMarks marks = m_marks; m_marks.clear(); foreach (ITextMark *mrk, marks) { + TextEditor::Internal::DocumentMarker *documentMarker + = static_cast<TextEditor::Internal::DocumentMarker *>(mrk->markableInterface()); + documentMarker->removeMarkFromMarksCache(mrk); + mrk->setMarkableInterface(0); mrk->removedFromEditor(); } @@ -703,16 +723,37 @@ QSizeF BaseTextDocumentLayout::documentSize() const return size; } -void BaseTextDocumentLayout::documentClosing() +TextMarks BaseTextDocumentLayout::documentClosing() { + TextMarks marks; QTextBlock block = document()->begin(); while (block.isValid()) { if (TextBlockUserData *data = static_cast<TextBlockUserData *>(block.userData())) - data->documentClosing(); + marks.append(data->documentClosing()); block = block.next(); } + return marks; } +void BaseTextDocumentLayout::documentReloaded(TextMarks marks) +{ + foreach (ITextMark *mark, marks) { + int blockNumber = mark->lineNumber() - 1; + QTextBlock block = document()->findBlockByNumber(blockNumber); + if (block.isValid()) { + TextBlockUserData *userData = BaseTextDocumentLayout::userData(block); + userData->addMark(mark); + mark->setMarkableInterface(m_documentMarker); + mark->updateBlock(block); + } else { + TextEditor::Internal::DocumentMarker *documentMarker + = static_cast<TextEditor::Internal::DocumentMarker *>(m_documentMarker); + documentMarker->removeMarkFromMarksCache(mark); + mark->removedFromEditor(); + } + } + requestUpdate(); +} void BaseTextDocumentLayout::updateMarksLineNumber() { |