Skip to content

Commit

Permalink
editbox: removed lines changed signal to program model update slot
Browse files Browse the repository at this point in the history
With the edit box having direct access to the program model, the lines
changed signal to update slot is not necessary and was changed to a
normal function call (which is how the tester class accesses the program
model already)

also added a few comments and identified slot functions in the comments
  • Loading branch information
thunder422 committed Dec 15, 2013
1 parent 19c5f06 commit c864bdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 20 additions & 10 deletions editbox.cpp
Expand Up @@ -50,16 +50,20 @@ EditBox::EditBox(ProgramModel *programUnit, QWidget *parent) :
font.setStyleHint(QFont::Monospace);
setFont(font);

//========================
// INTERNAL CONNECTIONS
//========================

// connect to catch specific document changes
connect(document(), SIGNAL(contentsChange(int, int, int)),
this, SLOT(documentChanged(int, int, int)));

// connect to catch cursor position changes
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(cursorMoved()));

// connect to catch line changes
connect(this, SIGNAL(linesChanged(int, int, int, QStringList)),
m_programUnit, SLOT(update(int, int, int, QStringList)));
//============================
// FROM PROGRAM CONNECTIONS
//============================

// connect to catch when an error has been inserted
connect(m_programUnit, SIGNAL(errorInserted(int, ErrorItem)),
Expand All @@ -77,9 +81,14 @@ EditBox::EditBox(ProgramModel *programUnit, QWidget *parent) :
connect(m_programUnit, SIGNAL(errorListChanged()),
this, SLOT(errorListChanged()));

//======================
// LINE NUMBER WIDGET
//======================

// create line number area width and connect signal to update it
m_lineNumberWidget = new LineNumberWidget(this);

// connect signals to line number widget functions
connect(this, SIGNAL(blockCountChanged(int)),
this, SLOT(lineNumberWidgetUpdateWidth()));
connect(this, SIGNAL(updateRequest(QRect, int)),
Expand Down Expand Up @@ -291,7 +300,7 @@ void EditBox::resetModified(void)
}


// function to detect lines changed when the document was changed
// slot function to detect lines changed when the document was changed
//
// - determines the number of lines that were modified
// - determines the net line count changed of the document
Expand Down Expand Up @@ -429,7 +438,8 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)
+ i).text();
}
}
emit linesChanged(changeLine, linesDeleted, linesInserted, lines);
m_programUnit->update(changeLine, linesDeleted, linesInserted,
lines);
}
m_lineCount = newLineCount;
}
Expand All @@ -442,7 +452,7 @@ void EditBox::documentChanged(int position, int charsRemoved, int charsAdded)
}


// function to check if cursor was moved from the modified line
// slot function to check if cursor was moved from the modified line

void EditBox::cursorMoved(void)
{
Expand All @@ -460,7 +470,7 @@ void EditBox::cursorMoved(void)
}


// overloaded function to set plain text of the document
// overloaded slot function to set plain text of the document

void EditBox::setPlainText(const QString &text)
{
Expand All @@ -476,7 +486,7 @@ void EditBox::captureModifiedLine(int offset)
{
if (m_modifiedLine >= 0)
{
emit linesChanged(m_modifiedLine, 0, m_modifiedLineIsNew ? 1 : 0,
m_programUnit->update(m_modifiedLine, 0, m_modifiedLineIsNew ? 1 : 0,
QStringList() << document()->findBlockByNumber(m_modifiedLine
+ offset).text());

Expand Down Expand Up @@ -579,15 +589,15 @@ int EditBox::lineNumberWidgetWidth(void)
}


// function to update the line number area width based on the maximum line
// slot function to update the line number area width based on the maximum line

void EditBox::lineNumberWidgetUpdateWidth(void)
{
setViewportMargins(lineNumberWidgetWidth(), 0, 0, 0);
}


// function to update the line number area when display update requested
// slot function to update the line number area when display update requested

void EditBox::lineNumberWidgetUpdate(const QRect &rect, int dy)
{
Expand Down
2 changes: 0 additions & 2 deletions editbox.h
Expand Up @@ -70,8 +70,6 @@ class EditBox : public QPlainTextEdit
void resizeEvent(QResizeEvent *event);

signals:
void linesChanged(int lineNumber, int linesDeleted, int linesInserted,
QStringList lines);
void cursorChanged(const QString &message);
void errorsAvailable(bool available);

Expand Down

0 comments on commit c864bdd

Please sign in to comment.