aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2017-10-06 14:51:22 +0200
committerDavid Schulz <david.schulz@qt.io>2017-10-09 12:31:33 +0000
commitc2686fd9ae3bc8ac1550984d88b59cb9a307c13a (patch)
tree6f6ba3bf858bdb2e99d4d4c35464085a23daf666
parent26d0b536cabce93bd2564bdbea0233357c50c32a (diff)
TextEditor: Fix annotation rectangle caching
The rectangle of an annotation is cached after it was painted. If just a part of an editor was updated all annotations were removed but only redrawn annotations were added to the cache again. This behavior is replaced by removing annotations that are not visible and those which got redrawn. So annotations that are still visible but were not redrawn are kept in the cache. Change-Id: I9246f1347b8f795284fb4fc9aabe11f251d16c25 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/texteditor/texteditor.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 20b08e0df9..f4b70645fc 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -4051,7 +4051,6 @@ void TextEditorWidget::paintEvent(QPaintEvent *e)
int cursor_cpos = 0;
QPen cursor_pen;
- d->m_annotationRects.clear();
d->m_searchResultOverlay->clear();
if (!d->m_searchExpr.isEmpty()) { // first pass for the search result overlays
@@ -4206,6 +4205,12 @@ void TextEditorWidget::paintEvent(QPaintEvent *e)
fs.toTextCharFormat(C_SEARCH_RESULT).background().color(),
e->rect());
+ { // remove all annotation rects from the cache that where drawn before the first visible block
+ auto it = d->m_annotationRects.begin();
+ auto end = d->m_annotationRects.end();
+ while (it != end && it.key() < block.blockNumber())
+ it = d->m_annotationRects.erase(it);
+ }
while (block.isValid()) {
@@ -4421,6 +4426,7 @@ void TextEditorWidget::paintEvent(QPaintEvent *e)
&& blockSelectionCursorRect.isValid())
painter.fillRect(blockSelectionCursorRect, palette().text());
+ d->m_annotationRects.remove(block.blockNumber());
d->drawLineAnnotation(painter, block, lineX < viewportRect.width() ? lineX : 0, er);
}
@@ -4441,6 +4447,19 @@ void TextEditorWidget::paintEvent(QPaintEvent *e)
block = doc->findBlockByLineNumber(block.firstLineNumber());
}
}
+
+ // remove all annotation rects from the cache that where drawn after the last visible block
+ if (block.isValid()) {
+ auto it = d->m_annotationRects.begin();
+ auto end = d->m_annotationRects.end();
+ while (it != end) {
+ if (it.key() > block.blockNumber())
+ it = d->m_annotationRects.erase(it);
+ else
+ ++it;
+ }
+ }
+
painter.setPen(context.palette.text().color());
if (backgroundVisible() && !block.isValid() && offset.y() <= er.bottom()