From 84853aa7f941bd89ec2ba868e16b2a8b340e1ead Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 17:40:47 +0200 Subject: [PATCH 01/11] Added recheck and clear results buttons. --- gui/mainwindow.cpp | 36 +++++++++++++++++++++++++++++++----- gui/mainwindow.h | 16 ++++++++++++++++ gui/resultstree.cpp | 4 ---- gui/threadhandler.cpp | 15 +++++++-------- gui/threadhandler.h | 3 ++- 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7b0d00f10..c27b019ad 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -30,13 +30,17 @@ MainWindow::MainWindow() : mSettings(tr("CppCheck"), tr("CppCheck-GUI")), mActionExit(tr("E&xit"), this), mActionCheckFiles(tr("&Check files(s)"), this), - mActionCheckDirectory(tr("&Check directory"), this), + mActionClearResults(tr("Clear &results"), this), + mActionReCheck(tr("Recheck files"), this), + mActionCheckDirectory(tr("Check &directory"), this), mActionSettings(tr("&Settings"), this), mResults(mSettings) { QMenu *menu = menuBar()->addMenu(tr("&File")); menu->addAction(&mActionCheckFiles); menu->addAction(&mActionCheckDirectory); + menu->addAction(&mActionReCheck); + menu->addAction(&mActionClearResults); menu->addSeparator(); menu->addAction(&mActionExit); @@ -50,6 +54,8 @@ MainWindow::MainWindow() : connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); + connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); + connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); mThread.Initialize(&mResults); @@ -102,8 +108,8 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) mThread.ClearFiles(); mThread.SetFiles(RemoveUnacceptedFiles(fileNames)); mSettings.setValue(tr("Check path"), dialog.directory().absolutePath()); - mActionCheckFiles.setDisabled(true); - mThread.Check(GetCppCheckSettings()); + EnableCheckButtons(false); + mThread.Check(GetCppCheckSettings(),false); } } @@ -125,7 +131,7 @@ Settings MainWindow::GetCppCheckSettings() result._checkCodingStyle = true; result._errorsOnly = false; result._verbose = true; - result._force = true; + result._force = mSettings.value(tr("Check force"), 1).toBool(); result._xml = false; result._unusedFunctions = true; result._security = true; @@ -186,7 +192,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list) void MainWindow::CheckDone() { - mActionCheckFiles.setDisabled(false); + EnableCheckButtons(true); } void MainWindow::ProgramSettings() @@ -198,3 +204,23 @@ void MainWindow::ProgramSettings() } } + +void MainWindow::ReCheck() +{ + ClearResults(); + EnableCheckButtons(false); + mThread.Check(GetCppCheckSettings(),true); +} + +void MainWindow::ClearResults() +{ + mResults.Clear(); +} + +void MainWindow::EnableCheckButtons(bool enable) +{ + mActionCheckFiles.setEnabled(enable); + mActionReCheck.setEnabled(enable); + mActionCheckDirectory.setEnabled(enable); +} + diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b0ccb5fcc..c735fd0f5 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -49,6 +49,8 @@ public slots: * */ void CheckFiles(); + void ReCheck(); + void ClearResults(); /** * @brief Slot for check directory menu item @@ -66,6 +68,7 @@ protected slots: */ void CheckDone(); protected: + void EnableCheckButtons(bool enable); void DoCheckFiles(QFileDialog::FileMode mode); QStringList GetFilesRecursively(const QString &path); QStringList RemoveDuplicates(const QStringList &list); @@ -102,6 +105,19 @@ protected: */ QAction mActionCheckFiles; + /** + * @brief Menu action to clear results + * + */ + QAction mActionClearResults; + + /** + * @brief Menu action to re check + * + */ + QAction mActionReCheck; + + /** * @brief Menu action to check a directory * diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 4b55c58c3..716378072 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -72,15 +72,11 @@ void ResultsTree::AddErrorItem(const QString &file, mModel.appendRow(fileitem); } - //qDebug() << "Adding error for file" << realfile << ". Message is" << message; - QList list; list << CreateItem(severity); list << CreateItem(QString("%1").arg(lines[0])); list << CreateItem(message); fileitem->appendRow(list); - - //qDebug()<<"\n"; } QStandardItem *ResultsTree::FindFileItem(const QString &name) diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index eed089cdf..396608d13 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -33,22 +33,23 @@ ThreadHandler::~ThreadHandler() void ThreadHandler::ClearFiles() { + mLastFiles.clear(); mResults.ClearFiles(); } void ThreadHandler::SetFiles(const QStringList &files) { mResults.SetFiles(files); + mLastFiles = files; QString file; - qDebug() << "Files to check:"; - foreach(file, files) - { - qDebug() << file; - } } -void ThreadHandler::Check(Settings settings) +void ThreadHandler::Check(Settings settings, bool recheck) { + if (recheck && mRunningThreadCount == 0) { + mResults.SetFiles(mLastFiles); + } + if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs <= 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; @@ -126,8 +127,6 @@ void ThreadHandler::Stop() { mThreads[i]->terminate(); } - - mResults.ClearFiles(); } void ThreadHandler::Initialize(ResultsView *view) diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 4a704f300..fb0fb89c6 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -57,7 +57,7 @@ public: */ void SetFiles(const QStringList &files); - void Check(Settings settings); + void Check(Settings settings, bool recheck); signals: @@ -66,6 +66,7 @@ protected slots: void Stop(); void ThreadDone(); protected: + QStringList mLastFiles; void RemoveThreads(); ThreadResult mResults; QList mThreads; From 9eda0ce52c8b86976bdd82810ae09034803f1bae Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 17:41:14 +0200 Subject: [PATCH 02/11] astyle formatting. --- gui/mainwindow.cpp | 4 ++-- gui/threadhandler.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index c27b019ad..d1c1e7f66 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -109,7 +109,7 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) mThread.SetFiles(RemoveUnacceptedFiles(fileNames)); mSettings.setValue(tr("Check path"), dialog.directory().absolutePath()); EnableCheckButtons(false); - mThread.Check(GetCppCheckSettings(),false); + mThread.Check(GetCppCheckSettings(), false); } } @@ -209,7 +209,7 @@ void MainWindow::ReCheck() { ClearResults(); EnableCheckButtons(false); - mThread.Check(GetCppCheckSettings(),true); + mThread.Check(GetCppCheckSettings(), true); } void MainWindow::ClearResults() diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 396608d13..e7e84de54 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -46,7 +46,8 @@ void ThreadHandler::SetFiles(const QStringList &files) void ThreadHandler::Check(Settings settings, bool recheck) { - if (recheck && mRunningThreadCount == 0) { + if (recheck && mRunningThreadCount == 0) + { mResults.SetFiles(mLastFiles); } From c6e8d61db3acff243a55f7b233c1e382a4338e7d Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 17:42:00 +0200 Subject: [PATCH 03/11] Added recheck and clear results buttons. --- gui/mainwindow.cpp | 36 +++++++++++++++++++++++++++++++----- gui/mainwindow.h | 16 ++++++++++++++++ gui/resultstree.cpp | 4 ---- gui/threadhandler.cpp | 16 ++++++++-------- gui/threadhandler.h | 3 ++- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 7b0d00f10..d1c1e7f66 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -30,13 +30,17 @@ MainWindow::MainWindow() : mSettings(tr("CppCheck"), tr("CppCheck-GUI")), mActionExit(tr("E&xit"), this), mActionCheckFiles(tr("&Check files(s)"), this), - mActionCheckDirectory(tr("&Check directory"), this), + mActionClearResults(tr("Clear &results"), this), + mActionReCheck(tr("Recheck files"), this), + mActionCheckDirectory(tr("Check &directory"), this), mActionSettings(tr("&Settings"), this), mResults(mSettings) { QMenu *menu = menuBar()->addMenu(tr("&File")); menu->addAction(&mActionCheckFiles); menu->addAction(&mActionCheckDirectory); + menu->addAction(&mActionReCheck); + menu->addAction(&mActionClearResults); menu->addSeparator(); menu->addAction(&mActionExit); @@ -50,6 +54,8 @@ MainWindow::MainWindow() : connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles())); connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); + connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); + connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); mThread.Initialize(&mResults); @@ -102,8 +108,8 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode) mThread.ClearFiles(); mThread.SetFiles(RemoveUnacceptedFiles(fileNames)); mSettings.setValue(tr("Check path"), dialog.directory().absolutePath()); - mActionCheckFiles.setDisabled(true); - mThread.Check(GetCppCheckSettings()); + EnableCheckButtons(false); + mThread.Check(GetCppCheckSettings(), false); } } @@ -125,7 +131,7 @@ Settings MainWindow::GetCppCheckSettings() result._checkCodingStyle = true; result._errorsOnly = false; result._verbose = true; - result._force = true; + result._force = mSettings.value(tr("Check force"), 1).toBool(); result._xml = false; result._unusedFunctions = true; result._security = true; @@ -186,7 +192,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list) void MainWindow::CheckDone() { - mActionCheckFiles.setDisabled(false); + EnableCheckButtons(true); } void MainWindow::ProgramSettings() @@ -198,3 +204,23 @@ void MainWindow::ProgramSettings() } } + +void MainWindow::ReCheck() +{ + ClearResults(); + EnableCheckButtons(false); + mThread.Check(GetCppCheckSettings(), true); +} + +void MainWindow::ClearResults() +{ + mResults.Clear(); +} + +void MainWindow::EnableCheckButtons(bool enable) +{ + mActionCheckFiles.setEnabled(enable); + mActionReCheck.setEnabled(enable); + mActionCheckDirectory.setEnabled(enable); +} + diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b0ccb5fcc..c735fd0f5 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -49,6 +49,8 @@ public slots: * */ void CheckFiles(); + void ReCheck(); + void ClearResults(); /** * @brief Slot for check directory menu item @@ -66,6 +68,7 @@ protected slots: */ void CheckDone(); protected: + void EnableCheckButtons(bool enable); void DoCheckFiles(QFileDialog::FileMode mode); QStringList GetFilesRecursively(const QString &path); QStringList RemoveDuplicates(const QStringList &list); @@ -102,6 +105,19 @@ protected: */ QAction mActionCheckFiles; + /** + * @brief Menu action to clear results + * + */ + QAction mActionClearResults; + + /** + * @brief Menu action to re check + * + */ + QAction mActionReCheck; + + /** * @brief Menu action to check a directory * diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 4b55c58c3..716378072 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -72,15 +72,11 @@ void ResultsTree::AddErrorItem(const QString &file, mModel.appendRow(fileitem); } - //qDebug() << "Adding error for file" << realfile << ". Message is" << message; - QList list; list << CreateItem(severity); list << CreateItem(QString("%1").arg(lines[0])); list << CreateItem(message); fileitem->appendRow(list); - - //qDebug()<<"\n"; } QStandardItem *ResultsTree::FindFileItem(const QString &name) diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index eed089cdf..e7e84de54 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -33,22 +33,24 @@ ThreadHandler::~ThreadHandler() void ThreadHandler::ClearFiles() { + mLastFiles.clear(); mResults.ClearFiles(); } void ThreadHandler::SetFiles(const QStringList &files) { mResults.SetFiles(files); + mLastFiles = files; QString file; - qDebug() << "Files to check:"; - foreach(file, files) - { - qDebug() << file; - } } -void ThreadHandler::Check(Settings settings) +void ThreadHandler::Check(Settings settings, bool recheck) { + if (recheck && mRunningThreadCount == 0) + { + mResults.SetFiles(mLastFiles); + } + if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs <= 0) { qDebug() << "Can't start checking if there's no files to check or if check is in progress."; @@ -126,8 +128,6 @@ void ThreadHandler::Stop() { mThreads[i]->terminate(); } - - mResults.ClearFiles(); } void ThreadHandler::Initialize(ResultsView *view) diff --git a/gui/threadhandler.h b/gui/threadhandler.h index 4a704f300..fb0fb89c6 100644 --- a/gui/threadhandler.h +++ b/gui/threadhandler.h @@ -57,7 +57,7 @@ public: */ void SetFiles(const QStringList &files); - void Check(Settings settings); + void Check(Settings settings, bool recheck); signals: @@ -66,6 +66,7 @@ protected slots: void Stop(); void ThreadDone(); protected: + QStringList mLastFiles; void RemoveThreads(); ThreadResult mResults; QList mThreads; From 592ff8ba3cb836263fb55cfa1c702c2f63b06c7d Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 18:46:51 +0200 Subject: [PATCH 04/11] Added view menu and buttons for it. --- gui/mainwindow.cpp | 30 ++++++++++++++++++++++++++++++ gui/mainwindow.h | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d1c1e7f66..646c456da 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -34,6 +34,11 @@ MainWindow::MainWindow() : mActionReCheck(tr("Recheck files"), this), mActionCheckDirectory(tr("Check &directory"), this), mActionSettings(tr("&Settings"), this), + mActionShowAll(tr("Show &more errors"), this), + mActionShowSecurity(tr("Show &security errors"), this), + mActionShowStyle(tr("Show s&tyle errors"), this), + mActionShowUnused(tr("Show errors on &unused functions"), this), + mActionShowErrors(tr("Show &common errors"), this), mResults(mSettings) { QMenu *menu = menuBar()->addMenu(tr("&File")); @@ -44,6 +49,19 @@ MainWindow::MainWindow() : menu->addSeparator(); menu->addAction(&mActionExit); + QMenu *menuview = menuBar()->addMenu(tr("&View")); + mActionShowAll.setCheckable(true); + mActionShowSecurity.setCheckable(true); + mActionShowStyle.setCheckable(true); + mActionShowUnused.setCheckable(true); + mActionShowErrors.setCheckable(true); + + menuview->addAction(&mActionShowAll); + menuview->addAction(&mActionShowSecurity); + menuview->addAction(&mActionShowStyle); + menuview->addAction(&mActionShowUnused); + menuview->addAction(&mActionShowErrors); + QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); menuprogram->addAction(&mActionSettings); @@ -77,6 +95,12 @@ void MainWindow::LoadSettings() resize(mSettings.value(tr("Window width"), 800).toInt(), mSettings.value(tr("Window height"), 600).toInt()); } + + mActionShowAll.setChecked(mSettings.value(tr("Show all"), true).toBool()); + mActionShowSecurity.setChecked(mSettings.value(tr("Show security"), true).toBool()); + mActionShowStyle.setChecked(mSettings.value(tr("Show style"), true).toBool()); + mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool()); + mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool()); } void MainWindow::SaveSettings() @@ -84,6 +108,12 @@ void MainWindow::SaveSettings() mSettings.setValue(tr("Window width"), size().width()); mSettings.setValue(tr("Window height"), size().height()); mSettings.setValue(tr("Window maximized"), isMaximized()); + + mSettings.setValue(tr("Show all"), mActionShowAll.isChecked()); + mSettings.setValue(tr("Show security"), mActionShowSecurity.isChecked()); + mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked()); + mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked()); + mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked()); } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index c735fd0f5..b4df26580 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -130,6 +130,13 @@ protected: */ QAction mActionSettings; + QAction mActionShowAll; + QAction mActionShowSecurity; + QAction mActionShowStyle; + QAction mActionShowUnused; + QAction mActionShowErrors; + + /** * @brief Results for checking From 856b3cd9498ea662fe0d2fd1251ac441dcb0dc10 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:37:26 +0200 Subject: [PATCH 05/11] Can now hide and show results based on cpp flags. --- gui/common.h | 16 +++++++ gui/mainwindow.cpp | 38 +++++++++++++++++ gui/mainwindow.h | 6 +++ gui/resultstree.cpp | 101 +++++++++++++++++++++++++++++++++++++++----- gui/resultstree.h | 20 ++++++++- gui/resultsview.cpp | 5 +++ gui/resultsview.h | 5 +++ 7 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 gui/common.h diff --git a/gui/common.h b/gui/common.h new file mode 100644 index 000000000..3427729a5 --- /dev/null +++ b/gui/common.h @@ -0,0 +1,16 @@ +#ifndef COMMON_H +#define COMMON_H + + +typedef enum +{ + SHOW_ALL, + SHOW_STYLE, + SHOW_SECURITY, + SHOW_UNUSED, + SHOW_ERRORS, + SHOW_NONE +} +ShowTypes; + +#endif diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 646c456da..bf4b1dc6c 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -73,6 +73,13 @@ MainWindow::MainWindow() : connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); + + connect(&mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool))); + connect(&mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool))); + connect(&mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool))); + connect(&mActionShowUnused, SIGNAL(toggled(bool)), this, SLOT(ShowUnused(bool))); + connect(&mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool))); + connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); @@ -101,6 +108,12 @@ void MainWindow::LoadSettings() mActionShowStyle.setChecked(mSettings.value(tr("Show style"), true).toBool()); mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool()); mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool()); + + mResults.ShowResults(SHOW_ALL,mActionShowAll.isChecked()); + mResults.ShowResults(SHOW_ERRORS,mActionShowErrors.isChecked()); + mResults.ShowResults(SHOW_SECURITY,mActionShowSecurity.isChecked()); + mResults.ShowResults(SHOW_STYLE,mActionShowStyle.isChecked()); + mResults.ShowResults(SHOW_UNUSED,mActionShowUnused.isChecked()); } void MainWindow::SaveSettings() @@ -254,3 +267,28 @@ void MainWindow::EnableCheckButtons(bool enable) mActionCheckDirectory.setEnabled(enable); } + +void MainWindow::ShowAll(bool checked) +{ + mResults.ShowResults(SHOW_ALL,checked); +} + +void MainWindow::ShowSecurity(bool checked) +{ + mResults.ShowResults(SHOW_SECURITY,checked); +} + +void MainWindow::ShowStyle(bool checked) +{ + mResults.ShowResults(SHOW_STYLE,checked); +} + +void MainWindow::ShowUnused(bool checked) +{ + mResults.ShowResults(SHOW_UNUSED,checked); +} + +void MainWindow::ShowErrors(bool checked) +{ + mResults.ShowResults(SHOW_ERRORS,checked); +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index b4df26580..e1a9cd538 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -52,6 +52,12 @@ public slots: void ReCheck(); void ClearResults(); + void ShowAll(bool checked); + void ShowSecurity(bool checked); + void ShowStyle(bool checked); + void ShowUnused(bool checked); + void ShowErrors(bool checked); + /** * @brief Slot for check directory menu item * diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 716378072..2b38fbf10 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -63,20 +63,32 @@ void ResultsTree::AddErrorItem(const QString &file, if (realfile.isEmpty()) realfile = "Undefined file"; - QStandardItem *fileitem = FindFileItem(realfile); + ErrorItem item; + item.file = realfile; + item.type = SeverityToShowType(severity); + item.message = message; + item.files = files; + item.lines = lines; + mItems< list; - list << CreateItem(severity); - list << CreateItem(QString("%1").arg(lines[0])); - list << CreateItem(message); - fileitem->appendRow(list); +ShowTypes ResultsTree::SeverityToShowType(const QString &severity) +{ + if (severity == "all") + return SHOW_ALL; + if (severity == "error") + return SHOW_ERRORS; + if (severity == "style") + return SHOW_STYLE; + if (severity == "security") + return SHOW_SECURITY; + + return SHOW_NONE; } QStandardItem *ResultsTree::FindFileItem(const QString &name) @@ -90,6 +102,7 @@ QStandardItem *ResultsTree::FindFileItem(const QString &name) void ResultsTree::Clear() { mModel.removeRows(0, mModel.rowCount()); + mItems.clear(); } void ResultsTree::LoadSettings() @@ -110,3 +123,71 @@ void ResultsTree::SaveSettings() mSettings.setValue(temp, columnWidth(i)); } } + +void ResultsTree::ShowResults(ShowTypes type, bool show) +{ + if (type != SHOW_NONE) + { + if (mShowTypes[type] != show) + { + mShowTypes[type] = show; + RefreshTree(); + } + } +} + + +void ResultsTree::RefreshTree() +{ + mModel.removeRows(0, mModel.rowCount()); + for (int i=0;i= 0 && index < mItems.size()) + { + QStandardItem *fileitem = FindFileItem(mItems[index].file); + if (!fileitem) + { + //qDebug()<<"No previous error for file"< list; + list << CreateItem(ShowTypeToString(mItems[index].type)); + list << CreateItem(QString("%1").arg(mItems[index].lines[0])); + list << CreateItem(mItems[index].message); + fileitem->appendRow(list); + } +} + diff --git a/gui/resultstree.h b/gui/resultstree.h index 2215e3893..6a82fdafe 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -25,7 +25,7 @@ #include #include #include - +#include "common.h" /** * @brief Cppcheck's results are shown in this tree @@ -55,7 +55,23 @@ public: * */ void Clear(); + + void ShowResults(ShowTypes type, bool show); protected: + void AddItem(int index); + void RefreshTree(); + ShowTypes SeverityToShowType(const QString &severity); + QString ShowTypeToString(ShowTypes type); + + typedef struct { + QString file; + ShowTypes type; + QString message; + QStringList files; + QList lines; + }ErrorItem; + + QList mItems; /** * @brief Load all settings * Colum widths @@ -95,6 +111,8 @@ protected: * */ QSettings &mSettings; + + bool mShowTypes[SHOW_NONE]; private: }; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 4a2e9fede..bda7e9005 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -63,3 +63,8 @@ void ResultsView::Error(const QString &file, { mTree->AddErrorItem(file, severity, message, files, lines); } + +void ResultsView::ShowResults(ShowTypes type, bool show) +{ + mTree->ShowResults(type,show); +} diff --git a/gui/resultsview.h b/gui/resultsview.h index bd09d6d5f..f87563da7 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -26,6 +26,8 @@ #include #include "../src/errorlogger.h" #include "resultstree.h" +#include "common.h" + /** * @brief Widget to show cppcheck progressbar and result @@ -35,9 +37,12 @@ class ResultsView : public QWidget { Q_OBJECT public: + ResultsView(QSettings &settings); virtual ~ResultsView(); + void ShowResults(ShowTypes type, bool show); + /** * @brief Clear results * From 55ad06a7b2e284d37edbc8bf9daad0bfcb959619 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:38:03 +0200 Subject: [PATCH 06/11] Astyle formatting. --- gui/mainwindow.cpp | 20 ++++++++++---------- gui/resultstree.cpp | 6 +++--- gui/resultstree.h | 3 ++- gui/resultsview.cpp | 2 +- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index bf4b1dc6c..74051a2aa 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -109,11 +109,11 @@ void MainWindow::LoadSettings() mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool()); mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool()); - mResults.ShowResults(SHOW_ALL,mActionShowAll.isChecked()); - mResults.ShowResults(SHOW_ERRORS,mActionShowErrors.isChecked()); - mResults.ShowResults(SHOW_SECURITY,mActionShowSecurity.isChecked()); - mResults.ShowResults(SHOW_STYLE,mActionShowStyle.isChecked()); - mResults.ShowResults(SHOW_UNUSED,mActionShowUnused.isChecked()); + mResults.ShowResults(SHOW_ALL, mActionShowAll.isChecked()); + mResults.ShowResults(SHOW_ERRORS, mActionShowErrors.isChecked()); + mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked()); + mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked()); + mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked()); } void MainWindow::SaveSettings() @@ -270,25 +270,25 @@ void MainWindow::EnableCheckButtons(bool enable) void MainWindow::ShowAll(bool checked) { - mResults.ShowResults(SHOW_ALL,checked); + mResults.ShowResults(SHOW_ALL, checked); } void MainWindow::ShowSecurity(bool checked) { - mResults.ShowResults(SHOW_SECURITY,checked); + mResults.ShowResults(SHOW_SECURITY, checked); } void MainWindow::ShowStyle(bool checked) { - mResults.ShowResults(SHOW_STYLE,checked); + mResults.ShowResults(SHOW_STYLE, checked); } void MainWindow::ShowUnused(bool checked) { - mResults.ShowResults(SHOW_UNUSED,checked); + mResults.ShowResults(SHOW_UNUSED, checked); } void MainWindow::ShowErrors(bool checked) { - mResults.ShowResults(SHOW_ERRORS,checked); + mResults.ShowResults(SHOW_ERRORS, checked); } diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 2b38fbf10..75faa870e 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -69,11 +69,11 @@ void ResultsTree::AddErrorItem(const QString &file, item.message = message; item.files = files; item.lines = lines; - mItems<ShowResults(type,show); + mTree->ShowResults(type, show); } From 0953995ee3947da7829424bb6c850fba9e3c95db Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:39:44 +0200 Subject: [PATCH 07/11] Merged gui branch to master. --- gui/common.h | 16 +++++++ gui/mainwindow.cpp | 69 ++++++++++++++++++++++++++++++ gui/mainwindow.h | 13 ++++++ gui/resultstree.cpp | 102 +++++++++++++++++++++++++++++++++++++++----- gui/resultstree.h | 21 ++++++++- gui/resultsview.cpp | 5 +++ gui/resultsview.h | 5 +++ 7 files changed, 220 insertions(+), 11 deletions(-) create mode 100644 gui/common.h diff --git a/gui/common.h b/gui/common.h new file mode 100644 index 000000000..3427729a5 --- /dev/null +++ b/gui/common.h @@ -0,0 +1,16 @@ +#ifndef COMMON_H +#define COMMON_H + + +typedef enum +{ + SHOW_ALL, + SHOW_STYLE, + SHOW_SECURITY, + SHOW_UNUSED, + SHOW_ERRORS, + SHOW_NONE +} +ShowTypes; + +#endif diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d1c1e7f66..a8d2ae4cf 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -34,6 +34,11 @@ MainWindow::MainWindow() : mActionReCheck(tr("Recheck files"), this), mActionCheckDirectory(tr("Check &directory"), this), mActionSettings(tr("&Settings"), this), + mActionShowAll(tr("Show &more errors"), this), + mActionShowSecurity(tr("Show &security errors"), this), + mActionShowStyle(tr("Show s&tyle errors"), this), + mActionShowUnused(tr("Show errors on &unused functions"), this), + mActionShowErrors(tr("Show &common errors"), this), mResults(mSettings) { QMenu *menu = menuBar()->addMenu(tr("&File")); @@ -44,6 +49,19 @@ MainWindow::MainWindow() : menu->addSeparator(); menu->addAction(&mActionExit); + QMenu *menuview = menuBar()->addMenu(tr("&View")); + mActionShowAll.setCheckable(true); + mActionShowSecurity.setCheckable(true); + mActionShowStyle.setCheckable(true); + mActionShowUnused.setCheckable(true); + mActionShowErrors.setCheckable(true); + + menuview->addAction(&mActionShowAll); + menuview->addAction(&mActionShowSecurity); + menuview->addAction(&mActionShowStyle); + menuview->addAction(&mActionShowUnused); + menuview->addAction(&mActionShowErrors); + QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); menuprogram->addAction(&mActionSettings); @@ -55,6 +73,13 @@ MainWindow::MainWindow() : connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory())); connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings())); connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults())); + + connect(&mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool))); + connect(&mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool))); + connect(&mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool))); + connect(&mActionShowUnused, SIGNAL(toggled(bool)), this, SLOT(ShowUnused(bool))); + connect(&mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool))); + connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck())); connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); @@ -77,6 +102,18 @@ void MainWindow::LoadSettings() resize(mSettings.value(tr("Window width"), 800).toInt(), mSettings.value(tr("Window height"), 600).toInt()); } + + mActionShowAll.setChecked(mSettings.value(tr("Show all"), true).toBool()); + mActionShowSecurity.setChecked(mSettings.value(tr("Show security"), true).toBool()); + mActionShowStyle.setChecked(mSettings.value(tr("Show style"), true).toBool()); + mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool()); + mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool()); + + mResults.ShowResults(SHOW_ALL, mActionShowAll.isChecked()); + mResults.ShowResults(SHOW_ERRORS, mActionShowErrors.isChecked()); + mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked()); + mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked()); + mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked()); } void MainWindow::SaveSettings() @@ -84,6 +121,12 @@ void MainWindow::SaveSettings() mSettings.setValue(tr("Window width"), size().width()); mSettings.setValue(tr("Window height"), size().height()); mSettings.setValue(tr("Window maximized"), isMaximized()); + + mSettings.setValue(tr("Show all"), mActionShowAll.isChecked()); + mSettings.setValue(tr("Show security"), mActionShowSecurity.isChecked()); + mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked()); + mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked()); + mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked()); } @@ -224,3 +267,29 @@ void MainWindow::EnableCheckButtons(bool enable) mActionCheckDirectory.setEnabled(enable); } + +void MainWindow::ShowAll(bool checked) +{ + mResults.ShowResults(SHOW_ALL, checked); +} + +void MainWindow::ShowSecurity(bool checked) +{ + mResults.ShowResults(SHOW_SECURITY, checked); +} + +void MainWindow::ShowStyle(bool checked) +{ + mResults.ShowResults(SHOW_STYLE, checked); +} + +void MainWindow::ShowUnused(bool checked) +{ + mResults.ShowResults(SHOW_UNUSED, checked); +} + +void MainWindow::ShowErrors(bool checked) +{ + mResults.ShowResults(SHOW_ERRORS, checked); +} + diff --git a/gui/mainwindow.h b/gui/mainwindow.h index c735fd0f5..e1a9cd538 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -52,6 +52,12 @@ public slots: void ReCheck(); void ClearResults(); + void ShowAll(bool checked); + void ShowSecurity(bool checked); + void ShowStyle(bool checked); + void ShowUnused(bool checked); + void ShowErrors(bool checked); + /** * @brief Slot for check directory menu item * @@ -130,6 +136,13 @@ protected: */ QAction mActionSettings; + QAction mActionShowAll; + QAction mActionShowSecurity; + QAction mActionShowStyle; + QAction mActionShowUnused; + QAction mActionShowErrors; + + /** * @brief Results for checking diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 716378072..559fb1b84 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -63,20 +63,33 @@ void ResultsTree::AddErrorItem(const QString &file, if (realfile.isEmpty()) realfile = "Undefined file"; - QStandardItem *fileitem = FindFileItem(realfile); + ErrorItem item; + item.file = realfile; + item.type = SeverityToShowType(severity); + item.message = message; + item.files = files; + item.lines = lines; + mItems << item; - if (!fileitem) + if (mShowTypes[item.type]) { - //qDebug()<<"No previous error for file"< list; - list << CreateItem(severity); - list << CreateItem(QString("%1").arg(lines[0])); - list << CreateItem(message); - fileitem->appendRow(list); + +ShowTypes ResultsTree::SeverityToShowType(const QString &severity) +{ + if (severity == "all") + return SHOW_ALL; + if (severity == "error") + return SHOW_ERRORS; + if (severity == "style") + return SHOW_STYLE; + if (severity == "security") + return SHOW_SECURITY; + + return SHOW_NONE; } QStandardItem *ResultsTree::FindFileItem(const QString &name) @@ -90,6 +103,7 @@ QStandardItem *ResultsTree::FindFileItem(const QString &name) void ResultsTree::Clear() { mModel.removeRows(0, mModel.rowCount()); + mItems.clear(); } void ResultsTree::LoadSettings() @@ -110,3 +124,71 @@ void ResultsTree::SaveSettings() mSettings.setValue(temp, columnWidth(i)); } } + +void ResultsTree::ShowResults(ShowTypes type, bool show) +{ + if (type != SHOW_NONE) + { + if (mShowTypes[type] != show) + { + mShowTypes[type] = show; + RefreshTree(); + } + } +} + + +void ResultsTree::RefreshTree() +{ + mModel.removeRows(0, mModel.rowCount()); + for (int i = 0;i < mItems.size();i++) + { + if (mShowTypes[mItems[i].type]) + { + AddItem(i); + } + } +} + +QString ResultsTree::ShowTypeToString(ShowTypes type) +{ + switch (type) + { + case SHOW_ALL: + return "all"; + case SHOW_ERRORS: + return "error"; + case SHOW_STYLE: + return "style"; + case SHOW_SECURITY: + return "security"; + case SHOW_UNUSED: + return "unused"; + case SHOW_NONE: + return "none"; + } + + return ""; +} + + +void ResultsTree::AddItem(int index) +{ + if (index >= 0 && index < mItems.size()) + { + QStandardItem *fileitem = FindFileItem(mItems[index].file); + if (!fileitem) + { + //qDebug()<<"No previous error for file"< list; + list << CreateItem(ShowTypeToString(mItems[index].type)); + list << CreateItem(QString("%1").arg(mItems[index].lines[0])); + list << CreateItem(mItems[index].message); + fileitem->appendRow(list); + } +} + diff --git a/gui/resultstree.h b/gui/resultstree.h index 2215e3893..89f8bea94 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -25,7 +25,7 @@ #include #include #include - +#include "common.h" /** * @brief Cppcheck's results are shown in this tree @@ -55,7 +55,24 @@ public: * */ void Clear(); + + void ShowResults(ShowTypes type, bool show); protected: + void AddItem(int index); + void RefreshTree(); + ShowTypes SeverityToShowType(const QString &severity); + QString ShowTypeToString(ShowTypes type); + + typedef struct + { + QString file; + ShowTypes type; + QString message; + QStringList files; + QList lines; + }ErrorItem; + + QList mItems; /** * @brief Load all settings * Colum widths @@ -95,6 +112,8 @@ protected: * */ QSettings &mSettings; + + bool mShowTypes[SHOW_NONE]; private: }; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 4a2e9fede..7ea84f9a0 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -63,3 +63,8 @@ void ResultsView::Error(const QString &file, { mTree->AddErrorItem(file, severity, message, files, lines); } + +void ResultsView::ShowResults(ShowTypes type, bool show) +{ + mTree->ShowResults(type, show); +} diff --git a/gui/resultsview.h b/gui/resultsview.h index bd09d6d5f..f87563da7 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -26,6 +26,8 @@ #include #include "../src/errorlogger.h" #include "resultstree.h" +#include "common.h" + /** * @brief Widget to show cppcheck progressbar and result @@ -35,9 +37,12 @@ class ResultsView : public QWidget { Q_OBJECT public: + ResultsView(QSettings &settings); virtual ~ResultsView(); + void ShowResults(ShowTypes type, bool show); + /** * @brief Clear results * From 855dda69b7dbb2ef2a59ff01a61959875521a8f6 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:40:29 +0200 Subject: [PATCH 08/11] Conflicts: gui/mainwindow.cpp gui/resultstree.cpp --- gui/mainwindow.cpp | 3 +++ gui/resultstree.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index a8d2ae4cf..3f20e7bc5 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -292,4 +292,7 @@ void MainWindow::ShowErrors(bool checked) { mResults.ShowResults(SHOW_ERRORS, checked); } +<<<<<<< HEAD:gui/mainwindow.cpp +======= +>>>>>>> gui:gui/mainwindow.cpp diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 559fb1b84..a32a48f87 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -77,7 +77,10 @@ void ResultsTree::AddErrorItem(const QString &file, } } +<<<<<<< HEAD:gui/resultstree.cpp +======= +>>>>>>> gui:gui/resultstree.cpp ShowTypes ResultsTree::SeverityToShowType(const QString &severity) { if (severity == "all") From 1e66d7f0e44949fc56e57b93cf1c106b736a363e Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:41:32 +0200 Subject: [PATCH 09/11] Merge conflicts. --- gui/mainwindow.cpp | 4 ---- gui/resultstree.cpp | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3f20e7bc5..74051a2aa 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -292,7 +292,3 @@ void MainWindow::ShowErrors(bool checked) { mResults.ShowResults(SHOW_ERRORS, checked); } -<<<<<<< HEAD:gui/mainwindow.cpp - -======= ->>>>>>> gui:gui/mainwindow.cpp diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index a32a48f87..574546030 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -77,11 +77,8 @@ void ResultsTree::AddErrorItem(const QString &file, } } -<<<<<<< HEAD:gui/resultstree.cpp -======= ->>>>>>> gui:gui/resultstree.cpp -ShowTypes ResultsTree::SeverityToShowType(const QString &severity) +ShowTypes ResultsTree::SeverityToShowType(const QString & severity) { if (severity == "all") return SHOW_ALL; From 31845a89bca381f18af9cbf9e74a6ec9a68d9589 Mon Sep 17 00:00:00 2001 From: Vesa Pikki Date: Sun, 22 Mar 2009 19:47:25 +0200 Subject: [PATCH 10/11] Added license text. --- gui/common.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gui/common.h b/gui/common.h index 3427729a5..2cebde2e1 100644 --- a/gui/common.h +++ b/gui/common.h @@ -1,3 +1,22 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam, + * Leandro Penz, Kimmo Varis, Vesa Pikki + * + * 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 Date: Sun, 22 Mar 2009 19:51:49 +0200 Subject: [PATCH 11/11] Added a window title. --- gui/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 74051a2aa..64166a74d 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -84,6 +84,7 @@ MainWindow::MainWindow() : connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); LoadSettings(); mThread.Initialize(&mResults); + setWindowTitle(tr("CppCheck")); } MainWindow::~MainWindow()