-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
None
-
4.6.2
-
None
-
516ffeecded9ed20ef309143b5f15bcce4abbe60
Hi,
recently I used the Code Editor Example and recognised that the paint event function CodeEditor::lineNumberAreaPaintEvent() is called all the time. That's because of the connection "connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));". That is triggered whenever the text cursor blinks. So every second. That may be not a problem for editors with only a few line, but if you have more it becomes heavy since in the paint function all text blocks are looped.
So I would suggest to improve the code a little bit to increase performance. I thought of a new private member QPair<int, int> m_countCache; with "-1" as start values. Then altering following function
void CodeEditor::updateLineNumberArea(const QRect &rect, int dy)
{
if (dy)
lineNumberArea->scroll(0, dy);
else if (m_countCache.first != blockCount() ||
m_countCache.second != textCursor().block().lineCount())
if (rect.contains(viewport()->rect()))
updateLineNumberAreaWidth(0);
}
And a paint event will only happen if it is really needed.
I also think the last if statement could be deleted since it works also without it. But not sure on that.