GUI: Show separate statistics graphs for cppcheck and clang-tidy

This commit is contained in:
Daniel Marjamäki 2017-08-12 15:44:43 +02:00
parent 416cf641f3
commit b62c145c36
4 changed files with 65 additions and 41 deletions

View File

@ -368,6 +368,12 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
if (r2.exactMatch(r1.cap(5))) { if (r2.exactMatch(r1.cap(5))) {
message = r2.cap(1); message = r2.cap(1);
id = tool + '-' + r2.cap(2); id = tool + '-' + r2.cap(2);
if (r2.cap(2) == "performance")
errorItem.severity = Severity::SeverityType::performance;
else if (r2.cap(2) == "portability")
errorItem.severity = Severity::SeverityType::portability;
else if (r2.cap(2) == "readability")
errorItem.severity = Severity::SeverityType::style;
} else { } else {
message = r1.cap(5); message = r1.cap(5);
id = CLANG; id = CLANG;

View File

@ -344,9 +344,9 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="mLblHistoryFile">
<property name="text"> <property name="text">
<string>Reported warnings</string> <string>File:</string>
</property> </property>
</widget> </widget>
</item> </item>

95
gui/statsdialog.cpp Normal file → Executable file
View File

@ -21,7 +21,6 @@
#include <QFileInfo> #include <QFileInfo>
#include <QTextDocument> #include <QTextDocument>
#include <QWidget> #include <QWidget>
#include <QDialog>
#include <QString> #include <QString>
#include <QClipboard> #include <QClipboard>
#include <QMimeData> #include <QMimeData>
@ -37,6 +36,8 @@ StatsDialog::StatsDialog(QWidget *parent)
{ {
mUI.setupUi(this); mUI.setupUi(this);
setWindowFlags(Qt::Window);
connect(mUI.mCopyToClipboard, &QPushButton::pressed, this, &StatsDialog::copyToClipboard); connect(mUI.mCopyToClipboard, &QPushButton::pressed, this, &StatsDialog::copyToClipboard);
connect(mUI.mPDFexport, &QPushButton::pressed, this, &StatsDialog::pdfExport); connect(mUI.mPDFexport, &QPushButton::pressed, this, &StatsDialog::pdfExport);
} }
@ -51,48 +52,21 @@ void StatsDialog::setProject(const ProjectFile* projectFile)
#ifndef HAVE_QCHART #ifndef HAVE_QCHART
mUI.mTabHistory->setVisible(false); mUI.mTabHistory->setVisible(false);
#else #else
QString statsFile;
if (!projectFile->getBuildDir().isEmpty()) { if (!projectFile->getBuildDir().isEmpty()) {
const QString prjpath = QFileInfo(projectFile->getFilename()).absolutePath(); const QString prjpath = QFileInfo(projectFile->getFilename()).absolutePath();
const QString buildDir = prjpath + '/' + projectFile->getBuildDir(); const QString buildDir = prjpath + '/' + projectFile->getBuildDir();
if (QDir(buildDir).exists()) { if (QDir(buildDir).exists()) {
QChart *chart = new QChart(); statsFile = buildDir + "/statistics.txt";
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-error")); }
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-warning")); }
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-style")); mUI.mLblHistoryFile->setText(tr("File: ") + (statsFile.isEmpty() ? tr("No cppcheck build dir") : statsFile));
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-performance")); if (!statsFile.isEmpty()) {
chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-portability")); QChartView *chartView;
chartView = createChart(statsFile, "cppcheck");
QDateTimeAxis *axisX = new QDateTimeAxis; mUI.mTabHistory->layout()->addWidget(chartView);
axisX->setFormat("MMM yyyy"); if (projectFile->getAddons().contains("clang-tidy")) {
axisX->setTitleText("Date"); chartView = createChart(statsFile, "clang-tidy");
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); mUI.mTabHistory->layout()->addWidget(chartView);
} }
} }
@ -344,6 +318,49 @@ void StatsDialog::setStatistics(const CheckStatistics *stats)
} }
#ifdef HAVE_QCHART #ifdef HAVE_QCHART
QChartView *StatsDialog::createChart(const QString &statsFile, const QString &tool)
{
QChart *chart = new QChart;
chart->addSeries(numberOfReports(statsFile, tool + "-error"));
chart->addSeries(numberOfReports(statsFile, tool + "-warning"));
chart->addSeries(numberOfReports(statsFile, tool + "-style"));
chart->addSeries(numberOfReports(statsFile, tool + "-performance"));
chart->addSeries(numberOfReports(statsFile, tool + "-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(tool);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
return chartView;
}
QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString &severity) const QLineSeries *StatsDialog::numberOfReports(const QString &fileName, const QString &severity) const
{ {
QLineSeries *series = new QLineSeries(); QLineSeries *series = new QLineSeries();

View File

@ -69,6 +69,7 @@ private slots:
void copyToClipboard(); void copyToClipboard();
void pdfExport(); void pdfExport();
#ifdef HAVE_QCHART #ifdef HAVE_QCHART
QChartView *createChart(const QString &statsFile, const QString &tool);
QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const; QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const;
#endif #endif
private: private: