From c1b0a07ab3ecead4b4fb21b24e171d4c3b58c7a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 9 Aug 2017 16:31:04 +0200 Subject: [PATCH] GUI: Add a simple graph in the statistics dialog --- gui/gui.pro | 8 +++++ gui/stats.ui | 16 ++++++++- gui/statsdialog.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++ gui/statsdialog.h | 7 +++- 4 files changed, 111 insertions(+), 2 deletions(-) diff --git a/gui/gui.pro b/gui/gui.pro index 7d51683f8..3b8081df8 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -171,3 +171,11 @@ contains(QMAKE_CC, gcc) { contains(QMAKE_CXX, clang++) { 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.") +} + diff --git a/gui/stats.ui b/gui/stats.ui index d565e934b..e4d261257 100644 --- a/gui/stats.ui +++ b/gui/stats.ui @@ -20,7 +20,7 @@ QTabWidget::Rounded - 2 + 0 @@ -338,6 +338,20 @@ + + + History + + + + + + Reported warnings + + + + + diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 13cbc3b6a..bcd0a4edf 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -46,6 +46,55 @@ void StatsDialog::setProject(const ProjectFile* projectFile) mUI.mPaths->setText(projectFile->getCheckPaths().join(";")); mUI.mIncludePaths->setText(projectFile->getIncludeDirs().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(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 { mUI.mProject->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.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 diff --git a/gui/statsdialog.h b/gui/statsdialog.h index 91df55234..87333dd46 100644 --- a/gui/statsdialog.h +++ b/gui/statsdialog.h @@ -20,6 +20,9 @@ #define STATSDIALOG_H #include +#ifdef HAVE_QCHART +#include +#endif #include "ui_stats.h" class ProjectFile; @@ -65,7 +68,9 @@ public: private slots: void copyToClipboard(); void pdfExport(); - +#ifdef HAVE_QCHART + QLineSeries *numberOfReports(const QString &fileName, const QString &severity) const; +#endif private: Ui::StatsDialog mUI; const CheckStatistics *mStatistics;