Cppcheck
projectfiledialog.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 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 #ifndef PROJECTFILE_DIALOG_H
20 #define PROJECTFILE_DIALOG_H
21 
22 #include "suppressions.h"
23 
24 #include <QDialog>
25 #include <QList>
26 #include <QObject>
27 #include <QString>
28 #include <QStringList>
29 
30 class QModelIndex;
31 class QWidget;
32 namespace Ui {
33  class ProjectFile;
34 }
35 
36 /// @addtogroup GUI
37 /// @{
38 
39 
40 class ProjectFile;
41 
42 /**
43  * @brief A dialog for editing project file data.
44  */
45 class ProjectFileDialog : public QDialog {
46  Q_OBJECT
47 public:
48  explicit ProjectFileDialog(ProjectFile *projectFile, bool premium, QWidget *parent = nullptr);
49  ~ProjectFileDialog() override;
50 
51 private:
52  void loadFromProjectFile(const ProjectFile *projectFile);
53  void saveToProjectFile(ProjectFile *projectFile) const;
54 
55  /** Enable and disable widgets in the 'Paths and Defines' tab */
56  void updatePathsAndDefines();
57 
58  /**
59  * @brief Return project root path from the dialog control.
60  * @return Project root path.
61  */
62  QString getRootPath() const;
63 
64  QStringList getProjectConfigurations() const;
65  void setProjectConfigurations(const QStringList &configs);
66 
67  QString getImportProject() const;
68 
69  /** Get Cppcheck build dir */
70  QString getBuildDir() const;
71 
72  /**
73  * @brief Return include paths from the dialog control.
74  * @return List of include paths.
75  */
76  QStringList getIncludePaths() const;
77 
78  /**
79  * @brief Return define names from the dialog control.
80  * @return List of define names.
81  */
82  QStringList getDefines() const;
83 
84  /**
85  * @brief Return undefine names from the dialog control.
86  * @return List of undefine names.
87  */
88  QStringList getUndefines() const;
89 
90  /**
91  * @brief Return check paths from the dialog control.
92  * @return List of check paths.
93  */
94  QStringList getCheckPaths() const;
95 
96  /**
97  * @brief Return excluded paths from the dialog control.
98  * @return List of excluded paths.
99  */
100  QStringList getExcludedPaths() const;
101 
102  /**
103  * @brief Return selected libraries from the dialog control.
104  * @return List of libraries.
105  */
106  QStringList getLibraries() const;
107 
108  /**
109  * @brief Return suppressions from the dialog control.
110  * @return List of suppressions.
111  */
112  const QList<SuppressionList::Suppression>& getSuppressions() const {
113  return mSuppressions;
114  }
115 
116  /**
117  * @brief Set project root path to dialog control.
118  * @param root Project root path to set to dialog control.
119  */
120  void setRootPath(const QString &root);
121 
122  /** Set build dir */
123  void setBuildDir(const QString &buildDir);
124 
125  void setImportProject(const QString &importProject);
126 
127  /**
128  * @brief Set include paths to dialog control.
129  * @param includes List of include paths to set to dialog control.
130  */
131  void setIncludepaths(const QStringList &includes);
132 
133  /**
134  * @brief Set define names to dialog control.
135  * @param defines List of define names to set to dialog control.
136  */
137  void setDefines(const QStringList &defines);
138 
139  /**
140  * @brief Set undefine names to dialog control.
141  * @param undefines List of undefine names to set to dialog control.
142  */
143  void setUndefines(const QStringList &undefines);
144 
145  /**
146  * @brief Set check paths to dialog control.
147  * @param paths List of path names to set to dialog control.
148  */
149  void setCheckPaths(const QStringList &paths);
150 
151  /**
152  * @brief Set excluded paths to dialog control.
153  * @param paths List of path names to set to dialog control.
154  */
155  void setExcludedPaths(const QStringList &paths);
156 
157  /**
158  * @brief Set libraries to dialog control.
159  * @param libraries List of libraries to set to dialog control.
160  */
161  void setLibraries(const QStringList &libraries);
162 
163  /**
164  * @brief Add a single suppression to dialog control.
165  * @param suppression A suppressions to add to dialog control.
166  */
167  void addSingleSuppression(const SuppressionList::Suppression &suppression);
168 
169  /**
170  * @brief Set suppressions to dialog control.
171  * @param suppressions List of suppressions to set to dialog control.
172  */
173  void setSuppressions(const QList<SuppressionList::Suppression> &suppressions);
174 
175 protected slots:
176 
177  /** ok button pressed, save changes and accept */
178  void ok();
179 
180  /**
181  * @brief Browse for build dir.
182  */
183  void browseBuildDir();
184 
185  /**
186  * @brief Clear 'import project'.
187  */
188  void clearImportProject();
189 
190  /**
191  * @brief Browse for solution / project / compile database.
192  */
193  void browseImportProject();
194 
195  /**
196  * @brief Add new path to check.
197  */
198  void addCheckPath();
199 
200  /**
201  * @brief Edit path in the list.
202  */
203  void editCheckPath();
204 
205  /**
206  * @brief Remove path from the list.
207  */
208  void removeCheckPath();
209 
210  /**
211  * @brief Browse for include directory.
212  * Allow user to add new include directory to the list.
213  */
214  void addIncludeDir();
215 
216  /**
217  * @brief Remove include directory from the list.
218  */
219  void removeIncludeDir();
220 
221  /**
222  * @brief Edit include directory in the list.
223  */
224  void editIncludeDir();
225 
226  /**
227  * @brief Add new path to exclude list.
228  */
229  void addExcludePath();
230 
231  /**
232  * @brief Add new file to exclude list.
233  */
234  void addExcludeFile();
235 
236  /**
237  * @brief Edit excluded path in the list.
238  */
239  void editExcludePath();
240 
241  /**
242  * @brief Remove excluded path from the list.
243  */
244  void removeExcludePath();
245 
246  /**
247  * @brief Move include path up in the list.
248  */
249  void moveIncludePathUp();
250 
251  /**
252  * @brief Move include path down in the list.
253  */
254  void moveIncludePathDown();
255 
256  /**
257  * @brief Add suppression to the list
258  */
259  void addSuppression();
260 
261  /**
262  * @brief Remove selected suppression from the list
263  */
264  void removeSuppression();
265 
266  /**
267  * @brief Edit suppression (double clicking on suppression)
268  */
269  void editSuppression(const QModelIndex &index);
270 
271  /**
272  * @brief Browse for misra file
273  */
274  void browseMisraFile();
275 
276  /**
277  * @brief Check for all VS configurations
278  */
279  void checkAllVSConfigs();
280 
281 protected:
282 
283  /**
284  * @brief Save dialog settings.
285  */
286  void loadSettings();
287 
288  /**
289  * @brief Load dialog settings.
290  */
291  void saveSettings() const;
292 
293  /**
294  * @brief Add new indlude directory.
295  * @param dir Directory to add.
296  */
297  void addIncludeDir(const QString &dir);
298 
299  /**
300  * @brief Add new path to check.
301  * @param path Path to add.
302  */
303  void addCheckPath(const QString &path);
304 
305  /**
306  * @brief Add new path to ignore list.
307  * @param path Path to add.
308  */
309  void addExcludePath(const QString &path);
310 
311  /**
312  * @brief Get mSuppressions index that match the
313  * given short text
314  * @param shortText text as generated by Suppression::getText
315  * @return index of matching suppression, -1 if not found
316  */
317  int getSuppressionIndex(const QString &shortText) const;
318 
319 private:
320  static QStringList getProjectConfigs(const QString &fileName);
321 
322  Ui::ProjectFile *mUI;
323 
324  /**
325  * @brief Projectfile path.
326  */
328 
329  /** Is this Cppcheck Premium? */
330  bool mPremium;
331 
332  QString getExistingDirectory(const QString &caption, bool trailingSlash);
333 
334  QList<SuppressionList::Suppression> mSuppressions;
335 };
336 
337 /// @}
338 #endif // PROJECTFILE_DIALOG_H
A dialog for editing project file data.
int getSuppressionIndex(const QString &shortText) const
Get mSuppressions index that match the given short text.
void updatePathsAndDefines()
Enable and disable widgets in the 'Paths and Defines' tab.
ProjectFileDialog(ProjectFile *projectFile, bool premium, QWidget *parent=nullptr)
bool mPremium
Is this Cppcheck Premium?
void ok()
ok button pressed, save changes and accept
void browseBuildDir()
Browse for build dir.
void setExcludedPaths(const QStringList &paths)
Set excluded paths to dialog control.
QStringList getLibraries() const
Return selected libraries from the dialog control.
QString getExistingDirectory(const QString &caption, bool trailingSlash)
QString getBuildDir() const
Get Cppcheck build dir.
void setCheckPaths(const QStringList &paths)
Set check paths to dialog control.
void moveIncludePathUp()
Move include path up in the list.
void addExcludePath()
Add new path to exclude list.
void editSuppression(const QModelIndex &index)
Edit suppression (double clicking on suppression)
void saveSettings() const
Load dialog settings.
void removeExcludePath()
Remove excluded path from the list.
QString getImportProject() const
void setBuildDir(const QString &buildDir)
Set build dir.
QStringList getExcludedPaths() const
Return excluded paths from the dialog control.
void addExcludeFile()
Add new file to exclude list.
static QStringList getProjectConfigs(const QString &fileName)
void clearImportProject()
Clear 'import project'.
void moveIncludePathDown()
Move include path down in the list.
void loadFromProjectFile(const ProjectFile *projectFile)
void addCheckPath()
Add new path to check.
void addSuppression()
Add suppression to the list.
void setImportProject(const QString &importProject)
void editExcludePath()
Edit excluded path in the list.
void loadSettings()
Save dialog settings.
void setProjectConfigurations(const QStringList &configs)
void browseImportProject()
Browse for solution / project / compile database.
QStringList getCheckPaths() const
Return check paths from the dialog control.
void removeIncludeDir()
Remove include directory from the list.
void setIncludepaths(const QStringList &includes)
Set include paths to dialog control.
const QList< SuppressionList::Suppression > & getSuppressions() const
Return suppressions from the dialog control.
void setRootPath(const QString &root)
Set project root path to dialog control.
QStringList getProjectConfigurations() const
void addIncludeDir()
Browse for include directory.
void addSingleSuppression(const SuppressionList::Suppression &suppression)
Add a single suppression to dialog control.
QStringList getDefines() const
Return define names from the dialog control.
void browseMisraFile()
Browse for misra file.
void checkAllVSConfigs()
Check for all VS configurations.
void saveToProjectFile(ProjectFile *projectFile) const
QString getRootPath() const
Return project root path from the dialog control.
QStringList getIncludePaths() const
Return include paths from the dialog control.
void removeSuppression()
Remove selected suppression from the list.
void editIncludeDir()
Edit include directory in the list.
void setUndefines(const QStringList &undefines)
Set undefine names to dialog control.
void removeCheckPath()
Remove path from the list.
void setLibraries(const QStringList &libraries)
Set libraries to dialog control.
void setSuppressions(const QList< SuppressionList::Suppression > &suppressions)
Set suppressions to dialog control.
QStringList getUndefines() const
Return undefine names from the dialog control.
QList< SuppressionList::Suppression > mSuppressions
void setDefines(const QStringList &defines)
Set define names to dialog control.
void editCheckPath()
Edit path in the list.
ProjectFile * mProjectFile
Projectfile path.
Ui::ProjectFile * mUI
A class that reads and writes project files.
Definition: projectfile.h:46
Definition: aboutdialog.h:27