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 *