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.
This commit is contained in:
Kimmo Varis 2011-10-11 22:14:15 +03:00
parent 849bee8437
commit 00ae7dbda3
12 changed files with 355 additions and 191 deletions

View File

@ -26,29 +26,29 @@ CheckStatistics::CheckStatistics(QObject *parent)
Clear(); Clear();
} }
void CheckStatistics::AddItem(ShowTypes type) void CheckStatistics::AddItem(ShowTypes::ShowType type)
{ {
switch (type) switch (type)
{ {
case SHOW_STYLE: case ShowTypes::ShowStyle:
mStyle++; mStyle++;
break; break;
case SHOW_WARNINGS: case ShowTypes::ShowWarnings:
mWarning++; mWarning++;
break; break;
case SHOW_PERFORMANCE: case ShowTypes::ShowPerformance:
mPerformance++; mPerformance++;
break; break;
case SHOW_PORTABILITY: case ShowTypes::ShowPortability:
mPortability++; mPortability++;
break; break;
case SHOW_ERRORS: case ShowTypes::ShowErrors:
mError++; mError++;
break; break;
case SHOW_INFORMATION: case ShowTypes::ShowInformation:
mInformation++; mInformation++;
break; break;
case SHOW_NONE: case ShowTypes::ShowNone:
default: default:
qDebug() << "Unknown error type - not added to statistics."; qDebug() << "Unknown error type - not added to statistics.";
break; break;
@ -65,30 +65,30 @@ void CheckStatistics::Clear()
mError = 0; mError = 0;
} }
unsigned CheckStatistics::GetCount(ShowTypes type) const unsigned CheckStatistics::GetCount(ShowTypes::ShowType type) const
{ {
unsigned count = 0; unsigned count = 0;
switch (type) switch (type)
{ {
case SHOW_STYLE: case ShowTypes::ShowStyle:
count = mStyle; count = mStyle;
break; break;
case SHOW_WARNINGS: case ShowTypes::ShowWarnings:
count = mWarning; count = mWarning;
break; break;
case SHOW_PERFORMANCE: case ShowTypes::ShowPerformance:
count = mPerformance; count = mPerformance;
break; break;
case SHOW_PORTABILITY: case ShowTypes::ShowPortability:
count = mPortability; count = mPortability;
break; break;
case SHOW_ERRORS: case ShowTypes::ShowErrors:
count = mError; count = mError;
break; break;
case SHOW_INFORMATION: case ShowTypes::ShowInformation:
count = mInformation; count = mInformation;
break; break;
case SHOW_NONE: case ShowTypes::ShowNone:
default: default:
qDebug() << "Unknown error type - returning zero statistics."; qDebug() << "Unknown error type - returning zero statistics.";
break; break;

View File

@ -21,6 +21,7 @@
#include <QObject> #include <QObject>
#include "common.h" #include "common.h"
#include "showtypes.h"
/// @addtogroup GUI /// @addtogroup GUI
/// @{ /// @{
@ -38,7 +39,7 @@ public:
* *
* @param type Type of the item to add. * @param type Type of the item to add.
*/ */
void AddItem(ShowTypes type); void AddItem(ShowTypes::ShowType type);
/** /**
* @brief Clear the statistics. * @brief Clear the statistics.
@ -52,7 +53,7 @@ public:
* @param type Type for which the statistics are returned. * @param type Type for which the statistics are returned.
* @return Number of items of given type. * @return Number of items of given type.
*/ */
unsigned GetCount(ShowTypes type) const; unsigned GetCount(ShowTypes::ShowType type) const;
private: private:
unsigned mStyle; unsigned mStyle;

View File

@ -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 * QSetting value names
*/ */

View File

@ -78,7 +78,8 @@ HEADERS += aboutdialog.h \
txtreport.h \ txtreport.h \
xmlreport.h \ xmlreport.h \
xmlreportv1.h \ xmlreportv1.h \
xmlreportv2.h xmlreportv2.h \
showtypes.h
SOURCES += aboutdialog.cpp \ SOURCES += aboutdialog.cpp \
application.cpp \ application.cpp \
@ -108,7 +109,8 @@ SOURCES += aboutdialog.cpp \
txtreport.cpp \ txtreport.cpp \
xmlreport.cpp \ xmlreport.cpp \
xmlreportv1.cpp \ xmlreportv1.cpp \
xmlreportv2.cpp xmlreportv2.cpp \
showtypes.cpp
win32 { win32 {
DEFINES += _CRT_SECURE_NO_WARNINGS DEFINES += _CRT_SECURE_NO_WARNINGS
@ -116,3 +118,5 @@ win32 {
HEADERS += ../cli/resource.h HEADERS += ../cli/resource.h
LIBS += -lshlwapi LIBS += -lshlwapi
} }

View File

@ -38,6 +38,7 @@
#include "statsdialog.h" #include "statsdialog.h"
#include "logview.h" #include "logview.h"
#include "filelist.h" #include "filelist.h"
#include "showtypes.h"
static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html"); static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html");
@ -210,20 +211,13 @@ void MainWindow::LoadSettings()
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt()); mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
} }
// Show * states ShowTypes *types = mUI.mResults->GetShowTypes();
mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool()); mUI.mActionShowStyle->setChecked(types->isShown(ShowTypes::ShowStyle));
mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool()); mUI.mActionShowErrors->setChecked(types->isShown(ShowTypes::ShowErrors));
mUI.mActionShowWarnings->setChecked(mSettings->value(SETTINGS_SHOW_WARNINGS, true).toBool()); mUI.mActionShowWarnings->setChecked(types->isShown(ShowTypes::ShowWarnings));
mUI.mActionShowPortability->setChecked(mSettings->value(SETTINGS_SHOW_PORTABILITY, true).toBool()); mUI.mActionShowPortability->setChecked(types->isShown(ShowTypes::ShowPortability));
mUI.mActionShowPerformance->setChecked(mSettings->value(SETTINGS_SHOW_PERFORMANCE, true).toBool()); mUI.mActionShowPerformance->setChecked(types->isShown(ShowTypes::ShowPerformance));
mUI.mActionShowInformation->setChecked(mSettings->value(SETTINGS_SHOW_INFORMATION, true).toBool()); mUI.mActionShowInformation->setChecked(types->isShown(ShowTypes::ShowInformation));
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());
// Main window settings // Main window settings
const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool(); 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) void MainWindow::ShowStyle(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_STYLE, checked); mUI.mResults->ShowResults(ShowTypes::ShowStyle, checked);
} }
void MainWindow::ShowErrors(bool checked) void MainWindow::ShowErrors(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_ERRORS, checked); mUI.mResults->ShowResults(ShowTypes::ShowErrors, checked);
} }
void MainWindow::ShowWarnings(bool checked) void MainWindow::ShowWarnings(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_WARNINGS, checked); mUI.mResults->ShowResults(ShowTypes::ShowWarnings, checked);
} }
void MainWindow::ShowPortability(bool checked) void MainWindow::ShowPortability(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_PORTABILITY, checked); mUI.mResults->ShowResults(ShowTypes::ShowPortability, checked);
} }
void MainWindow::ShowPerformance(bool checked) void MainWindow::ShowPerformance(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_PERFORMANCE, checked); mUI.mResults->ShowResults(ShowTypes::ShowPerformance, checked);
} }
void MainWindow::ShowInformation(bool checked) void MainWindow::ShowInformation(bool checked)
{ {
mUI.mResults->ShowResults(SHOW_INFORMATION, checked); mUI.mResults->ShowResults(ShowTypes::ShowInformation, checked);
} }
void MainWindow::CheckAll() void MainWindow::CheckAll()

View File

@ -45,6 +45,7 @@
#include "report.h" #include "report.h"
#include "xmlreport.h" #include "xmlreport.h"
#include "application.h" #include "application.h"
#include "showtypes.h"
ResultsTree::ResultsTree(QWidget * parent) : ResultsTree::ResultsTree(QWidget * parent) :
QTreeView(parent), QTreeView(parent),
@ -52,9 +53,6 @@ ResultsTree::ResultsTree(QWidget * parent) :
mVisibleErrors(false), mVisibleErrors(false),
mSelectionModel(0) mSelectionModel(0)
{ {
for (int i = 0; i < SHOW_NONE; i++)
mShowTypes[i] = false;
setModel(&mModel); setModel(&mModel);
QStringList labels; QStringList labels;
labels << tr("File") << tr("Severity") << tr("Line") << tr("Summary"); labels << tr("File") << tr("Severity") << tr("Line") << tr("Summary");
@ -110,7 +108,8 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
realfile = tr("Undefined file"); 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 specified, filter on summary, message, filename, and id
if (!hide && !mFilter.isEmpty()) if (!hide && !mFilter.isEmpty())
@ -151,7 +150,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
//Add user data to that item //Add user data to that item
QMap<QString, QVariant> data; QMap<QString, QVariant> data;
data["hide"] = false; data["hide"] = false;
data["severity"] = SeverityToShowType(item.severity); data["severity"] = ShowTypes::SeverityToShowType(item.severity);
data["summary"] = item.summary; data["summary"] = item.summary;
data["message"] = item.message; data["message"] = item.message;
data["file"] = item.files[0]; data["file"] = item.files[0];
@ -173,7 +172,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
//Add user data to that item //Add user data to that item
QMap<QString, QVariant> child_data; QMap<QString, QVariant> child_data;
child_data["severity"] = SeverityToShowType(line.severity); child_data["severity"] = ShowTypes::SeverityToShowType(line.severity);
child_data["summary"] = line.summary; child_data["summary"] = line.summary;
child_data["message"] = line.message; child_data["message"] = line.message;
child_data["file"] = item.files[i]; child_data["file"] = item.files[i];
@ -265,77 +264,6 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
return list[0]; 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) QString ResultsTree::SeverityToTranslatedString(Severity::SeverityType severity)
{ {
switch (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(); RefreshTree();
} }
} }
@ -496,7 +424,7 @@ void ResultsTree::RefreshTree()
QVariantMap data = userdata.toMap(); QVariantMap data = userdata.toMap();
//Check if this error should be hidden //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 specified, filter on summary, message, filename, and id
if (!hide && !mFilter.isEmpty()) if (!hide && !mFilter.isEmpty())
@ -961,7 +889,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
QVariantMap data = userdata.toMap(); QVariantMap data = userdata.toMap();
ErrorItem item; ErrorItem item;
item.severity = ShowTypeToSeverity(VariantToShowType(data["severity"])); item.severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data["severity"]));
item.summary = data["summary"].toString(); item.summary = data["summary"].toString();
item.message = data["message"].toString(); item.message = data["message"].toString();
item.id = data["id"].toString(); item.id = data["id"].toString();

View File

@ -29,6 +29,7 @@
#include "common.h" #include "common.h"
#include "applicationlist.h" #include "applicationlist.h"
#include "errorlogger.h" // Severity #include "errorlogger.h" // Severity
#include "showtypes.h"
class Report; class Report;
class ErrorItem; class ErrorItem;
@ -73,7 +74,7 @@ public:
* @param type Type of error to show/hide * @param type Type of error to show/hide
* @param show Should specified errors be shown (true) or hidden (false) * @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. * @brief Function to filter the displayed list of errors.
@ -136,11 +137,10 @@ public:
void Translate(); void Translate();
/** /**
* @brief Convert severity string to ShowTypes value * @brief GUI severities.
* @param severity Error severity */
* @return Severity converted to ShowTypes value ShowTypes mShowSeverities;
*/
static ShowTypes SeverityToShowType(Severity::SeverityType severity);
signals: signals:
/** /**
@ -289,21 +289,6 @@ protected:
*/ */
void RefreshTree(); 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. * @brief Convert Severity to translated string for GUI.
* @param type Severity to convert * @param type Severity to convert
@ -379,13 +364,6 @@ protected:
*/ */
QSettings *mSettings; 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. * @brief A string used to filter the results for display.
* *

View File

@ -91,10 +91,10 @@ void ResultsView::Error(const ErrorItem &item)
mErrorsFound = true; mErrorsFound = true;
mUI.mTree->AddErrorItem(item); mUI.mTree->AddErrorItem(item);
emit GotResults(); 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); mUI.mTree->ShowResults(type, show);
} }

View File

@ -25,6 +25,7 @@
#include "errorlogger.h" #include "errorlogger.h"
#include "common.h" #include "common.h"
#include "report.h" #include "report.h"
#include "showtypes.h"
#include "ui_resultsview.h" #include "ui_resultsview.h"
class ErrorItem; class ErrorItem;
@ -56,7 +57,7 @@ public:
* @param type Type of error to show/hide * @param type Type of error to show/hide
* @param show Should specified errors be shown (true) or hidden (false) * @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 * @brief Clear results
@ -143,15 +144,23 @@ public:
void ReadErrorsXml(const QString &filename); void ReadErrorsXml(const QString &filename);
/** /**
* @brief Return checking statistics. * @brief Return checking statistics.
* @param Pointer to checking statistics. * @return Pointer to checking statistics.
* */
*/
CheckStatistics *GetStatistics() const CheckStatistics *GetStatistics() const
{ {
return mStatistics; return mStatistics;
} }
/**
* @brief Return Showtypes.
* @return Pointer to Showtypes.
*/
ShowTypes * GetShowTypes() const
{
return &mUI.mTree->mShowSeverities;
}
signals: signals:
/** /**

140
gui/showtypes.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <QSettings>
#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;
}

126
gui/showtypes.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SHOWTYPES_H
#define SHOWTYPES_H
#include <QVariant>
#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

View File

@ -158,17 +158,17 @@ void StatsDialog::copyToClipboard()
) )
.arg(stats) .arg(stats)
.arg(errors) .arg(errors)
.arg(mStatistics->GetCount(SHOW_ERRORS)) .arg(mStatistics->GetCount(ShowTypes::ShowErrors))
.arg(warnings) .arg(warnings)
.arg(mStatistics->GetCount(SHOW_WARNINGS)) .arg(mStatistics->GetCount(ShowTypes::ShowWarnings))
.arg(style) .arg(style)
.arg(mStatistics->GetCount(SHOW_STYLE)) .arg(mStatistics->GetCount(ShowTypes::ShowStyle))
.arg(portability) .arg(portability)
.arg(mStatistics->GetCount(SHOW_PORTABILITY)) .arg(mStatistics->GetCount(ShowTypes::ShowPortability))
.arg(performance) .arg(performance)
.arg(mStatistics->GetCount(SHOW_PERFORMANCE)) .arg(mStatistics->GetCount(ShowTypes::ShowPerformance))
.arg(information) .arg(information)
.arg(mStatistics->GetCount(SHOW_INFORMATION)); .arg(mStatistics->GetCount(ShowTypes::ShowInformation));
const QString textSummary = settings + previous + statistics; const QString textSummary = settings + previous + statistics;
@ -220,17 +220,17 @@ void StatsDialog::copyToClipboard()
) )
.arg(stats) .arg(stats)
.arg(errors) .arg(errors)
.arg(mStatistics->GetCount(SHOW_ERRORS)) .arg(mStatistics->GetCount(ShowTypes::ShowErrors))
.arg(warnings) .arg(warnings)
.arg(mStatistics->GetCount(SHOW_WARNINGS)) .arg(mStatistics->GetCount(ShowTypes::ShowWarnings))
.arg(style) .arg(style)
.arg(mStatistics->GetCount(SHOW_STYLE)) .arg(mStatistics->GetCount(ShowTypes::ShowStyle))
.arg(portability) .arg(portability)
.arg(mStatistics->GetCount(SHOW_PORTABILITY)) .arg(mStatistics->GetCount(ShowTypes::ShowPortability))
.arg(performance) .arg(performance)
.arg(mStatistics->GetCount(SHOW_PERFORMANCE)) .arg(mStatistics->GetCount(ShowTypes::ShowPerformance))
.arg(information) .arg(information)
.arg(mStatistics->GetCount(SHOW_INFORMATION)); .arg(mStatistics->GetCount(ShowTypes::ShowInformation));
const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics; const QString htmlSummary = htmlSettings + htmlPrevious + htmlStatistics;
@ -244,10 +244,10 @@ void StatsDialog::copyToClipboard()
void StatsDialog::setStatistics(const CheckStatistics *stats) void StatsDialog::setStatistics(const CheckStatistics *stats)
{ {
mStatistics = const_cast<CheckStatistics*>(stats); mStatistics = const_cast<CheckStatistics*>(stats);
mUI.mLblErrors->setText(QString("%1").arg(stats->GetCount(SHOW_ERRORS))); mUI.mLblErrors->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowErrors)));
mUI.mLblWarnings->setText(QString("%1").arg(stats->GetCount(SHOW_WARNINGS))); mUI.mLblWarnings->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowWarnings)));
mUI.mLblStyle->setText(QString("%1").arg(stats->GetCount(SHOW_STYLE))); mUI.mLblStyle->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowStyle)));
mUI.mLblPortability->setText(QString("%1").arg(stats->GetCount(SHOW_PORTABILITY))); mUI.mLblPortability->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowPortability)));
mUI.mLblPerformance->setText(QString("%1").arg(stats->GetCount(SHOW_PERFORMANCE))); mUI.mLblPerformance->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowPerformance)));
mUI.mLblInformation->setText(QString("%1").arg(stats->GetCount(SHOW_INFORMATION))); mUI.mLblInformation->setText(QString("%1").arg(stats->GetCount(ShowTypes::ShowInformation)));
} }