Skip to content

Commit

Permalink
program: added append operation to program update
Browse files Browse the repository at this point in the history
new update append operation (in addition to insert, change, and remove)
is similar to insert except adds the line to the end of the program; is
meant to only be used when loading a program from a file (not yet
implemented in the program class); and is triggered by passing a -1 for
the line number to the update function (which the edit box instance will
not do)

the operation enumeration definition (with a new value for the append
operation) was moved from the error list header file to the program
model header file (the error list no longer uses the operation once
the no longer present set change index  function was removed)
  • Loading branch information
thunder422 committed Jan 8, 2014
1 parent 10724e4 commit b795a47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
10 changes: 1 addition & 9 deletions errorlist.h
Expand Up @@ -29,13 +29,6 @@
#include <QString>


enum Operation
{
Insert_Operation,
Change_Operation,
Remove_Operation
};

// class for holding details for an error of a program line
class ErrorItem
{
Expand Down Expand Up @@ -118,9 +111,8 @@ class ErrorList : public QList<ErrorItem>
}

private:
void setChangeIndex(int index, Operation operation);

bool m_changed; // error list changed
};


#endif // ERRORLIST_H
17 changes: 13 additions & 4 deletions programmodel.cpp
Expand Up @@ -238,7 +238,7 @@ void ProgramModel::clear(void)


// slot function to receive program updates

// - if lineNumber == 1 then append line to end of program
void ProgramModel::update(int lineNumber, int linesDeleted, int linesInserted,
QStringList lines)
{
Expand Down Expand Up @@ -269,12 +269,21 @@ void ProgramModel::update(int lineNumber, int linesDeleted, int linesInserted,
}
else if (linesInserted > 0)
{
// insert new lines into the program
Operation operation;
if (lineNumber == -1) // append to end of program?
{
lineNumber = oldCount;
operation = Append_Operation;
}
else // insert new lines into the program
{
operation = Insert_Operation;
}
int lastLineNumber = lineNumber + linesInserted - 1;
beginInsertRows(QModelIndex(), lineNumber, lastLineNumber);
while (i < count)
{
updateLine(Insert_Operation, lineNumber++, lines.at(i++));
updateLine(operation, lineNumber++, lines.at(i++));
}
endInsertRows();
}
Expand Down Expand Up @@ -341,7 +350,7 @@ bool ProgramModel::updateLine(Operation operation, int lineNumber,
delete rpnList; // no longer needed
return changed;
}
else if (operation == Insert_Operation)
else if (operation == Append_Operation || operation == Insert_Operation)
{
LineInfo lineInfo;
lineInfo.errIndex = -1;
Expand Down
9 changes: 9 additions & 0 deletions programmodel.h
Expand Up @@ -41,6 +41,15 @@ class Table;
class Translator;


enum Operation
{
Append_Operation,
Insert_Operation,
Change_Operation,
Remove_Operation
};


// class for holding and accessing a program word
class ProgramWord
{
Expand Down

0 comments on commit b795a47

Please sign in to comment.