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
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()
: m_layout(0)
, m_requestDocUpdate(false)
......
......@@ -211,6 +211,8 @@ public:
QSizeF documentSize() const;
void updateMarksLineNumber();
void updateMarksBlock(const QTextBlock &block);
};
} // namespace TextEditor
......
......@@ -675,20 +675,21 @@ void BaseTextEditorWidget::editorContentsChange(int position, int charsRemoved,
d->m_contentsChanged = true;
QTextDocument *doc = document();
BaseTextDocumentLayout *documentLayout = static_cast<BaseTextDocumentLayout*>(doc->documentLayout());
// Keep the line numbers and the block information for the text marks updated
if (charsRemoved != 0) {
d->updateMarksLineNumber();
d->updateMarksBlock(document()->findBlock(position));
documentLayout->updateMarksLineNumber();
documentLayout->updateMarksBlock(document()->findBlock(position));
} else {
const QTextBlock posBlock = doc->findBlock(position);
const QTextBlock nextBlock = doc->findBlock(position + charsAdded);
if (posBlock != nextBlock) {
d->updateMarksLineNumber();
d->updateMarksBlock(posBlock);
d->updateMarksBlock(nextBlock);
documentLayout->updateMarksLineNumber();
documentLayout->updateMarksBlock(posBlock);
documentLayout->updateMarksBlock(nextBlock);
} else {
d->updateMarksBlock(posBlock);
documentLayout->updateMarksBlock(posBlock);
}
}
......@@ -4823,28 +4824,6 @@ void BaseTextEditorWidget::clearLink()
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)
{
QTextBlock block = document()->begin();
......
......@@ -233,8 +233,6 @@ public:
void foldLicenseHeader();
QBasicTimer autoScrollTimer;
void updateMarksLineNumber();
void updateMarksBlock(const QTextBlock &block);
uint m_marksVisible : 1;
uint m_codeFoldingVisible : 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