Skip to content

Commit 00ae7db

Browse files
committed
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.
1 parent 849bee8 commit 00ae7db

12 files changed

Lines changed: 355 additions & 191 deletions

gui/checkstatistics.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,29 @@ CheckStatistics::CheckStatistics(QObject *parent)
2626
Clear();
2727
}
2828

29-
void CheckStatistics::AddItem(ShowTypes type)
29+
void CheckStatistics::AddItem(ShowTypes::ShowType type)
3030
{
3131
switch (type)
3232
{
33-
case SHOW_STYLE:
33+
case ShowTypes::ShowStyle:
3434
mStyle++;
3535
break;
36-
case SHOW_WARNINGS:
36+
case ShowTypes::ShowWarnings:
3737
mWarning++;
3838
break;
39-
case SHOW_PERFORMANCE:
39+
case ShowTypes::ShowPerformance:
4040
mPerformance++;
4141
break;
42-
case SHOW_PORTABILITY:
42+
case ShowTypes::ShowPortability:
4343
mPortability++;
4444
break;
45-
case SHOW_ERRORS:
45+
case ShowTypes::ShowErrors:
4646
mError++;
4747
break;
48-
case SHOW_INFORMATION:
48+
case ShowTypes::ShowInformation:
4949
mInformation++;
5050
break;
51-
case SHOW_NONE:
51+
case ShowTypes::ShowNone:
5252
default:
5353
qDebug() << "Unknown error type - not added to statistics.";
5454
break;
@@ -65,30 +65,30 @@ void CheckStatistics::Clear()
6565
mError = 0;
6666
}
6767

68-
unsigned CheckStatistics::GetCount(ShowTypes type) const
68+
unsigned CheckStatistics::GetCount(ShowTypes::ShowType type) const
6969
{
7070
unsigned count = 0;
7171
switch (type)
7272
{
73-
case SHOW_STYLE:
73+
case ShowTypes::ShowStyle:
7474
count = mStyle;
7575
break;
76-
case SHOW_WARNINGS:
76+
case ShowTypes::ShowWarnings:
7777
count = mWarning;
7878
break;
79-
case SHOW_PERFORMANCE:
79+
case ShowTypes::ShowPerformance:
8080
count = mPerformance;
8181
break;
82-
case SHOW_PORTABILITY:
82+
case ShowTypes::ShowPortability:
8383
count = mPortability;
8484
break;
85-
case SHOW_ERRORS:
85+
case ShowTypes::ShowErrors:
8686
count = mError;
8787
break;
88-
case SHOW_INFORMATION:
88+
case ShowTypes::ShowInformation:
8989
count = mInformation;
9090
break;
91-
case SHOW_NONE:
91+
case ShowTypes::ShowNone:
9292
default:
9393
qDebug() << "Unknown error type - returning zero statistics.";
9494
break;

gui/checkstatistics.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <QObject>
2323
#include "common.h"
24+
#include "showtypes.h"
2425

2526
/// @addtogroup GUI
2627
/// @{
@@ -38,7 +39,7 @@ class CheckStatistics : public QObject
3839
*
3940
* @param type Type of the item to add.
4041
*/
41-
void AddItem(ShowTypes type);
42+
void AddItem(ShowTypes::ShowType type);
4243

4344
/**
4445
* @brief Clear the statistics.
@@ -52,7 +53,7 @@ class CheckStatistics : public QObject
5253
* @param type Type for which the statistics are returned.
5354
* @return Number of items of given type.
5455
*/
55-
unsigned GetCount(ShowTypes type) const;
56+
unsigned GetCount(ShowTypes::ShowType type) const;
5657

5758
private:
5859
unsigned mStyle;

gui/common.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@
2323
/// @{
2424

2525

26-
/**
27-
* @brief List of error types to show
28-
*
29-
*/
30-
typedef enum
31-
{
32-
SHOW_STYLE = 0,
33-
SHOW_WARNINGS,
34-
SHOW_PERFORMANCE,
35-
SHOW_PORTABILITY,
36-
SHOW_INFORMATION,
37-
SHOW_ERRORS, // Keep this as last real item
38-
SHOW_NONE
39-
}
40-
ShowTypes;
41-
4226
/**
4327
* QSetting value names
4428
*/

gui/gui.pro

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ HEADERS += aboutdialog.h \
7878
txtreport.h \
7979
xmlreport.h \
8080
xmlreportv1.h \
81-
xmlreportv2.h
81+
xmlreportv2.h \
82+
showtypes.h
8283

8384
SOURCES += aboutdialog.cpp \
8485
application.cpp \
@@ -108,11 +109,14 @@ SOURCES += aboutdialog.cpp \
108109
txtreport.cpp \
109110
xmlreport.cpp \
110111
xmlreportv1.cpp \
111-
xmlreportv2.cpp
112+
xmlreportv2.cpp \
113+
showtypes.cpp
112114

113115
win32 {
114116
DEFINES += _CRT_SECURE_NO_WARNINGS
115117
RC_FILE = cppcheck-gui.rc
116118
HEADERS += ../cli/resource.h
117119
LIBS += -lshlwapi
118120
}
121+
122+

gui/mainwindow.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "statsdialog.h"
3939
#include "logview.h"
4040
#include "filelist.h"
41+
#include "showtypes.h"
4142

4243
static const QString OnlineHelpURL("http://cppcheck.sourceforge.net/manual.html");
4344

@@ -210,20 +211,13 @@ void MainWindow::LoadSettings()
210211
mSettings->value(SETTINGS_WINDOW_HEIGHT, 600).toInt());
211212
}
212213

213-
// Show * states
214-
mUI.mActionShowStyle->setChecked(mSettings->value(SETTINGS_SHOW_STYLE, true).toBool());
215-
mUI.mActionShowErrors->setChecked(mSettings->value(SETTINGS_SHOW_ERRORS, true).toBool());
216-
mUI.mActionShowWarnings->setChecked(mSettings->value(SETTINGS_SHOW_WARNINGS, true).toBool());
217-
mUI.mActionShowPortability->setChecked(mSettings->value(SETTINGS_SHOW_PORTABILITY, true).toBool());
218-
mUI.mActionShowPerformance->setChecked(mSettings->value(SETTINGS_SHOW_PERFORMANCE, true).toBool());
219-
mUI.mActionShowInformation->setChecked(mSettings->value(SETTINGS_SHOW_INFORMATION, true).toBool());
220-
221-
mUI.mResults->ShowResults(SHOW_ERRORS, mUI.mActionShowErrors->isChecked());
222-
mUI.mResults->ShowResults(SHOW_WARNINGS, mUI.mActionShowWarnings->isChecked());
223-
mUI.mResults->ShowResults(SHOW_STYLE, mUI.mActionShowStyle->isChecked());
224-
mUI.mResults->ShowResults(SHOW_PORTABILITY, mUI.mActionShowPortability->isChecked());
225-
mUI.mResults->ShowResults(SHOW_PERFORMANCE, mUI.mActionShowPerformance->isChecked());
226-
mUI.mResults->ShowResults(SHOW_INFORMATION, mUI.mActionShowInformation->isChecked());
214+
ShowTypes *types = mUI.mResults->GetShowTypes();
215+
mUI.mActionShowStyle->setChecked(types->isShown(ShowTypes::ShowStyle));
216+
mUI.mActionShowErrors->setChecked(types->isShown(ShowTypes::ShowErrors));
217+
mUI.mActionShowWarnings->setChecked(types->isShown(ShowTypes::ShowWarnings));
218+
mUI.mActionShowPortability->setChecked(types->isShown(ShowTypes::ShowPortability));
219+
mUI.mActionShowPerformance->setChecked(types->isShown(ShowTypes::ShowPerformance));
220+
mUI.mActionShowInformation->setChecked(types->isShown(ShowTypes::ShowInformation));
227221

228222
// Main window settings
229223
const bool showMainToolbar = mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool();
@@ -628,32 +622,32 @@ void MainWindow::EnableCheckButtons(bool enable)
628622

629623
void MainWindow::ShowStyle(bool checked)
630624
{
631-
mUI.mResults->ShowResults(SHOW_STYLE, checked);
625+
mUI.mResults->ShowResults(ShowTypes::ShowStyle, checked);
632626
}
633627

634628
void MainWindow::ShowErrors(bool checked)
635629
{
636-
mUI.mResults->ShowResults(SHOW_ERRORS, checked);
630+
mUI.mResults->ShowResults(ShowTypes::ShowErrors, checked);
637631
}
638632

639633
void MainWindow::ShowWarnings(bool checked)
640634
{
641-
mUI.mResults->ShowResults(SHOW_WARNINGS, checked);
635+
mUI.mResults->ShowResults(ShowTypes::ShowWarnings, checked);
642636
}
643637

644638
void MainWindow::ShowPortability(bool checked)
645639
{
646-
mUI.mResults->ShowResults(SHOW_PORTABILITY, checked);
640+
mUI.mResults->ShowResults(ShowTypes::ShowPortability, checked);
647641
}
648642

649643
void MainWindow::ShowPerformance(bool checked)
650644
{
651-
mUI.mResults->ShowResults(SHOW_PERFORMANCE, checked);
645+
mUI.mResults->ShowResults(ShowTypes::ShowPerformance, checked);
652646
}
653647

654648
void MainWindow::ShowInformation(bool checked)
655649
{
656-
mUI.mResults->ShowResults(SHOW_INFORMATION, checked);
650+
mUI.mResults->ShowResults(ShowTypes::ShowInformation, checked);
657651
}
658652

659653
void MainWindow::CheckAll()

gui/resultstree.cpp

Lines changed: 10 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,14 @@
4545
#include "report.h"
4646
#include "xmlreport.h"
4747
#include "application.h"
48+
#include "showtypes.h"
4849

4950
ResultsTree::ResultsTree(QWidget * parent) :
5051
QTreeView(parent),
5152
mContextItem(0),
5253
mVisibleErrors(false),
5354
mSelectionModel(0)
5455
{
55-
for (int i = 0; i < SHOW_NONE; i++)
56-
mShowTypes[i] = false;
57-
5856
setModel(&mModel);
5957
QStringList labels;
6058
labels << tr("File") << tr("Severity") << tr("Line") << tr("Summary");
@@ -110,7 +108,8 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
110108
realfile = tr("Undefined file");
111109
}
112110

113-
bool hide = !mShowTypes[SeverityToShowType(item.severity)];
111+
bool hide = !mShowSeverities.isShown(item.severity);
112+
//bool hide = !mShowTypes[SeverityToShowType(item.severity)];
114113

115114
//If specified, filter on summary, message, filename, and id
116115
if (!hide && !mFilter.isEmpty())
@@ -151,7 +150,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
151150
//Add user data to that item
152151
QMap<QString, QVariant> data;
153152
data["hide"] = false;
154-
data["severity"] = SeverityToShowType(item.severity);
153+
data["severity"] = ShowTypes::SeverityToShowType(item.severity);
155154
data["summary"] = item.summary;
156155
data["message"] = item.message;
157156
data["file"] = item.files[0];
@@ -173,7 +172,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item)
173172

174173
//Add user data to that item
175174
QMap<QString, QVariant> child_data;
176-
child_data["severity"] = SeverityToShowType(line.severity);
175+
child_data["severity"] = ShowTypes::SeverityToShowType(line.severity);
177176
child_data["summary"] = line.summary;
178177
child_data["message"] = line.message;
179178
child_data["file"] = item.files[i];
@@ -265,77 +264,6 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent,
265264
return list[0];
266265
}
267266

268-
ShowTypes ResultsTree::VariantToShowType(const QVariant &data)
269-
{
270-
int value = data.toInt();
271-
if (value < SHOW_STYLE || value > SHOW_ERRORS)
272-
{
273-
return SHOW_NONE;
274-
}
275-
return (ShowTypes)value;
276-
}
277-
278-
ShowTypes ResultsTree::SeverityToShowType(Severity::SeverityType severity)
279-
{
280-
switch (severity)
281-
{
282-
case Severity::none:
283-
return SHOW_NONE;
284-
case Severity::error:
285-
return SHOW_ERRORS;
286-
case Severity::style:
287-
return SHOW_STYLE;
288-
case Severity::warning:
289-
return SHOW_WARNINGS;
290-
case Severity::performance:
291-
return SHOW_PERFORMANCE;
292-
case Severity::portability:
293-
return SHOW_PORTABILITY;
294-
case Severity::information:
295-
return SHOW_INFORMATION;
296-
default:
297-
return SHOW_NONE;
298-
}
299-
300-
return SHOW_NONE;
301-
}
302-
303-
Severity::SeverityType ResultsTree::ShowTypeToSeverity(ShowTypes type)
304-
{
305-
switch (type)
306-
{
307-
case SHOW_STYLE:
308-
return Severity::style;
309-
break;
310-
311-
case SHOW_ERRORS:
312-
return Severity::error;
313-
break;
314-
315-
case SHOW_WARNINGS:
316-
return Severity::warning;
317-
break;
318-
319-
case SHOW_PERFORMANCE:
320-
return Severity::performance;
321-
break;
322-
323-
case SHOW_PORTABILITY:
324-
return Severity::portability;
325-
break;
326-
327-
case SHOW_INFORMATION:
328-
return Severity::information;
329-
break;
330-
331-
case SHOW_NONE:
332-
return Severity::none;
333-
break;
334-
}
335-
336-
return Severity::none;
337-
}
338-
339267
QString ResultsTree::SeverityToTranslatedString(Severity::SeverityType severity)
340268
{
341269
switch (severity)
@@ -414,11 +342,11 @@ void ResultsTree::SaveSettings()
414342
}
415343
}
416344

417-
void ResultsTree::ShowResults(ShowTypes type, bool show)
345+
void ResultsTree::ShowResults(ShowTypes::ShowType type, bool show)
418346
{
419-
if (type != SHOW_NONE && mShowTypes[type] != show)
347+
if (type != ShowTypes::ShowNone && mShowSeverities.isShown(type) != show)
420348
{
421-
mShowTypes[type] = show;
349+
mShowSeverities.show(type, show);
422350
RefreshTree();
423351
}
424352
}
@@ -496,7 +424,7 @@ void ResultsTree::RefreshTree()
496424
QVariantMap data = userdata.toMap();
497425

498426
//Check if this error should be hidden
499-
bool hide = (data["hide"].toBool() || !mShowTypes[VariantToShowType(data["severity"])]);
427+
bool hide = (data["hide"].toBool() || !mShowSeverities.isShown(ShowTypes::VariantToShowType(data["severity"])));
500428

501429
//If specified, filter on summary, message, filename, and id
502430
if (!hide && !mFilter.isEmpty())
@@ -961,7 +889,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item)
961889
QVariantMap data = userdata.toMap();
962890

963891
ErrorItem item;
964-
item.severity = ShowTypeToSeverity(VariantToShowType(data["severity"]));
892+
item.severity = ShowTypes::ShowTypeToSeverity(ShowTypes::VariantToShowType(data["severity"]));
965893
item.summary = data["summary"].toString();
966894
item.message = data["message"].toString();
967895
item.id = data["id"].toString();

0 commit comments

Comments
 (0)