Skip to content

Commit ad5eb66

Browse files
committed
Different improvements of frontend
1 parent 77ce8ad commit ad5eb66

13 files changed

+429
-133
lines changed

DiffFrontend/diffviewer.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void DiffViewer::lineNumbeerAreaPaintEvent(QPaintEvent *event)
2727

2828
while(block.isValid() && top <= event->rect().bottom()){
2929
if(block.isVisible() && bottom >= event->rect().top()) {
30-
QString number = QString::number(blockNumber + 1);
30+
QString number = QString::number(blockNumber + 1 + lineOffset);
3131
painter.setPen(Qt::red);
3232
painter.drawText(0,top,lineNumberArea->width(), fontMetrics().height(),Qt::AlignRight, number);
3333
}
@@ -52,6 +52,16 @@ int DiffViewer::lineNumberAreaWidth()
5252
return space;
5353
}
5454

55+
void DiffViewer::setLineOffset(int lineOffset)
56+
{
57+
this->lineOffset = lineOffset;
58+
}
59+
60+
int DiffViewer::getLineOffset()
61+
{
62+
return lineOffset;
63+
}
64+
5565
void DiffViewer::resizeEvent(QResizeEvent *e)
5666
{
5767
QPlainTextEdit::resizeEvent(e);

DiffFrontend/diffviewer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class DiffViewer : public QPlainTextEdit
1111

1212
void lineNumbeerAreaPaintEvent(QPaintEvent *event);
1313
int lineNumberAreaWidth();
14+
void setLineOffset(int lineOffset);
15+
int getLineOffset();
1416

1517
protected:
1618

@@ -22,6 +24,7 @@ private slots:
2224

2325
private:
2426
QWidget *lineNumberArea;
27+
int lineOffset = 0;
2528
};
2629

2730
#endif // DIFFVIEWER_H

DiffFrontend/diffviewertext.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,22 @@ void DiffViewerText::generateHTMLTextFromLexemsArrayJson(QJsonArray lexems, QJso
2121
{
2222
global->currentTextVersion = forTextVersion;
2323
text.clear();
24-
DiffViewerTextBuilder builder;
24+
DiffViewerTextBuilder builder(&lineOffset);
2525
text = builder.generateTextFromLexemsArray(lexems,comments);
2626
}
2727

28+
int DiffViewerText::getLineOffset()
29+
{
30+
if(lineOffset > 0){
31+
return lineOffset -1;
32+
}
33+
return 0;
34+
}
35+
2836
void DiffViewerText::generateHTMLTextFromJson(QJsonValue jsonVal,QJsonObject comments, bool isTopLevel)
2937
{
3038
global->currentTextVersion = forTextVersion;
3139
text.clear();
32-
DiffViewerTextBuilder builder;
40+
DiffViewerTextBuilder builder(&lineOffset);
3341
text = builder.generateText(jsonVal,comments, isTopLevel);
3442
}

DiffFrontend/diffviewertext.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DIFFVIEWERTEXT_H
22
#define DIFFVIEWERTEXT_H
33

4-
#include <Global.h>
4+
#include "global.h"
55
#include <QJsonDocument>
66
#include <QObject>
77

@@ -13,6 +13,7 @@ class DiffViewerText : public QObject
1313
QString getText();
1414
void generateHTMLTextFromJson(QJsonValue obj, QJsonObject comments, bool isTopLevel = true);
1515
void generateHTMLTextFromLexemsArrayJson(QJsonArray lexems, QJsonObject comments);
16+
int getLineOffset();
1617
private:
1718

1819
Global* global;
@@ -22,6 +23,10 @@ class DiffViewerText : public QObject
2223

2324
QString text;
2425

26+
int lineOffset = 0;
27+
28+
29+
2530

2631
signals:
2732

DiffFrontend/diffviewertextbuilder.cpp

Lines changed: 63 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
#include <QJsonArray>
44
#include <QJsonObject>
55

6-
DiffViewerTextBuilder::DiffViewerTextBuilder()
6+
DiffViewerTextBuilder::DiffViewerTextBuilder(int* diff_line)
77
{
88
global = Global::getInstance();
9+
this->diff_line = diff_line;
910
}
1011

1112
QString DiffViewerTextBuilder::generateText(QJsonValue jsonVal, QJsonObject comments, bool isTopLevel= true)
@@ -35,7 +36,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
3536
pasteSpaces(lex["column"].toInt() - cur_column);
3637
cur_line = getTrueLine(lex["line"].toInt());
3738
}
38-
pasteLexem(lex);
39+
pasteAtom(lex);
3940
if(lex["type"] == "string"){
4041
int newlines = lex["string"].toString().count('\n');
4142
cur_line += newlines;
@@ -48,7 +49,7 @@ QString DiffViewerTextBuilder::generateTextFromLexemsArray(QJsonArray lexems, QJ
4849

4950
int DiffViewerTextBuilder::getTrueLine(int cur_line)
5051
{
51-
return cur_line - diff_line;
52+
return cur_line - *diff_line;
5253
}
5354

5455
void DiffViewerTextBuilder::pasteTopLevel(const QJsonArray &array)
@@ -59,8 +60,8 @@ void DiffViewerTextBuilder::pasteTopLevel(const QJsonArray &array)
5960
void DiffViewerTextBuilder::pasteNewLinesAndComments(int next_line){
6061
QJsonObject comment;
6162
while(cur_line < next_line){
62-
if(comments[QString::number(cur_line+diff_line)] != QJsonValue::Undefined) {
63-
comment = comments[QString::number(cur_line+diff_line)].toObject();
63+
if(comments[QString::number(cur_line+*diff_line)] != QJsonValue::Undefined) {
64+
comment = comments[QString::number(cur_line+*diff_line)].toObject();
6465
int column_diff = comment["column"].toInt() - cur_column;
6566
pasteSpaces(column_diff);
6667
text.append("<font style=\"color:#cccccc;\">");
@@ -74,41 +75,40 @@ void DiffViewerTextBuilder::pasteNewLinesAndComments(int next_line){
7475
}
7576
}
7677

77-
void DiffViewerTextBuilder::pasteLexem(const QJsonObject &lex)
78+
void DiffViewerTextBuilder::pasteAtom(const QJsonObject &atom)
7879
{
79-
if(lex["diff-st"].toString() == "deleted"){
80+
if(atom["diff-st"].toString() == "deleted"){
8081
text.append("<font style=\"background-color:#FF9CA1;\">");
81-
text.append(lex["string"].toString());
82+
text.append(atom["string"].toString());
8283
text.append("</font>");
83-
}else if (lex["diff-st"].toString() == "new"){
84+
}else if (atom["diff-st"].toString() == "new"){
8485
text.append("<font style=\"background-color:#C9FFBF;\">");
85-
text.append(lex["string"].toString());
86+
text.append(atom["string"].toString());
8687
text.append("</font>");
87-
}else if (lex["diff-st"].toString() == "moved"){
88+
}else if (atom["diff-st"].toString() == "moved"){
8889
text.append("<font style=\"background-color: #E5F0FF;\">");
89-
text.append(lex["string"].toString());
90+
text.append(atom["string"].toString());
9091
text.append("</font>");
91-
}else if (lex["type"].toString() == "errorLexem"){
92-
if(lex["id"] == global->getSelectedErrorLexId()){
92+
}else if (atom["type"].toString() == "errorLexem"){
93+
if(atom["id"] == global->getSelectedErrorLexId()){
9394
text.append("<font style=\"background-color:#ffffe6;\">");
9495
}else{
9596
text.append("<font style=\"background-color:#FF9CA1;\">");
9697
}
97-
text.append(lex["string"].toString());
98+
text.append(atom["string"].toString());
9899
text.append("</font>");
99-
}else {
100-
text.append(lex["string"].toString());
100+
} else {
101+
text.append(atom["string"].toString());
101102
}
102103
}
103104

104-
void DiffViewerTextBuilder::pasteParent(QChar parent){
105+
void DiffViewerTextBuilder::pasteSymbol(QChar symbol){
105106

106-
text.append(parent);
107+
text.append(symbol);
107108
cur_column++;
108109
}
109110

110-
111-
void DiffViewerTextBuilder::pasteSpacesBeforeParent(int line, int column)
111+
void DiffViewerTextBuilder::pasteWhitespaces(int line, int column)
112112
{
113113
if(cur_line == line){
114114
pasteSpaces(column - cur_column);
@@ -120,43 +120,50 @@ void DiffViewerTextBuilder::pasteSpacesBeforeParent(int line, int column)
120120
}
121121
}
122122

123-
void DiffViewerTextBuilder::genLexem(const QJsonObject &lex)
123+
void DiffViewerTextBuilder::genAtom(const QJsonObject &lex)
124124
{
125-
QJsonArray lexem_pos = lex["lexem-coord"].toArray();
126-
if(getTrueLine(lexem_pos[0].toInt()) == cur_line){
127-
pasteSpaces(lexem_pos[1].toInt() - cur_column);
125+
QJsonArray atom_pos = lex["lexem-coord"].toArray();
126+
if(getTrueLine(atom_pos[0].toInt()) == cur_line){
127+
pasteSpaces(atom_pos[1].toInt() - cur_column);
128128
} else {
129-
pasteNewLinesAndComments(getTrueLine(lexem_pos[0].toInt()));
130-
pasteSpaces(lexem_pos[1].toInt() - cur_column);
131-
cur_line = getTrueLine(lexem_pos[0].toInt());
129+
pasteNewLinesAndComments(getTrueLine(atom_pos[0].toInt()));
130+
pasteSpaces(atom_pos[1].toInt() - cur_column);
131+
cur_line = getTrueLine(atom_pos[0].toInt());
132132
}
133-
pasteLexem(lex);
134-
cur_column = lexem_pos[1].toInt() + lex["string"].toString().size();
133+
pasteAtom(lex);
134+
cur_column = atom_pos[1].toInt() + lex["string"].toString().size();
135135
}
136136

137137
void DiffViewerTextBuilder::genList(const QJsonObject &listObj, bool isFirstCall = false)
138138
{
139139
QJsonObject parent_info = listObj["par-info"].toObject();
140140
QJsonArray lparenCoord = parent_info["lparenCoord"].toArray();
141141
if(isFirstCall && !isTopLevel){
142-
diff_line = lparenCoord[0].toInt();
142+
*diff_line = lparenCoord[0].toInt();
143143
}
144144
QJsonArray rparenCoord = parent_info["rparenCoord"].toArray();
145145
auto main_part = [&](){
146-
pasteParent('(');
146+
pasteSymbol('(');
147147
QJsonArray array = listObj["elems"].toArray();
148148
loopArray(array);
149-
pasteSpacesBeforeParent(getTrueLine(rparenCoord[0].toInt()),rparenCoord[1].toInt());
150-
pasteParent(')');
149+
pasteWhitespaces(getTrueLine(rparenCoord[0].toInt()),rparenCoord[1].toInt());
150+
pasteSymbol(')');
151151
};
152152

153153

154-
pasteSpacesBeforeParent(getTrueLine(lparenCoord[0].toInt()),lparenCoord[1].toInt());
155-
if((listObj["diff-st"].toString() == "deleted") ||
156-
listObj["isIllegalNode"].toBool()){
154+
pasteWhitespaces(getTrueLine(lparenCoord[0].toInt()),lparenCoord[1].toInt());
155+
if(listObj["diff-st"].toString() == "deleted"){
157156
text.append("<font style=\"background-color:#FF9CA1;\">");
158157
main_part();
159158
text.append("</font>");
159+
}else if(listObj["isIllegalNode"].toBool()){
160+
if(listObj["id"].toInt() == global->getSelectedErrorNodesId()){
161+
text.append("<font style=\"background-color:#ffffe6;\">");
162+
}else{
163+
text.append("<font style=\"background-color:#FF9CA1;\">");
164+
}
165+
main_part();
166+
text.append("</font>");
160167
}else if (listObj["diff-st"].toString() == "new"){
161168
text.append("<font style=\"background-color:#C9FFBF;\">");
162169
main_part();
@@ -175,14 +182,31 @@ void DiffViewerTextBuilder::genList(const QJsonObject &listObj, bool isFirstCall
175182
}
176183
}
177184

185+
void DiffViewerTextBuilder::genQuote(const QJsonObject &quoteSexpr)
186+
{
187+
QJsonArray quoteCoord = quoteSexpr["quote-coord"].toArray();
188+
pasteWhitespaces(getTrueLine(quoteCoord[0].toInt()),quoteCoord[1].toInt());
189+
pasteSymbol('\'');
190+
QJsonObject nextSexpr = quoteSexpr["q-s-expr"].toObject();
191+
if(nextSexpr["type"].toString() == "list"){
192+
genList(nextSexpr);
193+
} else if(nextSexpr["type"].toString() == "atom"){
194+
genAtom(nextSexpr);
195+
} else if(nextSexpr["type"].toString() == "quote"){
196+
genQuote(nextSexpr);
197+
}
198+
}
199+
178200
void DiffViewerTextBuilder::loopArray(const QJsonArray &array)
179201
{
180202
for(int elem_index = 0; elem_index < array.size(); ++elem_index){
181203
QJsonObject sexprObject = array[elem_index].toObject();
182204
if(sexprObject["type"].toString() == "list"){
183205
genList(sexprObject);
184-
} else if(sexprObject["type"].toString() == "lexem"){
185-
genLexem(sexprObject);
206+
} else if(sexprObject["type"].toString() == "atom"){
207+
genAtom(sexprObject);
208+
} else if(sexprObject["type"].toString() == "quote"){
209+
genQuote(sexprObject);
186210
}
187211
}
188212
}
@@ -191,7 +215,3 @@ void DiffViewerTextBuilder::pasteSpaces(int count)
191215
{
192216
text.append(QString(count, ' '));
193217
}
194-
195-
196-
197-

DiffFrontend/diffviewertextbuilder.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class DiffViewerTextBuilder
1313
{
1414
public:
15-
DiffViewerTextBuilder();
15+
DiffViewerTextBuilder(int* diff_line);
1616

1717
QString generateText(QJsonValue, QJsonObject, bool);
1818
QString generateTextFromLexemsArray(QJsonArray, QJsonObject);
@@ -27,16 +27,17 @@ class DiffViewerTextBuilder
2727
int cur_line=1;
2828
int cur_column=1;
2929

30-
int diff_line = 0;
30+
int* diff_line;
3131

3232
int getTrueLine(int cur_line);
3333
void pasteNewLinesAndComments(int lines);
3434
void pasteTopLevel(const QJsonArray& doc);
35-
void pasteLexem(const QJsonObject& lex);
36-
void pasteParent(QChar parent);
37-
void pasteSpacesBeforeParent(int line, int column);
38-
void genLexem(const QJsonObject& lex);
35+
void pasteAtom(const QJsonObject& lex);
36+
void pasteSymbol(QChar parent);
37+
void pasteWhitespaces(int line, int column);
38+
void genAtom(const QJsonObject& lex);
3939
void genList(const QJsonObject& list,bool isFirstCall);
40+
void genQuote(const QJsonObject& quoteSexpr);
4041
void loopArray(const QJsonArray& array);
4142
void pasteSpaces(int count);
4243

DiffFrontend/global.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ int Global::getSelectedErrorLexId()
1919
}
2020
}
2121

22+
int Global::getSelectedErrorNodesId()
23+
{
24+
if(currentTextVersion == 1){
25+
return selected_error_node_id1;
26+
} else if(currentTextVersion == 2) {
27+
return selected_error_node_id2;
28+
}
29+
}
30+
2231
Global::Global()
2332
{
2433

DiffFrontend/global.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
#ifndef GLOBAL_H
22
#define GLOBAL_H
33

4+
enum class ErrorsModeTypes {LexicalErrors, SyntaxErrors, SemanticErrors, NoErrors};
45

56
class Global
67
{
78
public:
89
void operator=(const Global&) = delete;
910
static Global *getInstance();
1011

11-
int currentTextVersion = 1;
12+
int currentTextVersion = -1;
1213

1314
int selected_error_lex_id1 = -1;
1415
int selected_error_lex_id2 = -1;
1516

17+
int selected_error_node_id1 = -1;
18+
int selected_error_node_id2 = -1;
19+
1620
int current_selected_moved_ids[2] = {-1,-1};
1721

22+
ErrorsModeTypes file1ErrorsMode = ErrorsModeTypes::NoErrors;
23+
ErrorsModeTypes file2ErrorsMode = ErrorsModeTypes::NoErrors;
24+
1825
int getSelectedErrorLexId();
26+
int getSelectedErrorNodesId();
1927
protected:
2028
Global();
2129

0 commit comments

Comments
 (0)