/
main.cpp
66 lines (61 loc) · 1.91 KB
/
main.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
#include "ProfilingDataParser.h"
#include "RoutineListModel.h"
#include "View.h"
#include <QAbstractTableModel>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QFile>
#include <QDebug>
#include <QApplication>
int main(int argc, char *argv[])
{
if (argc != 2) {
qDebug() << "Usage:" << argv[0] << "<filename.json>";
return 1;
}
QFile profile(argv[1]);
if (!profile.open(QIODevice::ReadOnly)) {
qDebug() << "Failed to open" << argv[1];
return 1;
}
QByteArray jsondata = profile.readAll();
profile.close();
QJsonDocument rawdata(QJsonDocument::fromJson(jsondata));
if (!rawdata.isArray()) {
// perhaps we got .html in, let's try to rip JSON from that
QByteArray pattern("var rawData = JSON.parse('");
int lineStart = jsondata.indexOf(pattern);
if (lineStart != -1) {
int lineEnd = jsondata.indexOf("\n", lineStart);
if (lineEnd != -1) {
// get the actual positions of the JSON string
lineStart += pattern.length();
lineEnd -= 3;
// cut the excess HTML on both sides
jsondata.truncate(lineEnd);
jsondata = jsondata.mid(lineStart);
}
}
}
rawdata = QJsonDocument::fromJson(jsondata);
if (!rawdata.isArray()) {
// if that didn't work either, we're screwed
qDebug() << "Malformed input file";
return 1;
}
QJsonArray arr = rawdata.array();
if (!arr[0].isObject()) {
qDebug() << "Malformed input file";
return 1;
}
ProfilingDataParser pdp(arr);
RoutineListModel rlm(0, pdp.buildRoutineList());
QMap<QString, QVariant> ovm(pdp.buildOverviewData());
QApplication app(argc, argv);
View view;
view.setRoutineModel(&rlm);
view.setOverviewModel(&ovm);
view.show();
return app.exec();
}