Cppcheck
showtypes.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "showtypes.h"
20 
21 #include "common.h"
22 #include "errortypes.h"
23 
24 #include <QSettings>
25 
27 {
28  load();
29 }
30 
32 {
33  save();
34 }
35 
37 {
38  switch (severity) {
39  case Severity::none:
40  case Severity::internal:
41  return ShowTypes::ShowNone;
42  case Severity::error:
43  return ShowTypes::ShowErrors;
44  case Severity::style:
45  return ShowTypes::ShowStyle;
46  case Severity::warning:
54  default:
55  return ShowTypes::ShowNone;
56  }
57 }
58 
60 {
61  switch (type) {
63  return Severity::style;
64 
66  return Severity::error;
67 
69  return Severity::warning;
70 
72  return Severity::performance;
73 
75  return Severity::portability;
76 
78  return Severity::information;
79 
81  default:
82  return Severity::none;
83  }
84 }
85 
87 {
88  const int value = data.toInt();
89  if (value < ShowTypes::ShowStyle || value > ShowTypes::ShowErrors) {
90  return ShowTypes::ShowNone;
91  }
92  return (ShowTypes::ShowType)value;
93 }
94 
96 {
97  QSettings settings;
98  mVisible[ShowStyle] = settings.value(SETTINGS_SHOW_STYLE, true).toBool();
99  mVisible[ShowErrors] = settings.value(SETTINGS_SHOW_ERRORS, true).toBool();
100  mVisible[ShowWarnings] = settings.value(SETTINGS_SHOW_WARNINGS, true).toBool();
101  mVisible[ShowPortability] = settings.value(SETTINGS_SHOW_PORTABILITY, true).toBool();
102  mVisible[ShowPerformance] = settings.value(SETTINGS_SHOW_PERFORMANCE, true).toBool();
103  mVisible[ShowInformation] = settings.value(SETTINGS_SHOW_INFORMATION, true).toBool();
104 }
105 
106 void ShowTypes::save() const
107 {
108  QSettings settings;
109  settings.setValue(SETTINGS_SHOW_STYLE, mVisible[ShowStyle]);
110  settings.setValue(SETTINGS_SHOW_ERRORS, mVisible[ShowErrors]);
111  settings.setValue(SETTINGS_SHOW_WARNINGS, mVisible[ShowWarnings]);
115 }
116 
118 {
119  return mVisible[category];
120 }
121 
122 bool ShowTypes::isShown(Severity severity) const
123 {
124  return isShown(ShowTypes::SeverityToShowType(severity));
125 }
126 
127 void ShowTypes::show(ShowTypes::ShowType category, bool showing)
128 {
129  mVisible[category] = showing;
130 }
bool mVisible[ShowNone]
Definition: showtypes.h:119
static ShowTypes::ShowType SeverityToShowType(Severity severity)
Convert severity string to ShowTypes value.
Definition: showtypes.cpp:36
ShowTypes()
Constructor.
Definition: showtypes.cpp:26
static ShowTypes::ShowType VariantToShowType(const QVariant &data)
Convert QVariant (that contains an int) to Showtypes value.
Definition: showtypes.cpp:86
ShowType
Show types we have (i.e.
Definition: showtypes.h:44
@ ShowPerformance
Definition: showtypes.h:47
@ ShowInformation
Definition: showtypes.h:49
@ ShowPortability
Definition: showtypes.h:48
@ ShowErrors
Definition: showtypes.h:50
@ ShowWarnings
Definition: showtypes.h:46
@ ShowStyle
Definition: showtypes.h:45
@ ShowNone
Definition: showtypes.h:51
static Severity ShowTypeToSeverity(ShowTypes::ShowType type)
Convert ShowType to severity string.
Definition: showtypes.cpp:59
void show(ShowTypes::ShowType category, bool showing)
Show/hide the showtype.
Definition: showtypes.cpp:127
void load()
Load visibility settings from the platform's settings storage.
Definition: showtypes.cpp:95
bool isShown(ShowTypes::ShowType category) const
Is the showtype visible in the GUI?
Definition: showtypes.cpp:117
~ShowTypes()
Destructor.
Definition: showtypes.cpp:31
void save() const
Save visibility settings to the platform's settings storage.
Definition: showtypes.cpp:106
Severity
enum class for severity.
Definition: errortypes.h:63
@ none
No severity (default value).
@ warning
Warning.
@ portability
Portability warning.
@ style
Style warning.
@ information
Checking information.
@ performance
Performance warning.
@ error
Programming error.
@ internal
Internal message.
#define SETTINGS_SHOW_INFORMATION
Definition: common.h:56
#define SETTINGS_SHOW_ERRORS
Definition: common.h:53
#define SETTINGS_SHOW_PERFORMANCE
Definition: common.h:55
#define SETTINGS_SHOW_STYLE
Definition: common.h:52
#define SETTINGS_SHOW_WARNINGS
Definition: common.h:54
#define SETTINGS_SHOW_PORTABILITY
Definition: common.h:57