Cppcheck
settingsdialog.h
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 
20 #ifndef SETTINGSDIALOG_H
21 #define SETTINGSDIALOG_H
22 
23 #include <QDialog>
24 #include <QObject>
25 #include <QString>
26 #include <Qt>
27 
28 class QSettings;
29 class QWidget;
30 class ApplicationList;
31 class TranslationHandler;
32 class CodeEditorStyle;
33 class QCheckBox;
34 namespace Ui {
35  class Settings;
36 }
37 
38 /// @addtogroup GUI
39 /// @{
40 
41 /**
42  * @brief Settings dialog
43  *
44  */
45 class SettingsDialog : public QDialog {
46  Q_OBJECT
47 public:
49  TranslationHandler *translator,
50  bool premium,
51  QWidget *parent = nullptr);
52  SettingsDialog(const SettingsDialog &) = delete;
53  ~SettingsDialog() override;
55 
56  /**
57  * @brief Save all values to QSettings
58  *
59  */
60  void saveSettingValues() const;
61 
62  /**
63  * @brief Get checkbox value for mShowFullPath
64  *
65  * @return should full path of errors be shown in the tree
66  */
67  bool showFullPath() const;
68 
69  /**
70  * @brief Get checkbox value for mSaveFullPath
71  *
72  * @return should full path of files be saved when creating a report
73  */
74  bool saveFullPath() const;
75 
76 
77  /**
78  * @brief Get checkbox value for mNoErrorsMessage
79  *
80  * @return Should "no errors message" be hidden
81  */
82  bool showNoErrorsMessage() const;
83 
84  /**
85  * @brief Get checkbox value for mShowIdColumn
86  *
87  * @return Should error id column be displayed
88  */
89  bool showErrorId() const;
90 
91 
92  /**
93  * @brief Get checkbox value for mEnableInconclusive
94  *
95  * @return Should inconclusive column be displayed
96  */
97  bool showInconclusive() const;
98 
99  /**
100  * @brief Get checkbox value for mSaveAllErrors
101  *
102  * @return should all errors be saved to report
103  */
104  bool saveAllErrors() const;
105 
106 protected slots:
107  /**
108  * @brief Slot for clicking OK.
109  *
110  */
111  void ok();
112 
113  /** @brief Slot for validating input value in @c editPythonPath */
114  void validateEditPythonPath();
115 
116  /**
117  * @brief Slot for adding a new application to the list
118  *
119  */
120  void addApplication();
121 
122  /**
123  * @brief Slot for deleting an application from the list
124  *
125  */
126  void removeApplication();
127 
128  /**
129  * @brief Slot for modifying an application in the list
130  *
131  */
132  void editApplication();
133 
134  /**
135  * @brief Slot for making the selected application as the default (first)
136  *
137  */
138  void defaultApplication();
139 
140  /** @brief Slot for browsing for the python binary */
141  void browsePythonPath();
142 
143  /** @brief Slot for browsing for the clang binary */
144  void browseClangPath();
145 
146  /**
147  * @brief Browse for MISRA file
148  */
149  void browseMisraFile();
150 
151  /**
152  * @brief Set Code Editor Style to Default
153  */
155 
156  /**
157  * @brief Edit Custom Code Editor Style
158  */
159  void editCodeEditorStyle();
160 
161 protected:
162  /**
163  * @brief Clear all applications from the list and re insert them from mTempApplications
164  *
165  */
167 
168  /**
169  * @brief Load saved values
170  * Loads dialog size and column widths.
171  *
172  */
173  void loadSettings();
174 
175  /**
176  * @brief Save settings
177  * Save dialog size and column widths.
178  */
179  void saveSettings() const;
180 
181  /**
182  * @brief Save a single checkboxes value
183  *
184  * @param settings Pointer to Settings.
185  * @param box checkbox to save
186  * @param name name for QSettings to store the value
187  */
188  static void saveCheckboxValue(QSettings *settings, const QCheckBox *box, const QString &name);
189 
190  /**
191  * @brief Convert bool to Qt::CheckState
192  *
193  * @param yes value to convert
194  * @return value converted to Qt::CheckState
195  */
196  static Qt::CheckState boolToCheckState(bool yes);
197 
198  /**
199  * @brief Converts Qt::CheckState to bool
200  *
201  * @param state Qt::CheckState to convert
202  * @return converted value
203  */
204  static bool checkStateToBool(Qt::CheckState state);
205 
206  /**
207  * @brief Populate the translations list.
208  */
209  void initTranslationsList();
210 
211  /**
212  * @brief Current Code Editor Style
213  */
215 
216  /**
217  * @brief List of applications user has specified
218  *
219  */
221 
222  /**
223  * @brief Temporary list of applications
224  * This will be copied to actual list of applications (mApplications)
225  * when user clicks ok.
226  */
228 
229  /**
230  * @brief List of translations.
231  *
232  */
234 
235  /**
236  * @brief Dialog from UI designer
237  *
238  */
239  Ui::Settings *mUI;
240 private:
241  void manageStyleControls();
242 
243  static constexpr int mLangCodeRole = Qt::UserRole;
244 
245  bool mPremium;
246 };
247 /// @}
248 #endif // SETTINGSDIALOG_H
List of applications user has specified to open errors with.
Settings dialog.
bool showNoErrorsMessage() const
Get checkbox value for mNoErrorsMessage.
void browsePythonPath()
Slot for browsing for the python binary.
SettingsDialog & operator=(const SettingsDialog &)=delete
void ok()
Slot for clicking OK.
bool saveAllErrors() const
Get checkbox value for mSaveAllErrors.
void browseClangPath()
Slot for browsing for the clang binary.
void saveSettingValues() const
Save all values to QSettings.
static void saveCheckboxValue(QSettings *settings, const QCheckBox *box, const QString &name)
Save a single checkboxes value.
void populateApplicationList()
Clear all applications from the list and re insert them from mTempApplications.
SettingsDialog(const SettingsDialog &)=delete
bool saveFullPath() const
Get checkbox value for mSaveFullPath.
CodeEditorStyle * mCurrentStyle
Current Code Editor Style.
void editApplication()
Slot for modifying an application in the list.
void addApplication()
Slot for adding a new application to the list.
void removeApplication()
Slot for deleting an application from the list.
void browseMisraFile()
Browse for MISRA file.
void editCodeEditorStyle()
Edit Custom Code Editor Style.
ApplicationList * mTempApplications
Temporary list of applications This will be copied to actual list of applications (mApplications) whe...
TranslationHandler * mTranslator
List of translations.
void validateEditPythonPath()
Slot for validating input value in editPythonPath.
~SettingsDialog() override
void loadSettings()
Load saved values Loads dialog size and column widths.
void initTranslationsList()
Populate the translations list.
static constexpr int mLangCodeRole
void manageStyleControls()
static bool checkStateToBool(Qt::CheckState state)
Converts Qt::CheckState to bool.
void saveSettings() const
Save settings Save dialog size and column widths.
SettingsDialog(ApplicationList *list, TranslationHandler *translator, bool premium, QWidget *parent=nullptr)
bool showInconclusive() const
Get checkbox value for mEnableInconclusive.
Ui::Settings * mUI
Dialog from UI designer.
static Qt::CheckState boolToCheckState(bool yes)
Convert bool to Qt::CheckState.
ApplicationList * mApplications
List of applications user has specified.
void defaultApplication()
Slot for making the selected application as the default (first)
void setCodeEditorStyleDefault()
Set Code Editor Style to Default.
bool showFullPath() const
Get checkbox value for mShowFullPath.
bool showErrorId() const
Get checkbox value for mShowIdColumn.
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
A class handling the available translations.
Definition: aboutdialog.h:27