From 00ae7dbda3f6d2410c8b2aa0cdd3742cebf1ae67 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 11 Oct 2011 22:14:15 +0300 Subject: [PATCH] GUI: Move ShowTypes enum to own class and file. We are using ShowTypes around the GUI codebase so it makes sense to have it in its own class. And the class also contains related helper functions instead of scattering them around different classes. ShowTypes also contains the visibility settings for all the GUI severities. Implementation in this commit makes ShowTypes class to load the visibility settings when it is created. And save the settings when it is destroyed. --- gui/checkstatistics.cpp | 32 ++++----- gui/checkstatistics.h | 5 +- gui/common.h | 16 ----- gui/gui.pro | 8 ++- gui/mainwindow.cpp | 34 ++++------ gui/resultstree.cpp | 92 +++----------------------- gui/resultstree.h | 34 ++-------- gui/resultsview.cpp | 4 +- gui/resultsview.h | 19 ++++-- gui/showtypes.cpp | 140 ++++++++++++++++++++++++++++++++++++++++ gui/showtypes.h | 126 ++++++++++++++++++++++++++++++++++++ gui/statsdialog.cpp | 36 +++++------ 12 files changed, 355 insertions(+), 191 deletions(-) create mode 100644 gui/showtypes.cpp create mode 100644 gui/showtypes.h diff --git a/gui/checkstatistics.cpp b/gui/checkstatistics.cpp index 4f031e5c8..4f431ae7f 100644 --- a/gui/checkstatistics.cpp +++ b/gui/checkstatistics.cpp @@ -26,29 +26,29 @@ CheckStatistics::CheckStatistics(QObject *parent) Clear(); } -void CheckStatistics::AddItem(ShowTypes type) +void CheckStatistics::AddItem(ShowTypes::ShowType type) { switch (type) { - case SHOW_STYLE: + case ShowTypes::ShowStyle: mStyle++; break; - case SHOW_WARNINGS: + case ShowTypes::ShowWarnings: mWarning++; break; - case SHOW_PERFORMANCE: + case ShowTypes::ShowPerformance: mPerformance++; break; - case SHOW_PORTABILITY: + case ShowTypes::ShowPortability: mPortability++; break; - case SHOW_ERRORS: + case ShowTypes::ShowErrors: mError++; break; - case SHOW_INFORMATION: + case ShowTypes::ShowInformation: mInformation++; break; - case SHOW_NONE: + case ShowTypes::ShowNone: default: qDebug() << "Unknown error type - not added to statistics."; break; @@ -65,30 +65,30 @@ void CheckStatistics::Clear() mError = 0; } -unsigned CheckStatistics::GetCount(ShowTypes type) const +unsigned CheckStatistics::GetCount(ShowTypes::ShowType type) const { unsigned count = 0; switch (type) { - case SHOW_STYLE: + case ShowTypes::ShowStyle: count = mStyle; break; - case SHOW_WARNINGS: + case ShowTypes::ShowWarnings: count = mWarning; break; - case SHOW_PERFORMANCE: + case ShowTypes::ShowPerformance: count = mPerformance; break; - case SHOW_PORTABILITY: + case ShowTypes::ShowPortability: count = mPortability; break; - case SHOW_ERRORS: + case ShowTypes::ShowErrors: count = mError; break; - case SHOW_INFORMATION: + case ShowTypes::ShowInformation: count = mInformation; break; - case SHOW_NONE: + case ShowTypes::ShowNone: default: qDebug() << "Unknown error type - returning zero statistics."; break; diff --git a/gui/checkstatistics.h b/gui/checkstatistics.h index f21b84643..0c44d6626 100644 --- a/gui/checkstatistics.h +++ b/gui/checkstatistics.h @@ -21,6 +21,7 @@ #include #include "common.h" +#include "showtypes.h" /// @addtogroup GUI /// @{ @@ -38,7 +39,7 @@ public: * * @param type Type of the item to add. */ - void AddItem(ShowTypes type); + void AddItem(ShowTypes::ShowType type); /** * @brief Clear the statistics. @@ -52,7 +53,7 @@ public: * @param type Type for which the statistics are returned. * @return Number of items of given type. */ - unsigned GetCount(ShowTypes type) const; + unsigned GetCount(ShowTypes::ShowType type) const; private: unsigned mStyle; diff --git a/gui/common.h b/gui/common.h index 3c9bace3e..cf1b71a55 100644 --- a/gui/common.h +++ b/gui/common.h @@ -23,22 +23,6 @@ /// @{ -/** -* @brief List of error types to show -* -*/ -typedef enum -{ - SHOW_STYLE = 0, - SHOW_WARNINGS, - SHOW_PERFORMANCE, - SHOW_PORTABILITY, - SHOW_INFORMATION, - SHOW_ERRORS, // Keep this as last real item - SHOW_NONE -} -ShowTypes; - /** * QSetting value names */ diff --git a/gui/gui.pro b/gui/gui.pro index 1d68a5569..e97603352 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -78,7 +78,8 @@ HEADERS += aboutdialog.h \ txtreport.h \ xmlreport.h \ xmlreportv1.h \ - xmlreportv2.h + xmlreportv2.h \ + showtypes.h SOURCES += aboutdialog.cpp \ application.cpp \ @@ -108,7 +109,8 @@ SOURCES += aboutdialog.cpp \ txtreport.cpp \ xmlreport.cpp \ xmlreportv1.cpp \ - xmlreportv2.cpp + xmlreportv2.cpp \ + showtypes.cpp win32 { DEFINES += _CRT_SECURE_NO_WARNINGS @@ -116,3 +118,5 @@ win32 { HEADERS += ../cli/resource.h LIBS += -lshlwapi } + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e554d0deb..4d318020a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -38,6 +38,7 @@ #include "statsdialog.h" #include "logview.h" #include "filelist.h" +#include "showtypes.h" static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html"); @@ -210,20 +211,13 @@ void MainWindow::LoadSettings() mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt()); } - // Show * states - mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool()); - mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool()); - mUI.mActionShowWarnings->setChecked(mSettings->value(SETTINGS_SHOW_WARNINGS, true).toBool()); - mUI.mActionShowPortability->setChecked(mSettings->value(SETTINGS_SHOW_PORTABILITY, true).toBool()); - mUI.mActionShowPerformance->setChecked(mSettings->value(SETTINGS_SHOW_PERFORMANCE, true).toBool()); - mUI.mActionShowInformation->setChecked(mSettings->value(SETTINGS_SHOW_INFORMATION, true).toBool()); - - mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked()); - mUI.mResults->ShowResults(SHOW_WARNINGS, mUI.mActionShowWarnings->isChecked()); - mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked()); - mUI.mResults->ShowResults(SHOW_PORTABILITY, mUI.mActionShowPortability->isChecked()); - mUI.mResults->ShowResults(SHOW_PERFORMANCE, mUI.mActionShowPerformance->isChecked()); - mUI.mResults->ShowResults(SHOW_INFORMATION, mUI.mActionShowInformation->isChecked()); + ShowTypes *types = mUI.mResults->GetShowTypes(); + mUI.mActionShowStyle->setChecked(types->isShown(ShowTypes::ShowStyle)); + mUI.mActionShowErrors->setChecked(types->isShown(ShowTypes::ShowErrors)); + mUI.mActionShowWarnings->setChecked(types->isShown(ShowTypes::ShowWarnings)); + mUI.mActionShowPortability->setChecked(types->isShown(ShowTypes::ShowPortability)); + mUI.mActionShowPerformance->setChecked(types->isShown(ShowTypes::ShowPerformance)); + mUI.mActionShowInformation->setChecked(types->isShown(ShowTypes::ShowInformation)); // Main window settings const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool(); @@ -628,32 +622,32 @@ void MainWindow::EnableCheckButtons(bool enable) void MainWindow::ShowStyle(bool checked) { - mUI.mResults->ShowResults(SHOW_STYLE, checked); + mUI.mResults->ShowResults(ShowTypes::ShowStyle, checked); } void MainWindow::ShowErrors(bool checked) { - mUI.mResults->ShowResults(SHOW_ERRORS, checked); + mUI.mResults->ShowResults(ShowTypes::ShowErrors, checked); } void MainWindow::ShowWarnings(bool checked) { - mUI.mResults->ShowResults(SHOW_WARNINGS, checked); + mUI.mResults->ShowResults(ShowTypes::ShowWarnings, checked); } void MainWindow::ShowPortability(bool checked) { - mUI.mResults->ShowResults(SHOW_PORTABILITY, checked); + mUI.mResults->ShowResults(ShowTypes::ShowPortability, checked); } void MainWindow::ShowPerformance(bool checked) { - mUI.mResults->ShowResults(SHOW_PERFORMANCE, checked); + mUI.mResults->ShowResults(ShowTypes::ShowPerformance, checked); } void MainWindow::ShowInformation(bool checked) { - mUI.mResults->ShowResults(SHOW_INFORMATION, checked); + mUI.mResults->ShowResults(ShowTypes::ShowInformation, checked); } void MainWindow::CheckAll() diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 02b29cbf2..bb02cdc92 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -45,6 +45,7 @@ #include "report.h" #include "xmlreport.h" #include "application.h" +#include "showtypes.h" ResultsTree::ResultsTree(QWidget * parent) : QTreeView(parent), @@ -52,9 +53,6 @@ ResultsTree::ResultsTree(QWidget * parent) : mVisibleErrors(false), mSelectionModel(0) { - for (int i = 0; i < SHOW_NONE; i++) - mShowTypes[i] = false; - setModel(&mModel); QStringList labels; labels << tr("File") << tr("Severity") << tr("Line") << tr("Summary"); @@ -110,7 +108,8 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) realfile = tr("Undefined file"); } - bool hide = !mShowTypes[SeverityToShowType(item.severity)]; + bool hide = !mShowSeverities.isShown(item.severity); + //bool hide = !mShowTypes[SeverityToShowType(item.severity)]; //If specified, filter on summary, message, filename, and id if (!hide && !mFilter.isEmpty()) @@ -151,7 +150,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) //Add user data to that item QMap data; data["hide"] = false; - data["severity"] = SeverityToShowType(item.severity); + data["severity"] = ShowTypes::SeverityToShowType(item.severity); data["summary"] = item.summary; data["message"] = item.message; data["file"] = item.files[0]; @@ -173,7 +172,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) //Add user data to that item QMap child_data; - child_data["severity"] = SeverityToShowType(line.severity); + child_data["severity"] = ShowTypes::SeverityToShowType(line.severity); child_data["summary"] = line.summary; child_data["message"] = line.message; child_data["file"] = item.files[i]; @@ -265,77 +264,6 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent, return list[0]; } -ShowTypes ResultsTree::VariantToShowType(const QVariant &data) -{ - int value = data.toInt(); - if (value < SHOW_STYLE || value > SHOW_ERRORS) - { - return SHOW_NONE; - } - return (ShowTypes)value; -} - -ShowTypes ResultsTree::SeverityToShowType(Severity::SeverityType severity) -{ - switch (severity) - { - case Severity::none: - return SHOW_NONE; - case Severity::error: - return SHOW_ERRORS; - case Severity::style: - return SHOW_STYLE; - case Severity::warning: - return SHOW_WARNINGS; - case Severity::performance: - return SHOW_PERFORMANCE; - case Severity::portability: - return SHOW_PORTABILITY; - case Severity::information: - return SHOW_INFORMATION; - default: - return SHOW_NONE; - } - - return SHOW_NONE; -} - -Severity::SeverityType ResultsTree::ShowTypeToSeverity(ShowTypes type) -{ - switch (type) - { - case SHOW_STYLE: - return Severity::style; - break; - - case SHOW_ERRORS: - return Severity::error; - break; - - case SHOW_WARNINGS: - return Severity::warning; - break; - - case SHOW_PERFORMANCE: - return Severity::performance; - break; - - case SHOW_PORTABILITY: - return Severity::portability; - break; - - case SHOW_INFORMATION: - return Severity::information; - break; - - case SHOW_NONE: - return Severity::none; - break; - } - - return Severity::none; -} - QString ResultsTree::SeverityToTranslatedString(Severity::SeverityType severity) { switch (severity) @@ -414,11 +342,11 @@ void ResultsTree::SaveSettings() } } -void ResultsTree::ShowResults(ShowTypes type, bool show) +void ResultsTree::ShowResults(ShowTypes::ShowType type, bool show) { - if (type != SHOW_NONE && mShowTypes[type] != show) + if (type != ShowTypes::ShowNone && mShowSeverities.isShown(type) != show) { - mShowTypes[type] = show; + mShowSeverities.show(type, show); RefreshTree(); } } @@ -496,7 +424,7 @@ void ResultsTree::RefreshTree() QVariantMap data = userdata.toMap(); //Check if this error should be hidden - bool hide = (data["hide"].toBool() || !mShowTypes[VariantToShowType(data["severity"])]); + bool hide = (data["hide"].toBool() || !mShowSeverities.isShown(ShowTypes::VariantToShowType(data["severity"]))); //If specified, filter on summary, message, filename, and id if (!hide && !mFilter.isEmpty()) @@ -961,7 +889,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) QVariantMap data = userdata.toMap(); ErrorItem item; - item.severity = ShowTypeToSeverity(VariantToShowType(data["severity"])); + item.severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data["severity"])); item.summary = data["summary"].toString(); item.message = data["message"].toString(); item.id = data["id"].toString(); diff --git a/gui/resultstree.h b/gui/resultstree.h index 7cee9917c..ceae73a72 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -29,6 +29,7 @@ #include "common.h" #include "applicationlist.h" #include "errorlogger.h" // Severity +#include "showtypes.h" class Report; class ErrorItem; @@ -73,7 +74,7 @@ public: * @param type Type of error to show/hide * @param show Should specified errors be shown (true) or hidden (false) */ - void ShowResults(ShowTypes type, bool show); + void ShowResults(ShowTypes::ShowType type, bool show); /** * @brief Function to filter the displayed list of errors. @@ -136,11 +137,10 @@ public: void Translate(); /** - * @brief Convert severity string to ShowTypes value - * @param severity Error severity - * @return Severity converted to ShowTypes value - */ - static ShowTypes SeverityToShowType(Severity::SeverityType severity); + * @brief GUI severities. + */ + ShowTypes mShowSeverities; + signals: /** @@ -289,21 +289,6 @@ protected: */ void RefreshTree(); - /** - * @brief Convert QVariant (that contains an int) to Showtypes value - * - * @param data QVariant (that contains an int) to be converted - * @return data converted to ShowTypes - */ - ShowTypes VariantToShowType(const QVariant &data); - - /** - * @brief Convert ShowType to severity string - * @param type ShowType to convert - * @return ShowType converted to severity - */ - Severity::SeverityType ShowTypeToSeverity(ShowTypes type); - /** * @brief Convert Severity to translated string for GUI. * @param type Severity to convert @@ -379,13 +364,6 @@ protected: */ QSettings *mSettings; - /** - * @brief List of bools to determine which of ShowTypes to display on the tree - * (true) and which of them should be hidden (false) - * - */ - bool mShowTypes[SHOW_NONE]; - /** * @brief A string used to filter the results for display. * diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index cb4d9caec..bd4a692e3 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -91,10 +91,10 @@ void ResultsView::Error(const ErrorItem &item) mErrorsFound = true; mUI.mTree->AddErrorItem(item); emit GotResults(); - mStatistics->AddItem(ResultsTree::SeverityToShowType(item.severity)); + mStatistics->AddItem(ShowTypes::SeverityToShowType(item.severity)); } -void ResultsView::ShowResults(ShowTypes type, bool show) +void ResultsView::ShowResults(ShowTypes::ShowType type, bool show) { mUI.mTree->ShowResults(type, show); } diff --git a/gui/resultsview.h b/gui/resultsview.h index 068e08062..72ad81c40 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -25,6 +25,7 @@ #include "errorlogger.h" #include "common.h" #include "report.h" +#include "showtypes.h" #include "ui_resultsview.h" class ErrorItem; @@ -56,7 +57,7 @@ public: * @param type Type of error to show/hide * @param show Should specified errors be shown (true) or hidden (false) */ - void ShowResults(ShowTypes type, bool show); + void ShowResults(ShowTypes::ShowType type, bool show); /** * @brief Clear results @@ -143,15 +144,23 @@ public: void ReadErrorsXml(const QString &filename); /** - * @brief Return checking statistics. - * @param Pointer to checking statistics. - * - */ + * @brief Return checking statistics. + * @return Pointer to checking statistics. + */ CheckStatistics *GetStatistics() const { return mStatistics; } + /** + * @brief Return Showtypes. + * @return Pointer to Showtypes. + */ + ShowTypes * GetShowTypes() const + { + return &mUI.mTree->mShowSeverities; + } + signals: /** diff --git a/gui/showtypes.cpp b/gui/showtypes.cpp new file mode 100644 index 000000000..b1a6e6883 --- /dev/null +++ b/gui/showtypes.cpp @@ -0,0 +1,140 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 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 "common.h" +#include "showtypes.h" +#include "errorlogger.h" + +ShowTypes::ShowTypes() +{ + load(); +} + +ShowTypes::~ShowTypes() +{ + save(); +} + +ShowTypes::ShowType ShowTypes::SeverityToShowType(Severity::SeverityType severity) +{ + switch (severity) + { + case Severity::none: + return ShowTypes::ShowNone; + case Severity::error: + return ShowTypes::ShowErrors; + case Severity::style: + return ShowTypes::ShowStyle; + case Severity::warning: + return ShowTypes::ShowWarnings; + case Severity::performance: + return ShowTypes::ShowPerformance; + case Severity::portability: + return ShowTypes::ShowPortability; + case Severity::information: + return ShowTypes::ShowPortability; + default: + return ShowTypes::ShowPortability; + } + + return ShowTypes::ShowNone; +} + +Severity::SeverityType ShowTypes::ShowTypeToSeverity(ShowTypes::ShowType type) +{ + switch (type) + { + case ShowTypes::ShowStyle: + return Severity::style; + break; + + case ShowTypes::ShowErrors: + return Severity::error; + break; + + case ShowTypes::ShowWarnings: + return Severity::warning; + break; + + case ShowTypes::ShowPerformance: + return Severity::performance; + break; + + case ShowTypes::ShowPortability: + return Severity::portability; + break; + + case ShowTypes::ShowInformation: + return Severity::information; + break; + + case ShowTypes::ShowNone: + return Severity::none; + break; + } + + return Severity::none; +} + +ShowTypes::ShowType ShowTypes::VariantToShowType(const QVariant &data) +{ + const int value = data.toInt(); + if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) + { + return ShowTypes::ShowNone; + } + return (ShowTypes::ShowType)value; +} + +void ShowTypes::load() +{ + QSettings settings; + mVisible[ShowStyle] = settings.value(SETTINGS_SHOW_STYLE, true).toBool(); + mVisible[ShowErrors] = settings.value(SETTINGS_SHOW_ERRORS, true).toBool(); + mVisible[ShowWarnings] = settings.value(SETTINGS_SHOW_WARNINGS, true).toBool(); + mVisible[ShowPortability] = settings.value(SETTINGS_SHOW_PORTABILITY, true).toBool(); + mVisible[ShowPerformance] = settings.value(SETTINGS_SHOW_PERFORMANCE, true).toBool(); + mVisible[ShowInformation] = settings.value(SETTINGS_SHOW_INFORMATION, true).toBool(); +} + +void ShowTypes::save() +{ + QSettings settings; + settings.setValue(SETTINGS_SHOW_STYLE, mVisible[ShowStyle]); + settings.setValue(SETTINGS_SHOW_ERRORS, mVisible[ShowErrors]); + settings.setValue(SETTINGS_SHOW_WARNINGS, mVisible[ShowWarnings]); + settings.setValue(SETTINGS_SHOW_PORTABILITY, mVisible[ShowPortability]); + settings.setValue(SETTINGS_SHOW_PERFORMANCE, mVisible[ShowPerformance]); + settings.setValue(SETTINGS_SHOW_INFORMATION, mVisible[ShowInformation]); +} + +bool ShowTypes::isShown(ShowTypes::ShowType category) const +{ + return mVisible[category]; +} + +bool ShowTypes::isShown(Severity::SeverityType severity) const +{ + return isShown(ShowTypes::SeverityToShowType(severity)); +} + +void ShowTypes::show(ShowTypes::ShowType category, bool show) +{ + mVisible[category] = show; +} diff --git a/gui/showtypes.h b/gui/showtypes.h new file mode 100644 index 000000000..197fd3100 --- /dev/null +++ b/gui/showtypes.h @@ -0,0 +1,126 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2011 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 SHOWTYPES_H +#define SHOWTYPES_H + +#include +#include "errorlogger.h" + +/// @addtogroup GUI +/// @{ + +/** + * @brief A class for different show types we have. + * This class contains enum type for the different show types we have. Each + * show type presents one severity selectable in the GUI. In addition there + * are several supporting functions. + * + * Notice that the "visibility" settings are automatically loaded when the + * class is constructed and saved when the class is destroyed. + */ +class ShowTypes +{ +public: + + /** + * @brief Show types we have (i.e. severities in the GUI). + */ + enum ShowType + { + ShowStyle = 0, + ShowWarnings, + ShowPerformance, + ShowPortability, + ShowInformation, + ShowErrors, // Keep this as last real item + ShowNone + }; + + /** + * @brief Constructor. + * @note Loads visibility settings. + */ + ShowTypes(); + + /** + * @brief Destructor. + * @note Saves visibility settings. + */ + ~ShowTypes(); + + /** + * @brief Load visibility settings from the platform's settings storage. + */ + void load(); + + /** + * @brief Save visibility settings to the platform's settings storage. + */ + void save(); + + /** + * @brief Is the showtype visible in the GUI? + * @param category Showtype to check. + * @return true if the showtype is visible. + */ + bool isShown(ShowTypes::ShowType category) const; + + /** + * @brief Is the severity visible in the GUI? + * @param severity severity to check. + * @return true if the severity is visible. + */ + bool isShown(Severity::SeverityType severity) const; + + /** + * @brief Show/hide the showtype. + * @param category Showtype whose visibility to set. + * @return true if the severity is set visible. + */ + void show(ShowTypes::ShowType category, bool show); + + /** + * @brief Convert severity string to ShowTypes value + * @param severity Error severity + * @return Severity converted to ShowTypes value + */ + static ShowTypes::ShowType SeverityToShowType(Severity::SeverityType severity); + + /** + * @brief Convert ShowType to severity string + * @param type ShowType to convert + * @return ShowType converted to severity + */ + static Severity::SeverityType ShowTypeToSeverity(ShowTypes::ShowType type); + + /** + * @brief Convert QVariant (that contains an int) to Showtypes value + * + * @param data QVariant (that contains an int) to be converted + * @return data converted to ShowTypes + */ + static ShowTypes::ShowType VariantToShowType(const QVariant &data); + + bool mVisible[ShowNone]; +}; + + +/// @} + +#endif // SHOWTYPES_H diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 0582d9f57..903aed807 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -158,17 +158,17 @@ void StatsDialog::copyToClipboard() ) .arg(stats) .arg(errors) - .arg(mStatistics->GetCount(SHOW_ERRORS)) + .arg(mStatistics->GetCount(ShowTypes::ShowErrors)) .arg(warnings) - .arg(mStatistics->GetCount(SHOW_WARNINGS)) + .arg(mStatistics->GetCount(ShowTypes::ShowWarnings)) .arg(style) - .arg(mStatistics->GetCount(SHOW_STYLE)) + .arg(mStatistics->GetCount(ShowTypes::ShowStyle)) .arg(portability) - .arg(mStatistics->GetCount(SHOW_PORTABILITY)) + .arg(mStatistics->GetCount(ShowTypes::ShowPortability)) .arg(performance) - .arg(mStatistics->GetCount(SHOW_PERFORMANCE)) + .arg(mStatistics->GetCount(ShowTypes::ShowPerformance)) .arg(information) - .arg(mStatistics->GetCount(SHOW_INFORMATION)); + .arg(mStatistics->GetCount(ShowTypes::ShowInformation)); const QString textSummary = settings + previous + statistics; @@ -220,17 +220,17 @@ void StatsDialog::copyToClipboard() ) .arg(stats) .arg(errors) - .arg(mStatistics->GetCount(SHOW_ERRORS)) + .arg(mStatistics->GetCount(ShowTypes::ShowErrors)) .arg(warnings) - .arg(mStatistics->GetCount(SHOW_WARNINGS)) + .arg(mStatistics->GetCount(ShowTypes::ShowWarnings)) .arg(style) - .arg(mStatistics->GetCount(SHOW_STYLE)) + .arg(mStatistics->GetCount(ShowTypes::ShowStyle)) .arg(portability) - .arg(mStatistics->GetCount(SHOW_PORTABILITY)) + .arg(mStatistics->GetCount(ShowTypes::ShowPortability)) .arg(performance) - .arg(mStatistics->GetCount(SHOW_PERFORMANCE)) + .arg(mStatistics->GetCount(ShowTypes::ShowPerformance)) .arg(information) - .arg(mStatistics->GetCount(SHOW_INFORMATION)); + .arg(mStatistics->GetCount(ShowTypes::ShowInformation)); const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics; @@ -244,10 +244,10 @@ void StatsDialog::copyToClipboard() void StatsDialog::setStatistics(const CheckStatistics *stats) { mStatistics = const_cast(stats); - mUI.mLblErrors->setText(QString("%1").arg(stats->GetCount(SHOW_ERRORS))); - mUI.mLblWarnings->setText(QString("%1").arg(stats->GetCount(SHOW_WARNINGS))); - mUI.mLblStyle->setText(QString("%1").arg(stats->GetCount(SHOW_STYLE))); - mUI.mLblPortability->setText(QString("%1").arg(stats->GetCount(SHOW_PORTABILITY))); - mUI.mLblPerformance->setText(QString("%1").arg(stats->GetCount(SHOW_PERFORMANCE))); - mUI.mLblInformation->setText(QString("%1").arg(stats->GetCount(SHOW_INFORMATION))); + mUI.mLblErrors->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowErrors))); + mUI.mLblWarnings->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowWarnings))); + mUI.mLblStyle->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowStyle))); + mUI.mLblPortability->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowPortability))); + mUI.mLblPerformance->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowPerformance))); + mUI.mLblInformation->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowInformation))); }