forked from qt-creator/qt-creator
TextEditor: schedule update document layout
When generating a lot of text marks we do not need to update the document for every mark and every property that changes. Change-Id: Ibba80138f6ebcbbe30a4f741979df69ad62608c1 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -970,6 +970,13 @@ void TextDocument::updateLayout() const
|
||||
documentLayout->requestUpdate();
|
||||
}
|
||||
|
||||
void TextDocument::scheduleUpdateLayout() const
|
||||
{
|
||||
auto documentLayout = qobject_cast<TextDocumentLayout*>(d->m_document.documentLayout());
|
||||
QTC_ASSERT(documentLayout, return);
|
||||
documentLayout->scheduleUpdate();
|
||||
}
|
||||
|
||||
TextMarks TextDocument::marks() const
|
||||
{
|
||||
return d->m_marksCache;
|
||||
@@ -1001,7 +1008,7 @@ bool TextDocument::addMark(TextMark *mark)
|
||||
documentLayout->hasMarks = true;
|
||||
documentLayout->maxMarkWidthFactor = newMaxWidthFactor;
|
||||
if (fullUpdate)
|
||||
documentLayout->requestUpdate();
|
||||
documentLayout->scheduleUpdate();
|
||||
else
|
||||
documentLayout->requestExtraAreaUpdate();
|
||||
return true;
|
||||
@@ -1080,7 +1087,7 @@ void TextDocument::removeMark(TextMark *mark)
|
||||
removeMarkFromMarksCache(mark);
|
||||
emit markRemoved(mark);
|
||||
mark->setBaseTextDocument(nullptr);
|
||||
updateLayout();
|
||||
scheduleUpdateLayout();
|
||||
}
|
||||
|
||||
void TextDocument::updateMark(TextMark *mark)
|
||||
@@ -1092,7 +1099,7 @@ void TextDocument::updateMark(TextMark *mark)
|
||||
userData->removeMark(mark);
|
||||
userData->addMark(mark);
|
||||
}
|
||||
updateLayout();
|
||||
scheduleUpdateLayout();
|
||||
}
|
||||
|
||||
void TextDocument::moveMark(TextMark *mark, int previousLine)
|
||||
|
@@ -112,6 +112,7 @@ public:
|
||||
TextMarks marksAt(int line) const;
|
||||
void removeMark(TextMark *mark);
|
||||
void updateLayout() const;
|
||||
void scheduleUpdateLayout() const;
|
||||
void updateMark(TextMark *mark);
|
||||
void moveMark(TextMark *mark, int previousLine);
|
||||
void removeMarkFromMarksCache(TextMark *mark);
|
||||
|
@@ -638,6 +638,20 @@ void TextDocumentLayout::updateMarksBlock(const QTextBlock &block)
|
||||
}
|
||||
}
|
||||
|
||||
void TextDocumentLayout::scheduleUpdate()
|
||||
{
|
||||
if (m_updateScheduled)
|
||||
return;
|
||||
m_updateScheduled = true;
|
||||
QMetaObject::invokeMethod(this, &TextDocumentLayout::requestUpdateNow, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void TextDocumentLayout::requestUpdateNow()
|
||||
{
|
||||
m_updateScheduled = false;
|
||||
requestUpdate();
|
||||
}
|
||||
|
||||
QRectF TextDocumentLayout::blockBoundingRect(const QTextBlock &block) const
|
||||
{
|
||||
QRectF boundingRect = QPlainTextDocumentLayout::blockBoundingRect(block);
|
||||
|
@@ -237,6 +237,11 @@ public:
|
||||
void documentReloaded(TextMarks marks, TextDocument *baseextDocument);
|
||||
void updateMarksLineNumber();
|
||||
void updateMarksBlock(const QTextBlock &block);
|
||||
void scheduleUpdate();
|
||||
void requestUpdateNow();
|
||||
|
||||
private:
|
||||
bool m_updateScheduled = false;
|
||||
|
||||
signals:
|
||||
void updateExtraArea();
|
||||
|
@@ -242,7 +242,7 @@ void TextMark::removedFromEditor()
|
||||
void TextMark::updateMarker()
|
||||
{
|
||||
if (m_baseTextDocument)
|
||||
m_baseTextDocument->updateLayout();
|
||||
m_baseTextDocument->scheduleUpdateLayout();
|
||||
}
|
||||
|
||||
void TextMark::setPriority(TextMark::Priority prioriy)
|
||||
|
Reference in New Issue
Block a user