Skip to content

Commit

Permalink
replaced translated lines with line info list in program model
Browse files Browse the repository at this point in the history
added new LineInfo private structure to ProgramModel, which currently
contains an error list index (not used yet) and a pointer to the RPN
list for the line (will eventually be replaced with an index to the
program code array)
  • Loading branch information
thunder422 committed Apr 10, 2013
1 parent 2da69b3 commit aee559d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
25 changes: 13 additions & 12 deletions programmodel.cpp
Expand Up @@ -53,7 +53,7 @@ QVariant ProgramModel::data(const QModelIndex &index, int role) const
}
else if (role == Qt::DisplayRole)
{
RpnList *rpnList = m_linesTranslated.at(index.row());
RpnList *rpnList = m_lineInfo.at(index.row()).rpnList;
if (!rpnList->hasError())
{
return rpnList->text();
Expand All @@ -74,7 +74,7 @@ QVariant ProgramModel::data(const QModelIndex &index, int role) const

int ProgramModel::rowCount(const QModelIndex &parent) const
{
return m_linesTranslated.count();
return m_lineInfo.count();
}


Expand All @@ -84,17 +84,17 @@ void ProgramModel::update(int lineNumber, int linesDeleted, int linesInserted,
QStringList lines)
{
int i;
int oldCount = m_linesTranslated.count();
int oldCount = m_lineInfo.count();
int count = lines.count();
for (i = 0; i < count - linesInserted; i++)
{
// update changed program lines if they actually changed
RpnList *rpnList = m_translator->translate(lines.at(i));
if (*rpnList != *m_linesTranslated.at(lineNumber))
if (*rpnList != *m_lineInfo.at(lineNumber).rpnList)
{
// delete old list, translate line and store new list
delete m_linesTranslated[lineNumber];
m_linesTranslated[lineNumber] = rpnList;
delete m_lineInfo.at(lineNumber).rpnList;
m_lineInfo[lineNumber].rpnList = rpnList;

// need to emit signal that data changed
QModelIndex index = this->index(lineNumber);
Expand All @@ -110,8 +110,8 @@ void ProgramModel::update(int lineNumber, int linesDeleted, int linesInserted,
while (--linesDeleted >= 0)
{
// delete rpn list and remove from list
delete m_linesTranslated[lineNumber];
m_linesTranslated.removeAt(lineNumber);
delete m_lineInfo.at(lineNumber).rpnList;
m_lineInfo.removeAt(lineNumber);
}
endRemoveRows();
}
Expand All @@ -123,15 +123,16 @@ void ProgramModel::update(int lineNumber, int linesDeleted, int linesInserted,
while (i < count)
{
// translate new line and insert into list
m_linesTranslated.insert(lineNumber++,
m_translator->translate(lines.at(i++)));
LineInfo lineInfo;
lineInfo.rpnList = m_translator->translate(lines.at(i++));
m_lineInfo.insert(lineNumber++, lineInfo);
}
endInsertRows();
}

if (m_linesTranslated.count() != oldCount)
if (m_lineInfo.count() != oldCount)
{
// emit new line count if changed
emit lineCountChanged(m_linesTranslated.count());
emit lineCountChanged(m_lineInfo.count());
}
}
7 changes: 6 additions & 1 deletion programmodel.h
Expand Up @@ -49,7 +49,12 @@ public slots:

private:
Translator *m_translator; // program line translator instance
QList<RpnList *>m_linesTranslated; // rpn lists of the program lines
struct LineInfo
{
RpnList *rpnList; // pointer to rpn list
int errorIndex; // index to error list
};
QList<LineInfo> m_lineInfo; // program line information list
};

#endif // PROGRAMMODEL_H

0 comments on commit aee559d

Please sign in to comment.