From b62c145c36778a5b99867edf0aa3068bf6fba7e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 12 Aug 2017 15:44:43 +0200 Subject: [PATCH] GUI: Show separate statistics graphs for cppcheck and clang-tidy --- gui/checkthread.cpp | 6 +++ gui/stats.ui | 4 +- gui/statsdialog.cpp | 95 ++++++++++++++++++++++++++------------------- gui/statsdialog.h | 1 + 4 files changed, 65 insertions(+), 41 deletions(-) mode change 100644 => 100755 gui/statsdialog.cpp diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index eaa3ad49c..1fced9549 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -368,6 +368,12 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS if (r2.exactMatch(r1.cap(5))) { message = r2.cap(1); 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 { message = r1.cap(5); id = CLANG; diff --git a/gui/stats.ui b/gui/stats.ui index e4d261257..0c630abff 100644 --- a/gui/stats.ui +++ b/gui/stats.ui @@ -344,9 +344,9 @@ - + - Reported warnings + File: diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp old mode 100644 new mode 100755 index c372f3f8f..aafc92629 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,8 @@ StatsDialog::StatsDialog(QWidget *parent) { mUI.setupUi(this); + setWindowFlags(Qt::Window); + connect(mUI.mCopyToClipboard, &QPushButton::pressed, this, &StatsDialog::copyToClipboard); connect(mUI.mPDFexport, &QPushButton::pressed, this, &StatsDialog::pdfExport); } @@ -51,48 +52,21 @@ void StatsDialog::setProject(const ProjectFile* projectFile) #ifndef HAVE_QCHART mUI.mTabHistory->setVisible(false); #else + QString statsFile; 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", "cppcheck-error")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-warning")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-style")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-performance")); - chart->addSeries(numberOfReports(buildDir + "/statistics.txt", "cppcheck-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(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); + statsFile = buildDir + "/statistics.txt"; + } + } + mUI.mLblHistoryFile->setText(tr("File: ") + (statsFile.isEmpty() ? tr("No cppcheck build dir") : statsFile)); + if (!statsFile.isEmpty()) { + QChartView *chartView; + chartView = createChart(statsFile, "cppcheck"); + mUI.mTabHistory->layout()->addWidget(chartView); + if (projectFile->getAddons().contains("clang-tidy")) { + chartView = createChart(statsFile, "clang-tidy"); mUI.mTabHistory->layout()->addWidget(chartView); } } @@ -344,6 +318,49 @@ void StatsDialog::setStatistics(const CheckStatistics *stats) } #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(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 *series = new QLineSeries(); diff --git a/gui/statsdialog.h b/gui/statsdialog.h index 87333dd46..5207c59fd 100644 --- a/gui/statsdialog.h +++ b/gui/statsdialog.h @@ -69,6 +69,7 @@ private slots: void copyToClipboard(); void pdfExport(); #ifdef HAVE_QCHART + QChartView *createChart(const QString &statsFile, const QString &tool); QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const; #endif private: