Skip to content

Commit 9f3df77

Browse files
committed
Improved frontend
1 parent 839440a commit 9f3df77

11 files changed

+523
-157
lines changed

DiffFrontend/DiffFrontend.pro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,22 @@ SOURCES += \
1212
diffviewer.cpp \
1313
diffviewertext.cpp \
1414
diffviewertextbuilder.cpp \
15+
global.cpp \
1516
linenumberarea.cpp \
1617
main.cpp \
1718
mainwindow.cpp \
18-
stat.cpp \
19-
statjsonreader.cpp
19+
statjsonreader.cpp \
20+
stats.cpp
2021

2122
HEADERS += \
2223
diffviewer.h \
2324
diffviewertext.h \
2425
diffviewertextbuilder.h \
26+
global.h \
2527
linenumberarea.h \
2628
mainwindow.h \
27-
stat.h \
28-
statjsonreader.h
29+
statjsonreader.h \
30+
stats.h
2931

3032
FORMS += \
3133
mainwindow.ui

DiffFrontend/diffviewer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DiffViewer::DiffViewer(QWidget *parent)
1818
void DiffViewer::lineNumbeerAreaPaintEvent(QPaintEvent *event)
1919
{
2020
QPainter painter(lineNumberArea);
21-
painter.fillRect(event->rect(), Qt::blue);
21+
painter.fillRect(event->rect(), Qt::black);
2222

2323
QTextBlock block = firstVisibleBlock();
2424
int blockNumber = block.blockNumber();

DiffFrontend/diffviewertext.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include <QJsonDocument>
77
#include <QJsonObject>
88

9-
DiffViewerText::DiffViewerText(QObject *parent) : QObject(parent)
9+
DiffViewerText::DiffViewerText(int forTextVersion, QObject *parent) : QObject(parent)
1010
{
11-
11+
this->forTextVersion = forTextVersion;
12+
global = Global::getInstance();
1213
}
1314

1415
QString DiffViewerText::getText()
@@ -18,12 +19,16 @@ QString DiffViewerText::getText()
1819

1920
void DiffViewerText::generateHTMLTextFromLexemsArrayJson(QJsonArray lexems, QJsonObject comments)
2021
{
22+
global->currentTextVersion = forTextVersion;
23+
text.clear();
2124
DiffViewerTextBuilder builder;
2225
text = builder.generateTextFromLexemsArray(lexems,comments);
2326
}
2427

2528
void DiffViewerText::generateHTMLTextFromJson(QJsonValue jsonVal,QJsonObject comments, bool isTopLevel)
2629
{
30+
global->currentTextVersion = forTextVersion;
31+
text.clear();
2732
DiffViewerTextBuilder builder;
2833
text = builder.generateText(jsonVal,comments, isTopLevel);
2934
}

DiffFrontend/diffviewertext.h

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

4+
#include <Global.h>
45
#include <QJsonDocument>
56
#include <QObject>
67

78
class DiffViewerText : public QObject
89
{
910
Q_OBJECT
1011
public:
11-
explicit DiffViewerText(QObject *parent = nullptr);
12+
explicit DiffViewerText(int forTextVersion, QObject *parent = nullptr);
1213
QString getText();
1314
void generateHTMLTextFromJson(QJsonValue obj, QJsonObject comments, bool isTopLevel = true);
1415
void generateHTMLTextFromLexemsArrayJson(QJsonArray lexems, QJsonObject comments);
1516
private:
1617

18+
Global* global;
19+
1720
QJsonDocument loadedJson;
21+
int forTextVersion;
1822

1923
QString text;
2024

DiffFrontend/diffviewertextbuilder.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
DiffViewerTextBuilder::DiffViewerTextBuilder()
77
{
8-
8+
global = Global::getInstance();
99
}
1010

1111
QString DiffViewerTextBuilder::generateText(QJsonValue jsonVal, QJsonObject comments, bool isTopLevel= true)
@@ -88,6 +88,14 @@ void DiffViewerTextBuilder::pasteLexem(const QJsonObject &lex)
8888
text.append("<font style=\"background-color: #E5F0FF;\">");
8989
text.append(lex["string"].toString());
9090
text.append("</font>");
91+
}else if (lex["type"].toString() == "errorLexem"){
92+
if(lex["id"] == global->getSelectedErrorLexId()){
93+
text.append("<font style=\"background-color:#ffffe6;\">");
94+
}else{
95+
text.append("<font style=\"background-color:#FF9CA1;\">");
96+
}
97+
text.append(lex["string"].toString());
98+
text.append("</font>");
9199
}else {
92100
text.append(lex["string"].toString());
93101
}
@@ -144,16 +152,22 @@ void DiffViewerTextBuilder::genList(const QJsonObject &listObj, bool isFirstCall
144152

145153

146154
pasteSpacesBeforeParent(getTrueLine(lparenCoord[0].toInt()),lparenCoord[1].toInt());
147-
if(listObj["diff-st"].toString() == "deleted"){
155+
if((listObj["diff-st"].toString() == "deleted") ||
156+
listObj["isIllegalNode"].toBool()){
148157
text.append("<font style=\"background-color:#FF9CA1;\">");
149158
main_part();
150159
text.append("</font>");
151160
}else if (listObj["diff-st"].toString() == "new"){
152161
text.append("<font style=\"background-color:#C9FFBF;\">");
153162
main_part();
154163
text.append("</font>");
155-
}else if(listObj["diff-st"].toString() == "moved"){
156-
text.append("<font style=\"background-color: #E5F0FF;\">");
164+
}else if(listObj["diff-st"].isArray() && listObj["diff-st"].toArray()[0] == "moved"){
165+
if((global->currentTextVersion == 1 && global->current_selected_moved_ids[1] == listObj["diff-st"].toArray()[1].toInt())
166+
|| (global->currentTextVersion == 2 && global->current_selected_moved_ids[0] == listObj["diff-st"].toArray()[1].toInt())){
167+
text.append("<font style=\"background-color: #AAA0FF;\">");
168+
} else {
169+
text.append("<font style=\"background-color: #E5F0FF;\">");
170+
}
157171
main_part();
158172
text.append("</font>");
159173
}else {

DiffFrontend/diffviewertextbuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef DIFFVIEWERTEXTBUILDER_H
22
#define DIFFVIEWERTEXTBUILDER_H
33

4+
#include "global.h"
5+
46
#include <QJsonDocument>
57
#include <QJsonObject>
68
#include <QString>
@@ -16,6 +18,8 @@ class DiffViewerTextBuilder
1618
QString generateTextFromLexemsArray(QJsonArray, QJsonObject);
1719

1820
private:
21+
Global* global;
22+
1923
QString text;
2024
QJsonObject comments;
2125
bool isTopLevel;

DiffFrontend/global.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "global.h"
2+
3+
Global* Global::global_ = nullptr;
4+
5+
Global *Global::getInstance()
6+
{
7+
if(global_ ==nullptr){
8+
global_ = new Global();
9+
}
10+
return global_;
11+
}
12+
13+
int Global::getSelectedErrorLexId()
14+
{
15+
if(currentTextVersion == 1){
16+
return selected_error_lex_id1;
17+
} else if(currentTextVersion == 2) {
18+
return selected_error_lex_id2;
19+
}
20+
}
21+
22+
Global::Global()
23+
{
24+
25+
}

DiffFrontend/global.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef GLOBAL_H
2+
#define GLOBAL_H
3+
4+
5+
class Global
6+
{
7+
public:
8+
void operator=(const Global&) = delete;
9+
static Global *getInstance();
10+
11+
int currentTextVersion = 1;
12+
13+
int selected_error_lex_id1 = -1;
14+
int selected_error_lex_id2 = -1;
15+
16+
int current_selected_moved_ids[2] = {-1,-1};
17+
18+
int getSelectedErrorLexId();
19+
protected:
20+
Global();
21+
22+
static Global* global_;
23+
};
24+
25+
#endif // GLOBAL_H

0 commit comments

Comments
 (0)