Commit b9016b90 authored by Daniel Teske's avatar Daniel Teske
Browse files

Move mark related functions to BaseTextDocumentLayout



BaseTextDocument::updateMarksLineNumber() and updateMarksBlock()

Change-Id: I407cddcbe3133a5e8af960d39fe8d499b640c708
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent 502e8ab3
...@@ -578,6 +578,27 @@ QSizeF BaseTextDocumentLayout::documentSize() const ...@@ -578,6 +578,27 @@ QSizeF BaseTextDocumentLayout::documentSize() const
return size; return size;
} }
void BaseTextDocumentLayout::updateMarksLineNumber()
{
QTextBlock block = document()->begin();
int blockNumber = 0;
while (block.isValid()) {
if (const TextBlockUserData *userData = testUserData(block))
foreach (ITextMark *mrk, userData->marks()) {
mrk->updateLineNumber(blockNumber + 1);
}
block = block.next();
++blockNumber;
}
}
void BaseTextDocumentLayout::updateMarksBlock(const QTextBlock &block)
{
if (const TextBlockUserData *userData = testUserData(block))
foreach (ITextMark *mrk, userData->marks())
mrk->updateBlock(block);
}
BaseTextDocumentLayout::FoldValidator::FoldValidator() BaseTextDocumentLayout::FoldValidator::FoldValidator()
: m_layout(0) : m_layout(0)
, m_requestDocUpdate(false) , m_requestDocUpdate(false)
......
...@@ -211,6 +211,8 @@ public: ...@@ -211,6 +211,8 @@ public:
QSizeF documentSize() const; QSizeF documentSize() const;
void updateMarksLineNumber();
void updateMarksBlock(const QTextBlock &block);
}; };
} // namespace TextEditor } // namespace TextEditor
......
...@@ -675,20 +675,21 @@ void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved, ...@@ -675,20 +675,21 @@ void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved,
d->m_contentsChanged = true; d->m_contentsChanged = true;
QTextDocument *doc = document(); QTextDocument *doc = document();
BaseTextDocumentLayout *documentLayout = static_cast<BaseTextDocumentLayout*>(doc->documentLayout());
// Keep the line numbers and the block information for the text marks updated // Keep the line numbers and the block information for the text marks updated
if (charsRemoved != 0) { if (charsRemoved != 0) {
d->updateMarksLineNumber(); documentLayout->updateMarksLineNumber();
d->updateMarksBlock(document()->findBlock(position)); documentLayout->updateMarksBlock(document()->findBlock(position));
} else { } else {
const QTextBlock posBlock = doc->findBlock(position); const QTextBlock posBlock = doc->findBlock(position);
const QTextBlock nextBlock = doc->findBlock(position + charsAdded); const QTextBlock nextBlock = doc->findBlock(position + charsAdded);
if (posBlock != nextBlock) { if (posBlock != nextBlock) {
d->updateMarksLineNumber(); documentLayout->updateMarksLineNumber();
d->updateMarksBlock(posBlock); documentLayout->updateMarksBlock(posBlock);
d->updateMarksBlock(nextBlock); documentLayout->updateMarksBlock(nextBlock);
} else { } else {
d->updateMarksBlock(posBlock); documentLayout->updateMarksBlock(posBlock);
} }
} }
...@@ -4823,28 +4824,6 @@ void BaseTextEditorWidget::clearLink() ...@@ -4823,28 +4824,6 @@ void BaseTextEditorWidget::clearLink()
d->m_linkPressed = false; d->m_linkPressed = false;
} }
void BaseTextEditorPrivate::updateMarksBlock(const QTextBlock &block)
{
if (const TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block))
foreach (ITextMark *mrk, userData->marks())
mrk->updateBlock(block);
}
void BaseTextEditorPrivate::updateMarksLineNumber()
{
QTextDocument *doc = q->document();
QTextBlock block = doc->begin();
int blockNumber = 0;
while (block.isValid()) {
if (const TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block))
foreach (ITextMark *mrk, userData->marks()) {
mrk->updateLineNumber(blockNumber + 1);
}
block = block.next();
++blockNumber;
}
}
void BaseTextEditorWidget::markBlocksAsChanged(QList<int> blockNumbers) void BaseTextEditorWidget::markBlocksAsChanged(QList<int> blockNumbers)
{ {
QTextBlock block = document()->begin(); QTextBlock block = document()->begin();
......
...@@ -233,8 +233,6 @@ public: ...@@ -233,8 +233,6 @@ public:
void foldLicenseHeader(); void foldLicenseHeader();
QBasicTimer autoScrollTimer; QBasicTimer autoScrollTimer;
void updateMarksLineNumber();
void updateMarksBlock(const QTextBlock &block);
uint m_marksVisible : 1; uint m_marksVisible : 1;
uint m_codeFoldingVisible : 1; uint m_codeFoldingVisible : 1;
uint m_codeFoldingSupported : 1; uint m_codeFoldingSupported : 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment