-
Notifications
You must be signed in to change notification settings - Fork 2
/
logdiff.h
140 lines (105 loc) · 3.07 KB
/
logdiff.h
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
#ifndef LOGDIFF_H
#define LOGDIFF_H
#include <QMainWindow>
#include <QThread>
#include <QProgressDialog>
#include <QRunnable>
#include <QHash>
#include <QEvent>
namespace Ui {
class LogDiff;
}
struct Match {
Match(int removals=-1, int additions=-1, const QString &id1=QString(), const QString &id2=QString()):
removals(removals),
additions(additions),
id1(id1),
id2(id2) { }
int removals;
int additions;
QString id1;
QString id2;
/*double similarity() const {
double s = lines1 - removals;
return s / (double)lines1;
}*/
};
class DiffTask: public QRunnable
{
public:
DiffTask(QObject *parent, const QString &sessionDir, const QString &id1, const QStringList &ids2):
QRunnable(),
parent(parent),
sessionDir(sessionDir), id1(id1), ids2(ids2) { }
void run();
private:
void postError(const QString &error);
QObject *parent;
QString sessionDir;
QString id1;
QStringList ids2;
};
const QEvent::Type ThreadMatchEventType = (QEvent::Type)9493;
const QEvent::Type ThreadErrorEventType = (QEvent::Type)9494;
class ThreadMatchEvent: public QEvent {
public:
ThreadMatchEvent(QList<Match> *matches):
QEvent(ThreadMatchEventType),
matches(matches) { }
QList<Match> *matches;
};
class ThreadErrorEvent: public QEvent {
public:
ThreadErrorEvent(const QString &error):
QEvent(ThreadErrorEventType),
error(error) { }
QString error;
};
class LogDiff : public QMainWindow
{
Q_OBJECT
public:
explicit LogDiff(QWidget *parent = 0);
~LogDiff();
private slots:
void on_browse1Btn_clicked();
void on_browse2Btn_clicked();
void on_log1Edit_returnPressed();
void on_log2Edit_returnPressed();
void on_threadsTable_cellDoubleClicked(int row, int);
void on_searchEdit_returnPressed();
void on_searchBtn_clicked();
private:
Ui::LogDiff *ui;
void clearSession();
bool initSession();
void error(const QString &title, const QString &text);
void processLogs();
bool splitThreads(int logNo, QStringList &ids, QHash<QString, int> &lineNums, bool &slow);
void customEvent(QEvent *event);
void matchThreads(bool &slow);
void selectMatches();
bool getFirstLine(const QString &fname, QString &firstLine);
QString trimFirstLine(const QString &line);
void addMatches(const QList<Match> &best, const QList<Match> &other,
const QHash<quint64, QString> firstLines1, const QHash<quint64, QString> firstLines2);
bool addMatch(const Match &match, const QString &firstLine);
bool grepFile(const QString &fname, const QString &text, QHash<quint64, QString> &matches);
// fields
QString sessionDir;
int fieldsNum;
int pidCol;
int tidCol;
int operCol;
QStringList ids1;
QStringList ids2;
QHash<QString, int> lineNums1;
QHash<QString, int> lineNums2;
int diffsDone;
bool diffsFailed;
QList<Match> matches;
QList<Match> bestMatches;
QList<Match> otherMatches;
QProgressDialog matchProgress;
};
#endif // LOGDIFF_H