-
Notifications
You must be signed in to change notification settings - Fork 4
/
resultview.cpp
executable file
·151 lines (140 loc) · 4.59 KB
/
resultview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "resultview.h"
#include "ui_resultview.h"
#include "util.h"
#include <QDebug>
#include <QJsonArray>
ResultView::ResultView(QWidget *parent) :
QWidget(parent),
ui(new Ui::ResultView)
{
ui->setupUi(this);
this->resultGraph = new CompareRelation();
this->networkGraph = new NetworkGraph();
this->showCompareRelation();
this->showNetworkGraph();
connect(ui->result,SIGNAL(tabCloseRequested(int)),this,SLOT(removeSubTab(int)));
connect(this->networkGraph,SIGNAL(SIGNAL_showlayer(int)),this,SLOT(showlayer(int)));
}
void ResultView::showlayer(int layer)
{
emit SIGNAL_showlayer(layer);
}
void ResultView::showCompareRelation()
{
if(this->ui->result->indexOf(this->resultGraph) == -1){
this->ui->result->addTab(this->resultGraph,"Relation");
}
}
void ResultView::showNetworkGraph()
{
if(this->ui->result->indexOf(this->networkGraph) == -1){
this->ui->result->addTab(this->networkGraph,"Layers");
}
}
void ResultView::on_addNetworkGraph(const QString name, const QString layertype, int layernum, int layerwhich)
{
this->showNetworkGraph();
if(layerwhich==1)
{
this->networkGraph->clear();
this->ui->result->setCurrentWidget(this->networkGraph);
}
QString layerinfo;
QTextStream(&layerinfo)<<layerwhich<<"\nLayer type:\n"<<layertype<<"\nLayer name:\n"<<name<<"\nLayer num:\n"<<layernum;
this->networkGraph->addNode(layerinfo);
if(layerwhich>1)this->networkGraph->addEdge(this->lastLayer,layerinfo);
this->lastLayer=layerinfo;
}
void ResultView::parsingJsonFile(QString jsonFile)
{
this->resultGraph->clear();
this->showCompareRelation();
this->ui->result->setCurrentWidget(this->resultGraph);
QJsonObject * jsonObj = Util::parseJsonFile(jsonFile);
if(jsonObj==nullptr) {
qDebug() << "jsonObj is unvalid";
return ;
}
emit this->updateNetworkNodeStatus(*jsonObj);
if(jsonObj->contains("graph"))
{
QJsonObject graph = jsonObj->value("graph").toObject();
int nodes = 0;
if(graph.contains("number_of_nodes")){
nodes = graph.value("number_of_nodes").toString().toInt();
for(int i=0;i<nodes;i++)
{
//this->resultGraph->addNode(QString::number(i));
}
}
QStringList names;
int du[nodes+2];
memset(du,0,sizeof(du));
int G[nodes+2][nodes+2];
memset(G,0,sizeof(G));
if(graph.contains(("names")))
{
QJsonValue value = graph.value("names");
if(value.isArray())
{
QJsonArray array = value.toArray();
int size =array.size();
for(int i=0;i<size;i++){
names.append(array.at(i).toString());
this->resultGraph->addNode(array.at(i).toString());
}
}
}
if(graph.contains("edges"))
{
QJsonValue value = graph.value("edges");
if(value.isArray())
{
QJsonArray array = value.toArray();
int size =array.size();
for(int i=0;i<size;i++){
int indexFrom = array.at(i).toObject().value("from").toString().toInt();
int indexTo = array.at(i).toObject().value("to").toString().toInt();
this->resultGraph->addEdge(names.at(indexFrom),names.at(indexTo));
//qDebug()<<indexFrom<<indexTo;
du[indexTo]++;
G[indexFrom][indexTo]=1;
}
}
}
// for(int i=0;i<nodes;i++)
// for(int j=0;j<nodes;j++)
// if(G[i][j]!=0)qDebug()<<i<<" "<<j<<" "<<G[i][j];
//Caution:May cause some dead loop
//qDebug()<<du[0]<<du[1]<<du[2]<<du[3];
int posy=0;
while(true)
{
int posx=0;
for(int i=0;i<nodes;i++)
if(du[i]==0)
{
this->resultGraph->setpos(names.at(i),posx*40+posy*5,posy*40);
//qDebug()<<i<<" "<<posx<<" "<<posy;
du[i]=-posy-1;
posx++;
}
if(posx==0)break;
for(int i=0;i<nodes;i++)
if(du[i]==-posy-1)
{
for(int j=0;j<nodes;j++)
if(G[i][j]==1)du[j]--;
}
posy++;
}
}
}
void ResultView::removeSubTab(int index)
{
this->ui->result->removeTab(index);
}
ResultView::~ResultView()
{
delete ui;
}