GUI: Add a simple graph in the statistics dialog
This commit is contained in:
parent
0d02c598fd
commit
c1b0a07ab3
|
@ -171,3 +171,11 @@ contains(QMAKE_CC, gcc) {
|
||||||
contains(QMAKE_CXX, clang++) {
|
contains(QMAKE_CXX, clang++) {
|
||||||
QMAKE_CXXFLAGS += -std=c++11
|
QMAKE_CXXFLAGS += -std=c++11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contains(HAVE_QCHART, [yY][eE][sS]) {
|
||||||
|
QT += charts
|
||||||
|
DEFINES += HAVE_QCHART
|
||||||
|
} else {
|
||||||
|
message("Charts disabled - to enable it pass HAVE_QCHART=yes to qmake.")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
16
gui/stats.ui
16
gui/stats.ui
|
@ -20,7 +20,7 @@
|
||||||
<enum>QTabWidget::Rounded</enum>
|
<enum>QTabWidget::Rounded</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>2</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="mProjectTab">
|
<widget class="QWidget" name="mProjectTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -338,6 +338,20 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="mTabHistory">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>History</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Reported warnings</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -46,6 +46,55 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
|
||||||
mUI.mPaths->setText(projectFile->getCheckPaths().join(";"));
|
mUI.mPaths->setText(projectFile->getCheckPaths().join(";"));
|
||||||
mUI.mIncludePaths->setText(projectFile->getIncludeDirs().join(";"));
|
mUI.mIncludePaths->setText(projectFile->getIncludeDirs().join(";"));
|
||||||
mUI.mDefines->setText(projectFile->getDefines().join(";"));
|
mUI.mDefines->setText(projectFile->getDefines().join(";"));
|
||||||
|
#ifndef HAVE_QCHART
|
||||||
|
mUI.mTabHistory->setVisible(false);
|
||||||
|
#else
|
||||||
|
if (!projectFile->getBuildDir().isEmpty()) {
|
||||||
|
const QString prjpath = QFileInfo(projectFile->getFilename()).absolutePath();
|
||||||
|
const QString buildDir = prjpath + '/' + projectFile->getBuildDir();
|
||||||
|
if (QDir(buildDir).exists()) {
|
||||||
|
QChart *chart = new QChart();
|
||||||
|
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "error"));
|
||||||
|
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "warning"));
|
||||||
|
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "style"));
|
||||||
|
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "performance"));
|
||||||
|
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "portability"));
|
||||||
|
|
||||||
|
QDateTimeAxis *axisX = new QDateTimeAxis;
|
||||||
|
axisX->setFormat("MMM yyyy");
|
||||||
|
axisX->setTitleText("Date");
|
||||||
|
chart->addAxis(axisX, Qt::AlignBottom);
|
||||||
|
|
||||||
|
foreach (QAbstractSeries *s, chart->series()) {
|
||||||
|
s->attachAxis(axisX);
|
||||||
|
}
|
||||||
|
|
||||||
|
QValueAxis *axisY = new QValueAxis;
|
||||||
|
axisY->setLabelFormat("%i");
|
||||||
|
axisY->setTitleText("Count");
|
||||||
|
chart->addAxis(axisY, Qt::AlignLeft);
|
||||||
|
|
||||||
|
qreal maxY = 0;
|
||||||
|
foreach (QAbstractSeries *s, chart->series()) {
|
||||||
|
s->attachAxis(axisY);
|
||||||
|
if (QLineSeries *ls = dynamic_cast<QLineSeries*>(s)) {
|
||||||
|
foreach (QPointF p, ls->points()) {
|
||||||
|
if (p.y() > maxY)
|
||||||
|
maxY = p.y();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
axisY->setMax(maxY);
|
||||||
|
|
||||||
|
//chart->createDefaultAxes();
|
||||||
|
chart->setTitle("Number of reports");
|
||||||
|
|
||||||
|
QChartView *chartView = new QChartView(chart);
|
||||||
|
chartView->setRenderHint(QPainter::Antialiasing);
|
||||||
|
mUI.mTabHistory->layout()->addWidget(chartView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
mUI.mProject->setText(QString());
|
mUI.mProject->setText(QString());
|
||||||
mUI.mPaths->setText(QString());
|
mUI.mPaths->setText(QString());
|
||||||
|
@ -291,3 +340,36 @@ void StatsDialog::setStatistics(const CheckStatistics *stats)
|
||||||
mUI.mLblPerformance->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowPerformance)));
|
mUI.mLblPerformance->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowPerformance)));
|
||||||
mUI.mLblInformation->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowInformation)));
|
mUI.mLblInformation->setText(QString("%1").arg(stats->getCount(ShowTypes::ShowInformation)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_QCHART
|
||||||
|
QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString &severity) const
|
||||||
|
{
|
||||||
|
QLineSeries *series = new QLineSeries();
|
||||||
|
series->setName(severity);
|
||||||
|
QFile f(fileName);
|
||||||
|
if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
quint64 t = 0;
|
||||||
|
QTextStream in(&f);
|
||||||
|
while (!in.atEnd()) {
|
||||||
|
QString line = in.readLine();
|
||||||
|
QRegExp rxdate("\\[(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\\]");
|
||||||
|
if (rxdate.exactMatch(line)) {
|
||||||
|
int y = rxdate.cap(3).toInt();
|
||||||
|
int m = rxdate.cap(2).toInt();
|
||||||
|
int d = rxdate.cap(1).toInt();
|
||||||
|
QDateTime dt;
|
||||||
|
dt.setDate(QDate(y,m,d));
|
||||||
|
if (t == dt.toMSecsSinceEpoch())
|
||||||
|
t += 1000;
|
||||||
|
else
|
||||||
|
t = dt.toMSecsSinceEpoch();
|
||||||
|
}
|
||||||
|
if (line.startsWith(severity + ':')) {
|
||||||
|
int y = line.mid(1+severity.length()).toInt();
|
||||||
|
series->append(t, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return series;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -20,6 +20,9 @@
|
||||||
#define STATSDIALOG_H
|
#define STATSDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#ifdef HAVE_QCHART
|
||||||
|
#include <QtCharts>
|
||||||
|
#endif
|
||||||
#include "ui_stats.h"
|
#include "ui_stats.h"
|
||||||
|
|
||||||
class ProjectFile;
|
class ProjectFile;
|
||||||
|
@ -65,7 +68,9 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void copyToClipboard();
|
void copyToClipboard();
|
||||||
void pdfExport();
|
void pdfExport();
|
||||||
|
#ifdef HAVE_QCHART
|
||||||
|
QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const;
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
Ui::StatsDialog mUI;
|
Ui::StatsDialog mUI;
|
||||||
const CheckStatistics *mStatistics;
|
const CheckStatistics *mStatistics;
|
||||||
|
|
Loading…
Reference in New Issue