Skip to content

Commit

Permalink
correct errors not being highlighted on start up
Browse files Browse the repository at this point in the history
the problem occurred because the cursor was not valid, which caused the
extra selections to contain invalid cursor preventing the errors from
being highlighted

a new cursor valid flag member added to the edit box class, which is
initialized to false and only set to true when a cursor move signal is
received, at which time the extra selection list is updated from the
saved error list

a new error list member added to edit box where the received errors list
from the program model is saved (will be needed later anyway to access
the error messages) and the extra selection list will only be updated if
the cursor is valid
  • Loading branch information
thunder422 committed May 3, 2013
1 parent 24ae7f0 commit 89cfa53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 13 additions & 1 deletion editbox.cpp
Expand Up @@ -37,7 +37,8 @@ EditBox::EditBox(QWidget *parent) :
QPlainTextEdit(parent),
m_modifiedLine(-1),
m_modifiedLineIsNew(false),
m_lineCount(0)
m_lineCount(0),
m_cursorValid(false)
{
// set the edit box to a fixed width font
QFont font = this->font();
Expand Down Expand Up @@ -350,6 +351,11 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)

void EditBox::cursorMoved(void)
{
if (!m_cursorValid)
{
m_cursorValid = true;
updateErrors(m_errors);
}
if (m_modifiedLine >= 0 && m_modifiedLine != textCursor().blockNumber())
{
// there is a modified line and cursor moved from that line
Expand Down Expand Up @@ -385,6 +391,12 @@ void EditBox::captureModifiedLine(int offset)
// function to update errors when program error list changes
void EditBox::updateErrors(const ErrorList &errors)
{
m_errors = errors;
if (!m_cursorValid)
{
return; // wait until cursor is valid
}

int inserted = errors.size() - m_extraSelections.size();
int removed;
if (inserted > 0)
Expand Down
6 changes: 4 additions & 2 deletions editbox.h
Expand Up @@ -29,9 +29,9 @@
#include <QPlainTextEdit>
#include <QTextBlock>

#include "errorlist.h"

class QEvent;
class ErrorItem;
class ErrorList;


class EditBox : public QPlainTextEdit
Expand Down Expand Up @@ -80,6 +80,8 @@ private slots:
int m_lineCount; // total document line count
QList<QTextEdit::ExtraSelection>
m_extraSelections; // error highlight extra selections
bool m_cursorValid; // flag for when text cursor is valid
ErrorList m_errors; // list of errors from the program model
};


Expand Down

0 comments on commit 89cfa53

Please sign in to comment.