diff --git a/gui/gui.pro b/gui/gui.pro index 6364fd07e..371446a43 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -30,7 +30,8 @@ FORMS = main.ui \ projectfile.ui \ about.ui \ logview.ui \ - helpwindow.ui + helpwindow.ui \ + stats.ui TRANSLATIONS = cppcheck_fi.ts \ cppcheck_nl.ts \ @@ -67,7 +68,8 @@ HEADERS += mainwindow.h \ csvreport.h \ logview.h \ filelist.h \ - helpwindow.h + helpwindow.h \ + statsdialog.h SOURCES += main.cpp \ mainwindow.cpp\ @@ -92,7 +94,8 @@ SOURCES += main.cpp \ csvreport.cpp \ logview.cpp \ filelist.cpp \ - helpwindow.cpp + helpwindow.cpp \ + statsdialog.cpp win32 { DEFINES += _CRT_SECURE_NO_WARNINGS diff --git a/gui/main.ui b/gui/main.ui index 01ef7fa14..7578e428b 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -66,7 +66,7 @@ 0 0 640 - 21 + 25 @@ -105,6 +105,7 @@ + @@ -399,6 +400,15 @@ &Edit Project File... + + + + :/images/text-x-generic.png:/images/text-x-generic.png + + + &Statistics + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1f5a814b3..dd27f1cbb 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -33,6 +33,7 @@ #include "projectfile.h" #include "project.h" #include "report.h" +#include "statsdialog.h" #include "logview.h" #include "filelist.h" #include "helpwindow.h" @@ -67,6 +68,7 @@ MainWindow::MainWindow() : connect(mUI.mActionCollapseAll, SIGNAL(triggered()), mUI.mResults, SLOT(CollapseAllResults())); connect(mUI.mActionExpandAll, SIGNAL(triggered()), mUI.mResults, SLOT(ExpandAllResults())); connect(mUI.mActionViewLog, SIGNAL(triggered()), this, SLOT(ShowLogView())); + connect(mUI.mActionViewStats, SIGNAL(triggered()), this, SLOT(ShowStatistics())); connect(mUI.mActionRecheck, SIGNAL(triggered()), this, SLOT(ReCheck())); @@ -811,6 +813,22 @@ void MainWindow::ShowLogView() mLogView->activateWindow(); } +void MainWindow::ShowStatistics() +{ + StatsDialog statsDialog(this); + + // Show a dialog with the previous scan statistics and project information + if (mProject) + { + statsDialog.setProject(*mProject); + } + statsDialog.setPathSelected(mCurrentDirectory); + statsDialog.setNumberOfFilesScanned(mThread->GetPreviousFilesCount()); + statsDialog.setScanDuration(mThread->GetPreviousScanDuration() / 1000.0); + + statsDialog.exec(); +} + void MainWindow::Log(const QString &logline) { if (mLogView) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 23daa9a85..1f4a97063 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -37,6 +37,7 @@ class LogView; class HelpWindow; class Project; class ErrorItem; +class StatsDialog; /// @addtogroup GUI /// @{ @@ -166,6 +167,12 @@ public slots: */ void ShowLogView(); + /** + * @brief Slot for showing the scan and project statistics. + * + */ + void ShowStatistics(); + protected slots: /** diff --git a/gui/stats.ui b/gui/stats.ui new file mode 100644 index 000000000..84b33d56d --- /dev/null +++ b/gui/stats.ui @@ -0,0 +1,315 @@ + + + StatsDialog + + + + 0 + 0 + 502 + 329 + + + + Statistics + + + + + + QTabWidget::Rounded + + + 1 + + + + Project + + + + + + Project: + + + + + + + + 0 + 0 + + + + true + + + + + + + Paths: + + + + + + + true + + + + 0 + 0 + + + + true + + + false + + + true + + + true + + + + + + + Include paths: + + + + + + + true + + + + 0 + 0 + + + + true + + + + + + + Defines: + + + + + + + true + + + + 0 + 0 + + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Previous Scan + + + + + + Path Selected: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Number of Files Scanned: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + + + Scan Duration: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + true + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Copy to Clipboard + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + mTabWidget + mProject + mPaths + mIncludePaths + mDefines + mPath + + + + + mButtonBox + accepted() + StatsDialog + accept() + + + 227 + 307 + + + 157 + 274 + + + + + mButtonBox + rejected() + StatsDialog + reject() + + + 295 + 313 + + + 286 + 274 + + + + + diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp new file mode 100644 index 000000000..af9c9a875 --- /dev/null +++ b/gui/statsdialog.cpp @@ -0,0 +1,124 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include "common.h" +#include "project.h" +#include "projectfile.h" +#include "statsdialog.h" + +StatsDialog::StatsDialog(QWidget *parent) + : QDialog(parent) +{ + mUI.setupUi(this); + + connect(mUI.mCopyToClipboard, SIGNAL(pressed()), this, SLOT(copyToClipboard())); +} + +void StatsDialog::setProject(const Project& project) +{ + ProjectFile *projectFile = project.GetProjectFile(); + if (projectFile) + { + mUI.mProject->setText(projectFile->GetRootPath()); + mUI.mPaths->setText(projectFile->GetCheckPaths().join(";")); + mUI.mIncludePaths->setText(projectFile->GetIncludeDirs().join(";")); + mUI.mDefines->setText(projectFile->GetDefines().join(";")); + } + else + { + mUI.mProject->setText(""); + mUI.mPaths->setText(""); + mUI.mIncludePaths->setText(""); + mUI.mDefines->setText(""); + } +} + +void StatsDialog::setPathSelected(const QString& path) +{ + mUI.mPath->setText(path); +} + +void StatsDialog::setNumberOfFilesScanned(int num) +{ + mUI.mNumberOfFilesScanned->setText(QString::number(num)); +} + +void StatsDialog::setScanDuration(double seconds) +{ + mUI.mScanDuration->setText(tr("%1 secs").arg(seconds)); +} + +void StatsDialog::copyToClipboard() +{ + QClipboard *clipboard = QApplication::clipboard(); + if (clipboard) + { + // Plain text summary + QString textSummary = tr( + "Project Settings\n" + "\tProject:\t%1\n" + "\tPaths:\t%2\n" + "\tInclude paths:\t%3\n" + "\tDefines:\t%4\n" + "Previous Scan\n" + "\tPath selected:\t%5\n" + "\tNumber of files scanned:\t%6\n" + "\tScan duration:\t%7\n" + ) + .arg(mUI.mProject->text()) + .arg(mUI.mPaths->text()) + .arg(mUI.mIncludePaths->text()) + .arg(mUI.mDefines->text()) + .arg(mUI.mPath->text()) + .arg(mUI.mNumberOfFilesScanned->text()) + .arg(mUI.mScanDuration->text()); + + // HTML summary + QString htmlSummary = tr( + "

Project Settings

\n" + "\n" + " \n" + " \n" + " \n" + " \n" + "
Project:%1
Paths:%2
Include paths:%3
Defines:%4
\n" + "

Previous Scan

\n" + "\n" + " \n" + " \n" + " \n" + "
Path selected:%5
Number of files scanned:%6
Scan duration:%7
\n" + ) + .arg(mUI.mProject->text()) + .arg(mUI.mPaths->text()) + .arg(mUI.mIncludePaths->text()) + .arg(mUI.mDefines->text()) + .arg(mUI.mPath->text()) + .arg(mUI.mNumberOfFilesScanned->text()) + .arg(mUI.mScanDuration->text()); + + QMimeData *mimeData = new QMimeData(); + mimeData->setText(textSummary); + mimeData->setHtml(htmlSummary); + clipboard->setMimeData(mimeData); + + } +} + diff --git a/gui/statsdialog.h b/gui/statsdialog.h new file mode 100644 index 000000000..9d59290e0 --- /dev/null +++ b/gui/statsdialog.h @@ -0,0 +1,69 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef STATSDIALOG_H +#define STATSDIALOG_H + +#include +#include "ui_stats.h" + +class Project; + +/// @addtogroup GUI +/// @{ + +/** +* @brief A dialog that shows project and scan statistics. +* +*/ +class StatsDialog : public QDialog +{ + Q_OBJECT +public: + StatsDialog(QWidget *parent = 0); + + /** + * @brief Sets the project to extract statistics from + */ + void setProject(const Project& project); + + /** + * @brief Sets the string to display beside "Path Selected:" + */ + void setPathSelected(const QString& path); + + /** + * @brief Sets the number to display beside "Number of Files Scanned:" + */ + void setNumberOfFilesScanned(int num); + + /** + * @brief Sets the number of seconds to display beside "Scan Duration:" + */ + void setScanDuration(double seconds); + +private slots: + void copyToClipboard(); + +private: + Ui::StatsDialog mUI; +}; + +/// @} + +#endif // STATSDIALOG_H diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 6a8c0196c..83f40fa67 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -22,6 +22,7 @@ ThreadHandler::ThreadHandler(QObject *parent) : QObject(parent), + mScanDuration(0), mRunningThreadCount(0) { SetThreadCount(1); @@ -71,6 +72,8 @@ void ThreadHandler::Check(Settings settings, bool recheck) { mThreads[i]->Check(settings); } + + mTime.start(); } bool ThreadHandler::IsChecking() const @@ -124,6 +127,8 @@ void ThreadHandler::ThreadDone() if (mRunningThreadCount == 0) { emit Done(); + + mScanDuration = mTime.elapsed(); } } @@ -173,3 +178,8 @@ int ThreadHandler::GetPreviousFilesCount() const { return mLastFiles.size(); } + +int ThreadHandler::GetPreviousScanDuration() const +{ + return mScanDuration; +} diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 9f5b9a1e6..b139bca38 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -22,6 +22,7 @@ #include #include +#include #include "../lib/settings.h" #include "../lib/cppcheck.h" #include "threadresult.h" @@ -110,6 +111,13 @@ public: */ int GetPreviousFilesCount() const; + /** + * @brief Return the time elapsed while scanning the previous time. + * + * @return the time elapsed in milliseconds. + */ + int GetPreviousScanDuration() const; + signals: /** * @brief Signal that all threads are done @@ -140,6 +148,18 @@ protected: */ QStringList mLastFiles; + /** + * @brief Timer used for measuring scan duration + * + */ + QTime mTime; + + /** + * @brief The previous scan duration in milliseconds. + * + */ + int mScanDuration; + /** * @brief Function to delete all threads *