# # # patch "guitone/src/model/GetFile.cpp" # from [03b984484941b2811fe8e32ee6ab2c68e1a566be] # to [8e75d44d5d80e8fa38a7ab7ebe0f58844b20e315] # # patch "guitone/src/model/GetFile.h" # from [3b0bf490f7b095f95f579c6e67402057fa36f98f] # to [2d7fb807f93d2ac2ea5c3be5a72ee5e022da8271] # ============================================================ --- guitone/src/model/GetFile.cpp 03b984484941b2811fe8e32ee6ab2c68e1a566be +++ guitone/src/model/GetFile.cpp 8e75d44d5d80e8fa38a7ab7ebe0f58844b20e315 @@ -21,6 +21,7 @@ #include "GetFile.h" #include "../monotone/Monotone.h" #include +#include GetFile::GetFile(QObject *parent) : AutomateCommand(parent) @@ -89,12 +90,18 @@ void GetFile::parseOutput(AutomateComman return; } - QStringList lines(AutomateCommand::data.split("/[\\r\\n]+/")); + QStringList lines(AutomateCommand::data.split(QChar('\n'))); for (int i=0, s=lines.size(); ileftStart > 0) + if ((version == Left || version == Both) && hunk->leftStart > 0) { curLine += hunk->leftStart - leftLastHunk; } @@ -133,7 +140,8 @@ void GetFile::applyDiff(Diff * diff, Fil { DiffLineGroup * group = hunk->lineGroups.at(j); - qDebug("GetFile::applyDiff: linegroup: %d", j); + qDebug("GetFile::applyDiff: linegroup: %d, %d", j, group->state); + qDebug("Lines: %s", qPrintable(group->contents.join("\\n"))); if (version == Left) { @@ -151,7 +159,7 @@ void GetFile::applyDiff(Diff * diff, Fil // set the following lines to "Removed" for (int k = curLine, l = k+group->changeLen; kmarker = ContentLine::Removed; } curLine += group->changeLen; @@ -184,7 +192,11 @@ void GetFile::applyDiff(Diff * diff, Fil for (int x=0, y=group->changeLen; xcontents.at(x), ContentLine::Added) + new ContentLine( + group->contents.at(x), + ContentLine::Added, + curLine+x + ) ); } curLine += group->changeLen; @@ -192,7 +204,7 @@ void GetFile::applyDiff(Diff * diff, Fil // raise the line count for the other items for (int x=curLine, y=fileContents.size(); xnumber = x; } // to the next "removed" line group @@ -214,10 +226,12 @@ void GetFile::applyDiff(Diff * diff, Fil curLine += group->startPos - rightLastLine; } + qDebug("marking %d removed lines", group->changeLen); // mark deleted lines for (int k = curLine, l = k+group->changeLen; kmarker = ContentLine::Removed; } int oldLineStart = curLine; curLine += group->changeLen; @@ -228,18 +242,25 @@ void GetFile::applyDiff(Diff * diff, Fil // add the new lines accordingly group = hunk->lineGroups.at(j); + qDebug("adding %d added lines", group->changeLen); for (int x=0, y=group->contents.size(); xcontents.at(x), ContentLine::Added) + new ContentLine( + group->contents.at(x), + ContentLine::Added, + oldLineStart+x + ) ); } curLine += group->changeLen; + qDebug("renumbering the following contents starting from %d", curLine); // raise the line count for the other items for (int x=curLine, y=fileContents.size(); xnumber = x; } // to the next "removed" line @@ -250,16 +271,19 @@ void GetFile::applyDiff(Diff * diff, Fil Q_ASSERT(false); } } -} - -void setLinesRemoved(int start, int len) -{ + qDebug("Unchanged: %d, Added: %d, Removed: %d", ContentLine::Unchanged, ContentLine::Added, ContentLine::Removed); + for (int i=0,j=fileContents.size(); inumber, fileContents.at(i)->marker); + } + + reset(); } int GetFile::columnCount(const QModelIndex &parent) const { - return 1; + return 2; } QVariant GetFile::data(const QModelIndex &index, int role) const @@ -272,28 +296,40 @@ QVariant GetFile::data(const QModelIndex int row = index.row(); if (row >= fileContents.size()) return QVariant(); - ContentLine line = fileContents.at(row); + ContentLine * line = fileContents.at(row); if (role == Qt::DisplayRole) { switch (index.column()) { - case 0: return QVariant(line.number); - case 1: return QVariant(line.content); + case 0: return QVariant(line->number); + case 1: return QVariant(line->content); default: Q_ASSERT(false); } } else if (role == Qt::BackgroundRole) { - switch (line.marker) + switch (line->marker) { case ContentLine::Added: return QVariant(QBrush(Qt::green)); case ContentLine::Removed: return QVariant(QBrush(Qt::red)); default: return QVariant(); } } - + else + if (role == Qt::FontRole && index.column() == 1) + { + QFont font; + font.setStyleHint(QFont::Courier); + font.setFamily("Courier"); + return QVariant(font); + } + else + if (role == Qt::TextAlignmentRole && index.column() == 0) + { + return QVariant(Qt::AlignRight); + } return QVariant(); } @@ -304,13 +340,15 @@ QVariant GetFile::headerData(int section QVariant GetFile::headerData(int section, Qt::Orientation orientation, int role) const { - if (role != Qt::DisplayRole) return QVariant(); - - switch (section) + if (role == Qt::DisplayRole) { - case 0: return QVariant(tr("Line")); - case 1: return QVariant(tr("Content")); + switch (section) + { + case 0: return QVariant(tr("Line")); + case 1: return QVariant(tr("Content")); + } } + return QVariant(); } ============================================================ --- guitone/src/model/GetFile.h 3b0bf490f7b095f95f579c6e67402057fa36f98f +++ guitone/src/model/GetFile.h 2d7fb807f93d2ac2ea5c3be5a72ee5e022da8271 @@ -27,14 +27,14 @@ struct ContentLine { #include "../util/DiffParser.h" struct ContentLine { - int number; QString content; enum Marker {Unchanged, Added, Removed} marker; + int number; ContentLine() {} - ContentLine(QString c, Marker m) : content(c), marker(m) {} + ContentLine(QString c, Marker m, int n) : content(c), marker(m), number(n) {} }; -typedef QVector Content; +typedef QVector Content; class GetFile : public AutomateCommand {