forked from cppcheck-opensource/cppcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.cpp
More file actions
89 lines (72 loc) · 2.55 KB
/
Copy pathgraph.cpp
File metadata and controls
89 lines (72 loc) · 2.55 KB
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
#include "graph.h"
#include "applicationsettings.h"
#include <QDir>
#include <QDomDocument>
#include <QDomElement>
#include <QPainter>
Graph::Graph(QWidget *parent) :
QWidget(parent)
{
}
void Graph::trend(const QString &projectName)
{
values.clear();
datetimes.clear();
ApplicationSettings settings;
QDir dir(settings.resultsFolder);
dir.setSorting(QDir::Name);
dir.setNameFilters(QStringList() << "*.xml");
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
foreach(const QFileInfo fileinfo, dir.entryInfoList()) {
const QString filename = fileinfo.canonicalFilePath();
QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
continue;
QDomDocument doc;
if (!doc.setContent(&file))
continue;
const QDomElement rootElement = doc.documentElement();
if (rootElement.tagName() != "results")
continue;
const QDomElement metaElement = rootElement.firstChildElement("meta");
if (metaElement.isNull())
continue;
const QDomElement projectElement = metaElement.firstChildElement("project");
if (projectElement.text() != projectName)
continue;
int results = 0;
for (QDomElement child = rootElement.firstChildElement("results"); !child.isNull(); child = child.nextSiblingElement())
++results;
values.append(results);
datetimes.append(fileinfo.baseName().mid(0,10));
}
if (isVisible())
update();
}
static void drawLineGraph(QPainter *painter, int left, int top, int width, int height, const int values[], int numberOfValues)
{
int maxvalue = 0;
for (int i = 0; i < numberOfValues; i++) {
if (values[i] > maxvalue)
maxvalue = values[i];
}
painter->setPen(Qt::gray);
painter->setBrush(Qt::white);
painter->drawRect(left,top,width,height);
const int bottom = top + height;
const int w = width - 2;
const int h = height - 2;
painter->setPen(Qt::red);
for (int i = 1; i < numberOfValues; i++) {
painter->drawLine(left + 1 + (i-1) * w / (numberOfValues - 1),
bottom - 1 - (h * values[i-1]) / maxvalue,
left + 1 + i * w / (numberOfValues - 1),
bottom - 1 - (h * values[i]) / maxvalue);
}
}
void Graph::paintEvent(QPaintEvent * /*event*/)
{
QPainter painter(this);
painter.fillRect(rect(),Qt::white);
drawLineGraph(&painter,50,50,width()-100,height()-100,&values[0],values.size());
}