-
Notifications
You must be signed in to change notification settings - Fork 1
/
resultwindow.cpp
139 lines (110 loc) · 4.67 KB
/
resultwindow.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
#include "resultwindow.h"
#include "ui_resultwindow.h"
#include "detailwindow.h"
ResultWindow::ResultWindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::ResultWindow)
{
ui->setupUi(this);
}
ResultWindow::ResultWindow(std::vector<std::string> &codeFileList, std::string &docType, int k, int w): ResultWindow()
{
this->codeFileList = codeFileList;
this->docType = docType;
this->k = k;
this->w = w;
codes = docType == "C" ? getCodes(codeFileList, k, w) : getDocs(codeFileList, k, w);
std::vector <CodePair> similarities = calculateSimilarities(codes);
std::sort(similarities.begin(), similarities.end(),
[] (const CodePair &lhs, const CodePair &rhs) { return lhs.sim1 > rhs.sim1; });
fillTable(codes, similarities);
}
ResultWindow::~ResultWindow()
{
delete ui;
}
void ResultWindow::resizeTable()
{
ui->tableCodes->verticalHeader()->setVisible(false);
ui->tableCodes->setColumnWidth(0, 70);
ui->tableCodes->setColumnWidth(1, 325);
ui->tableCodes->setColumnWidth(2, 82);
ui->tableCodes->setColumnWidth(3, 325);
ui->tableCodes->setColumnWidth(4, 82);
ui->tableCodes->setColumnWidth(5, 0);
ui->tableCodes->setColumnWidth(6, 0);
ui->tableCodes->setColumnWidth(7, 0);
this->setMaximumWidth(ui->tableCodes->width());
this->setMinimumWidth(ui->tableCodes->width());
ui->tableCodes->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
}
void ResultWindow::fillTable(std::vector <Code> &codes, std::vector <CodePair> &similarities)
{
resizeTable();
ui->tableCodes->setHorizontalHeaderLabels(QStringList()
<< "Sıra" << "1. Kod" << "Benzerlik" << "2. Kod" << "Benzerlik");
QTableWidgetItem *tableItem = new QTableWidgetItem();
tableItem->setTextAlignment(Qt::AlignCenter);
tableItem->setFlags(tableItem->flags() & ~Qt::ItemIsEditable & ~Qt::ItemIsSelectable);
for (size_t i = 0; i < similarities.size(); ++i)
{
ui->tableCodes->insertRow(ui->tableCodes->rowCount());
int x = similarities[i].x;
int y = similarities[i].y;
int sim1 = similarities[i].sim1;
int sim2 = similarities[i].sim2;
QTableWidgetItem *newitem = tableItem->clone();
newitem->setText(QString::number(i+1));
ui->tableCodes->setItem(i, 0, newitem);
newitem = tableItem->clone();
newitem->setText(QString::fromStdString(codes[x].fileName));
ui->tableCodes->setItem(i, 1, newitem);
newitem = tableItem->clone();
newitem->setText("%" + QString::number(sim1));
ui->tableCodes->setItem(i, 2, newitem);
newitem = tableItem->clone();
newitem->setText(QString::fromStdString(codes[y].fileName));
ui->tableCodes->setItem(i, 3, newitem);
newitem = tableItem->clone();
newitem->setText("%" + QString::number(sim2));
ui->tableCodes->setItem(i, 4, newitem);
newitem = tableItem->clone();
newitem->setText(QString::number(x));
ui->tableCodes->setItem(i, 5, newitem);
newitem = tableItem->clone();
newitem->setText(QString::number(y));
ui->tableCodes->setItem(i, 6, newitem);
newitem = tableItem->clone();
newitem->setText(QString::number(similarities[i].sameFingerprints));
ui->tableCodes->setItem(i, 7, newitem);
}
}
std::vector <CodePair> ResultWindow::calculateSimilarities(std::vector<Code> &codes)
{
std::vector <CodePair> similarities;
for (size_t i = 0; i < codes.size()-1; ++i)
{
for (size_t j = i+1; j < codes.size(); ++j)
{
int sameFingerprints = compareCodes(codes[i], codes[j]);
size_t less, bigger;
if (codes[i].numOfSelectedFingerPrints < codes[j].numOfSelectedFingerPrints)
less = j, bigger = i;
else
less = i, bigger = j;
similarities.emplace_back(bigger, less, sameFingerprints, 100 * sameFingerprints / codes[bigger].numOfSelectedFingerPrints,
100 * sameFingerprints / codes[less].numOfSelectedFingerPrints);
}
}
return similarities;
}
void ResultWindow::on_tableCodes_cellDoubleClicked(int row, int column)
{
int x = ui->tableCodes->item(row, 5)->text().toInt();
int y = ui->tableCodes->item(row, 6)->text().toInt();
int matchedFP = ui->tableCodes->item(row, 7)->text().toInt();
int sim1 = std::stoi(ui->tableCodes->item(row, 2)->text().toStdString().substr(1));
int sim2 = std::stoi(ui->tableCodes->item(row, 4)->text().toStdString().substr(1));
DetailWindow *window = new DetailWindow(codes[x], codes[y], docType, matchedFP, sim1, sim2, k);
window->show();
}