Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9004

Improve Code Editor Example

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 4.6.2
    • Documentation
    • 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())

      { lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height()); 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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            dm Geir Vattekar
            lykurg Lorenz Haas
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes