From b795a471208368d920ff8faafb9c902e8625edbc Mon Sep 17 00:00:00 2001 From: Thunder422 Date: Tue, 7 Jan 2014 22:30:21 -0500 Subject: [PATCH] program: added append operation to program update 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) --- errorlist.h | 10 +--------- programmodel.cpp | 17 +++++++++++++---- programmodel.h | 9 +++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/errorlist.h b/errorlist.h index ba8190e..5f2d90d 100644 --- a/errorlist.h +++ b/errorlist.h @@ -29,13 +29,6 @@ #include -enum Operation -{ - Insert_Operation, - Change_Operation, - Remove_Operation -}; - // class for holding details for an error of a program line class ErrorItem { @@ -118,9 +111,8 @@ class ErrorList : public QList } private: - void setChangeIndex(int index, Operation operation); - bool m_changed; // error list changed }; + #endif // ERRORLIST_H diff --git a/programmodel.cpp b/programmodel.cpp index 261cdbc..b9b06bb 100644 --- a/programmodel.cpp +++ b/programmodel.cpp @@ -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) { @@ -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(); } @@ -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; diff --git a/programmodel.h b/programmodel.h index 7a28f51..3201cc7 100644 --- a/programmodel.h +++ b/programmodel.h @@ -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 {