Sunday, January 5, 2014

Edit Box – Error Handling During Startup

During startup when the program is loaded into the edit box, any errors detected in the program were saved in a member variable until the cursor became valid.  A valid cursor is needed in order to generated the extra selections used to highlight the errors.  The error list changed routine was then called, which would process the saved errors and clear the saved errors list.

The mechanism was modified where any errors are ignored during startup.  When the cursor becomes valid, the errors are retrieved from the attached program unit and the extra selections are generated.  The saved error list member variable was no longer needed and was removed.  Access functions were added to the program model to obtain the error count and an error item by index.

[commit 10724e4aab]

Edit Box – Line Wrapping Problem

While working on the next set of changes, an unrelated problem was discovered with error highlighting.  The problem occurred when there were long lines that wrapped onto the next line.  The problem was first noticed when a line with an error was modified and error was shifted to the wrong place.  The problem also occurred in other situations, including moving to an error that was in the wrapped portion of a line, or when a recreated line was after a wrapped line.

The problem was identified to be the use of the findBlockByLineNumber() function, a member of the QTextDocument class that holds the document of the edit box (in the QPlainTextEdit base class).  This function was being used to get the text block for a given line number, which was then used to gets its position within the document to set the position of the cursor.

However, this function was not working as expected.  What it actually does is return the text block of the actual physical line specified, which takes into account wrapped lines where each part of a wrapped line counts as separate lines.  The findBlockByNumber() function does work as needed and does not consider wrapped lines.  This latter function was already being used in two places, but not in three others.

On the surface, these two functions appear to do the same thing for a plain text document.  The only difference in the help documentation was in the argument, one taking a line number and the other taking a block number.  It was incorrectly assumed that line number meant the same thing as block number.  It is true that each line is a block in a plain text document, but a line number actually represents the physical line on the screen.  Once the latter function was used throughout, there were no problems.

[commit bf7fb54a79]