@@ -30,28 +30,55 @@ void MainWindow::on_actionloadFiles_triggered()
3030 QProcess* backend_process = new QProcess (this );
3131 QString file = " diff-backend.exe" ;
3232 qDebug () << file;
33+ cleanOldJsonFiles ();
3334 backend_process->start (file,lispFiles);
3435 if (!backend_process->waitForFinished ()) {
3536 qDebug () << " something is wrong" ;
3637 }
38+ qDebug () << " Backend is ok!" ;
39+ if (QFile::exists (" lexer-errors-msgs1.json" )) {
40+ viewerMode = ViewerMode::ErrorsMode;
41+ file1ErrorsMode = ErrorsModeTypes::LexicalErrors;
42+ errorsMsgs1 = convertJsonArrayToErrorsMsgsMap (getJsonDocument (" lexer-errors-msgs1.json" ).array ());
43+ }
44+ if (QFile::exists (" lexer-errors-msgs2.json" )) {
45+ viewerMode = ViewerMode::ErrorsMode;
46+ file2ErrorsMode = ErrorsModeTypes::LexicalErrors;
47+ errorsMsgs2 = convertJsonArrayToErrorsMsgsMap (getJsonDocument (" lexer-errors-msgs2.json" ).array ());
48+ }
3749
38- stats = Stat (" stats.json" );
39- fillStatsTree ();
40- synTreeJson1 = getJsonDocument (" res1.json" );
41- synTreeJson2 = getJsonDocument (" res2.json" );
4250 if (QFile::exists (" comments1.json" )) {
4351 commentsJsonObj1 = getJsonDocument (" comments1.json" ).object ();
4452 }
4553 if (QFile::exists (" comments2.json" )) {
4654 commentsJsonObj2 = getJsonDocument (" comments2.json" ).object ();
4755 }
48- analyzeSynTree (synTreeJson1,1 );
49- analyzeSynTree (synTreeJson2,2 );
5056
51- doc1.setTextDescriptionFromJson (QJsonValue (synTreeJson1.array ()),commentsJsonObj1);
52- doc2.setTextDescriptionFromJson (QJsonValue (synTreeJson2.array ()),commentsJsonObj2);
53- ui->plainTextEdit ->appendHtml (doc1.getText ());
54- ui->plainTextEdit_2 ->appendHtml (doc2.getText ());
57+ if (viewerMode == ViewerMode::NormalMode){
58+ stats = Stat (" stats.json" );
59+ fillStatsTree ();
60+ synTreeJson1 = getJsonDocument (" res1.json" );
61+ synTreeJson2 = getJsonDocument (" res2.json" );
62+ analyzeSynTree (synTreeJson1,1 );
63+ analyzeSynTree (synTreeJson2,2 );
64+
65+ doc1.generateHTMLTextFromJson (QJsonValue (synTreeJson1.array ()),commentsJsonObj1);
66+ doc2.generateHTMLTextFromJson (QJsonValue (synTreeJson2.array ()),commentsJsonObj2);
67+ ui->plainTextEdit ->appendHtml (doc1.getText ());
68+ ui->plainTextEdit_2 ->appendHtml (doc2.getText ());
69+ } else if (viewerMode == ViewerMode::ErrorsMode){
70+ if (QFile::exists (" lexems1.json" )){
71+ qDebug (" I am here" );
72+ lexemsArrayJson1 = getJsonDocument (" lexems1.json" ).array ();
73+ doc1.generateHTMLTextFromLexemsArrayJson (lexemsArrayJson1,commentsJsonObj1);
74+ ui->plainTextEdit ->appendHtml (doc1.getText ());
75+ }
76+ if (QFile::exists (" lexems2.json" )){
77+ lexemsArrayJson2 = getJsonDocument (" lexems2.json" ).array ();
78+ doc1.generateHTMLTextFromLexemsArrayJson (lexemsArrayJson2,commentsJsonObj2);
79+ ui->plainTextEdit_2 ->appendHtml (doc2.getText ());
80+ }
81+ }
5582}
5683
5784void MainWindow::fillStatsTree ()
@@ -119,6 +146,30 @@ void MainWindow::analyzeSynTree(QJsonDocument &doc, int num)
119146 }
120147}
121148
149+ void MainWindow::cleanOldJsonFiles ()
150+ {
151+ QFile::remove (" lexems1.json" );
152+ QFile::remove (" lexems2.json" );
153+ QFile::remove (" comments1.json" );
154+ QFile::remove (" comments2.json" );
155+ QFile::remove (" lexer-errors-msgs1.json" );
156+ QFile::remove (" lexer-errors-msgs2.json" );
157+ QFile::remove (" res1.json" );
158+ QFile::remove (" res2.json" );
159+ QFile::remove (" stats.json" );
160+ }
161+
162+ ErrorsMsgsMap MainWindow::convertJsonArrayToErrorsMsgsMap (QJsonArray array)
163+ {
164+ ErrorsMsgsMap errorsMsgsMap;
165+ for (int i = 0 ; i < array.size (); i++){
166+ int errorLexId = array[i].toObject ()[" errorLexId" ].toInt ();
167+ errorsMsgsMap[errorLexId] = array[i].toObject ();
168+ errorsMsgsMap[errorLexId].insert (" isSelected" ,QJsonValue (false ));
169+ }
170+ return errorsMsgsMap;
171+ }
172+
122173QJsonDocument MainWindow::getJsonDocument (QString pathname)
123174{
124175 QFile loadFile (pathname);
@@ -137,20 +188,20 @@ void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
137188 qDebug () << item->text (0 );
138189 QString text = item->text (0 );
139190 if (text == " all" ){
140- doc1.setTextDescriptionFromJson (QJsonValue (synTreeJson1.array ()), commentsJsonObj1);
141- doc2.setTextDescriptionFromJson (QJsonValue (synTreeJson2.array ()), commentsJsonObj2);
191+ doc1.generateHTMLTextFromJson (QJsonValue (synTreeJson1.array ()), commentsJsonObj1);
192+ doc2.generateHTMLTextFromJson (QJsonValue (synTreeJson2.array ()), commentsJsonObj2);
142193 ui->plainTextEdit ->clear ();
143194 ui->plainTextEdit_2 ->clear ();
144195 ui->plainTextEdit ->appendHtml (doc1.getText ());
145196 ui->plainTextEdit_2 ->appendHtml (doc2.getText ());
146197 } else {
147198 if (nameToObj1.contains (text)){
148- doc1.setTextDescriptionFromJson (QJsonValue (nameToObj1[text]), commentsJsonObj1,false );
199+ doc1.generateHTMLTextFromJson (QJsonValue (nameToObj1[text]), commentsJsonObj1,false );
149200 ui->plainTextEdit ->clear ();
150201 ui->plainTextEdit ->appendHtml (doc1.getText ());
151202 }
152203 if (nameToObj2.contains (text)){
153- doc2.setTextDescriptionFromJson (QJsonValue (nameToObj2[text]), commentsJsonObj2,false );
204+ doc2.generateHTMLTextFromJson (QJsonValue (nameToObj2[text]), commentsJsonObj2,false );
154205 ui->plainTextEdit_2 ->clear ();
155206 ui->plainTextEdit_2 ->appendHtml (doc2.getText ());
156207 }
0 commit comments