cppcheck/gui/mainwindow.h

478 lines
14 KiB
C
Raw Normal View History

/*
* Cppcheck - A tool for static C/C++ code analysis
2021-07-04 08:08:51 +02:00
* Copyright (C) 2007-2021 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 MAINWINDOW_H
#define MAINWINDOW_H
2022-02-02 16:17:28 +01:00
#include "ui_mainwindow.h"
#include "settings.h"
#include "platforms.h"
2022-02-02 16:17:28 +01:00
#include <QFileDialog>
#include <QMainWindow>
#include <QStringList>
class ThreadHandler;
class TranslationHandler;
class ScratchPad;
2017-07-31 12:02:51 +02:00
class ProjectFile;
class QAction;
class QActionGroup;
class QSettings;
class QTimer;
/// @addtogroup GUI
/// @{
/**
2016-10-02 18:23:51 +02:00
* @brief Main window for cppcheck-gui
*
*/
2011-10-13 20:53:06 +02:00
class MainWindow : public QMainWindow {
Q_OBJECT
public:
/**
2016-10-02 18:23:51 +02:00
* @brief Maximum number of MRU project items in File-menu.
*/
enum { MaxRecentProjects = 5 };
MainWindow(TranslationHandler* th, QSettings* settings);
MainWindow(const MainWindow &) = delete;
virtual ~MainWindow();
MainWindow &operator=(const MainWindow &) = delete;
/**
2021-08-07 20:51:18 +02:00
* List of checked platforms.
*/
Platforms mPlatforms;
/**
2017-07-30 13:30:35 +02:00
* @brief Analyze given code
2016-10-02 18:23:51 +02:00
*
2017-07-30 13:30:35 +02:00
* @param code Content of the (virtual) file to be analyzed
* @param filename Name of the (virtual) file to be analyzed - determines language.
2016-10-02 18:23:51 +02:00
*/
void analyzeCode(const QString& code, const QString& filename);
public slots:
2020-08-22 11:37:44 +02:00
/** Update "Functions" tab */
void updateFunctionContractsTab();
/** Update "Variables" tab */
void updateVariableContractsTab();
2017-07-30 13:30:35 +02:00
/** @brief Slot for analyze files menu item */
void analyzeFiles();
2017-07-30 13:30:35 +02:00
/** @brief Slot to reanalyze all files */
void reAnalyzeAll();
/** @brief Slot to reanalyze with checking library configuration */
void checkLibrary();
/** @brief Slot to check configuration */
void checkConfiguration();
/**
2017-07-30 13:30:35 +02:00
* @brief Slot to reanalyze selected files
2016-10-02 18:23:51 +02:00
* @param selectedFilesList list of selected files
*/
void performSelectedFilesCheck(const QStringList &selectedFilesList);
2017-07-30 13:30:35 +02:00
/** @brief Slot to reanalyze modified files */
void reAnalyzeModified();
2016-10-02 18:23:51 +02:00
/** @brief Slot to clear all search results */
2017-07-28 10:41:03 +02:00
void clearResults();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open XML report file */
2017-07-28 10:41:03 +02:00
void openResults();
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "style"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showStyle(bool checked);
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "error"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showErrors(bool checked);
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "warning"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showWarnings(bool checked);
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "portability"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showPortability(bool checked);
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "performance"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showPerformance(bool checked);
/**
2016-10-02 18:23:51 +02:00
* @brief Show errors with type "information"
* @param checked Should errors be shown (true) or hidden (false)
*/
2017-07-28 10:41:03 +02:00
void showInformation(bool checked);
2016-10-02 18:23:51 +02:00
/** @brief Slot to check all "Show errors" menu items */
2017-07-28 10:41:03 +02:00
void checkAll();
2016-10-02 18:23:51 +02:00
/** @brief Slot to uncheck all "Show errors" menu items */
2017-07-28 10:41:03 +02:00
void uncheckAll();
2009-03-22 18:39:44 +01:00
2017-07-30 13:30:35 +02:00
/** @brief Slot for analyze directory menu item */
void analyzeDirectory();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open program's settings dialog */
2017-07-28 10:41:03 +02:00
void programSettings();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open program's about dialog */
2017-07-28 10:41:03 +02:00
void about();
2016-10-02 18:23:51 +02:00
/** @brief Slot to to show license text */
2017-07-28 10:41:03 +02:00
void showLicense();
2016-10-02 18:23:51 +02:00
/** @brief Slot to to show authors list */
2017-07-28 10:41:03 +02:00
void showAuthors();
2016-10-02 18:23:51 +02:00
/** @brief Slot to save results */
2017-07-28 10:41:03 +02:00
void save();
2016-10-02 18:23:51 +02:00
/** @brief Slot to create new project file */
2017-07-28 10:41:03 +02:00
void newProjectFile();
2017-07-30 13:30:35 +02:00
/** @brief Slot to open project file and start analyzing contained paths. */
2017-07-28 10:41:03 +02:00
void openProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot to show scratchpad. */
2017-07-28 10:41:03 +02:00
void showScratchpad();
2016-10-02 18:23:51 +02:00
/** @brief Slot to close open project file. */
2017-07-28 10:41:03 +02:00
void closeProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot to edit project file. */
2017-07-28 10:41:03 +02:00
void editProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing the scan and project statistics. */
2017-07-28 10:41:03 +02:00
void showStatistics();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing the library editor */
2017-07-28 10:41:03 +02:00
void showLibraryEditor();
2015-08-16 17:36:10 +02:00
protected slots:
2016-10-02 18:23:51 +02:00
/** @brief Slot for checkthread's done signal */
void analysisDone();
2017-07-30 13:30:35 +02:00
/** @brief Lock down UI while analyzing */
2017-07-28 10:41:03 +02:00
void checkLockDownUI();
2016-10-02 18:23:51 +02:00
/** @brief Slot for enabling save and clear button */
2017-07-28 10:41:03 +02:00
void resultsAdded();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding standard toolbar */
2017-07-28 10:41:03 +02:00
void toggleMainToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding Categories toolbar */
2017-07-28 10:41:03 +02:00
void toggleViewToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding Filter toolbar */
2017-07-28 10:41:03 +02:00
void toggleFilterToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for updating View-menu before it is shown. */
2017-07-28 10:41:03 +02:00
void aboutToShowViewMenu();
2017-07-30 13:30:35 +02:00
/** @brief Slot when stop analysis button is pressed */
void stopAnalysis();
2016-10-02 18:23:51 +02:00
/** @brief Open help file contents */
2017-07-28 10:41:03 +02:00
void openHelpContents();
2016-10-02 18:23:51 +02:00
/** @brief Filters the results in the result list. */
2017-07-28 10:41:03 +02:00
void filterResults();
2016-10-02 18:23:51 +02:00
/** @brief Opens recently opened project file. */
2017-07-28 10:41:03 +02:00
void openRecentProject();
2017-07-30 13:30:35 +02:00
/** @brief Selects the platform as analyzed platform. */
2017-07-28 10:41:03 +02:00
void selectPlatform();
2017-08-11 07:45:29 +02:00
/** Suppress error ids */
void suppressIds(QStringList ids);
/** Edit contract for function */
void editFunctionContract(QString function);
2020-08-22 11:37:44 +02:00
/** Edit constraints for variable */
void editVariableContract(QString var);
/** Delete contract for function */
void deleteFunctionContract(const QString& function);
2020-08-22 11:37:44 +02:00
/** Edit constraints for variable */
void deleteVariableContract(const QString& var);
2020-08-22 11:37:44 +02:00
private:
/** Get filename for last results */
QString getLastResults() const;
2017-07-30 13:30:35 +02:00
/** @brief Reanalyzes files */
void reAnalyze(bool all);
/**
2017-07-30 13:30:35 +02:00
* @brief Reanalyze selected files
2016-10-02 18:23:51 +02:00
* @param files list of selected files
*/
void reAnalyzeSelected(QStringList files);
/**
2021-08-07 20:51:18 +02:00
* @brief Analyze the project.
* @param projectFile Pointer to the project to analyze.
* @param checkLibrary Flag to indicate if the library should be checked.
* @param checkConfiguration Flag to indicate if the configuration should be checked.
*/
void analyzeProject(const ProjectFile *projectFile, const bool checkLibrary = false, const bool checkConfiguration = false);
/**
2016-10-02 18:23:51 +02:00
* @brief Set current language
* @param code Language code of the language to set (e.g. "en").
*/
2017-07-28 05:44:15 +02:00
void setLanguage(const QString &code);
2016-10-02 18:23:51 +02:00
/** @brief Event coming when application is about to close. */
void closeEvent(QCloseEvent *event) override;
2009-06-01 23:54:21 +02:00
/**
2016-10-02 18:23:51 +02:00
* @brief Helper function to toggle all show error menu items
* @param checked Should all errors be shown (true) or hidden (false)
*/
2017-07-28 05:44:15 +02:00
void toggleAllChecked(bool checked);
2016-10-02 18:23:51 +02:00
/** @brief Helper function to enable/disable all check,recheck buttons */
2017-07-28 05:44:15 +02:00
void enableCheckButtons(bool enable);
/** @brief Helper function to enable/disable results buttons (clear,save,print) */
void enableResultsButtons();
2009-06-01 23:54:21 +02:00
/**
2017-07-30 13:30:35 +02:00
* @brief Select files/or directory to analyze.
2016-10-02 18:23:51 +02:00
* Helper function to open a dialog to ask user to select files or
2017-07-30 13:30:35 +02:00
* directory to analyze. Use native dialogs instead of Qt:s own dialogs.
2016-10-02 18:23:51 +02:00
*
* @param mode Dialog open mode (files or directories)
2017-07-30 13:30:35 +02:00
* @return QStringList of files or directories that were selected to analyze
2016-10-02 18:23:51 +02:00
*/
QStringList selectFilesToAnalyze(QFileDialog::FileMode mode);
2016-08-18 21:58:50 +02:00
/**
2017-07-30 13:30:35 +02:00
* @brief Analyze project
2016-10-02 18:23:51 +02:00
* @param p imported project
* @param checkLibrary Flag to indicate if library should be checked
* @param checkConfiguration Flag to indicate if the configuration should be checked.
2016-10-02 18:23:51 +02:00
*/
void doAnalyzeProject(ImportProject p, const bool checkLibrary = false, const bool checkConfiguration = false);
2016-08-18 21:58:50 +02:00
/**
2017-07-30 13:30:35 +02:00
* @brief Analyze all files specified in parameter files
2016-10-02 18:23:51 +02:00
*
2017-07-30 13:30:35 +02:00
* @param files List of files and/or directories to analyze
* @param checkLibrary Flag to indicate if library should be checked
* @param checkConfiguration Flag to indicate if the configuration should be checked.
2016-10-02 18:23:51 +02:00
*/
void doAnalyzeFiles(const QStringList &files, const bool checkLibrary = false, const bool checkConfiguration = false);
2009-06-01 23:54:21 +02:00
/**
2016-10-02 18:23:51 +02:00
* @brief Get our default cppcheck settings and read project file.
*
* @return Default cppcheck settings
*/
2017-07-28 05:44:15 +02:00
Settings getCppcheckSettings();
2016-10-02 18:23:51 +02:00
/** @brief Load program settings */
2017-07-28 05:44:15 +02:00
void loadSettings();
2016-10-02 18:23:51 +02:00
/** @brief Save program settings */
2017-07-28 05:44:15 +02:00
void saveSettings() const;
/**
2016-10-02 18:23:51 +02:00
* @brief Format main window title.
* @param text Text added to end of the title.
*/
2017-07-28 05:44:15 +02:00
void formatAndSetTitle(const QString &text = QString());
2016-10-02 18:23:51 +02:00
/** @brief Show help contents */
2017-07-28 05:44:15 +02:00
void openOnlineHelp();
/**
2016-10-02 18:23:51 +02:00
* @brief Enable or disable project file actions.
* Project editing and closing actions should be only enabled when project is
2017-07-30 13:30:35 +02:00
* open and we are not analyzing files.
2016-10-02 18:23:51 +02:00
* @param enable If true then actions are enabled.
*/
2017-07-28 05:44:15 +02:00
void enableProjectActions(bool enable);
/**
2016-10-02 18:23:51 +02:00
* @brief Enable or disable project file actions.
2017-07-30 13:30:35 +02:00
* Project opening and creating actions should be disabled when analyzing.
2016-10-02 18:23:51 +02:00
* @param enable If true then actions are enabled.
*/
2017-07-28 05:44:15 +02:00
void enableProjectOpenActions(bool enable);
2010-11-26 21:51:38 +01:00
/**
2016-10-02 18:23:51 +02:00
* @brief Add include directories.
* @param includeDirs List of include directories to add.
* @param result Settings class where include directories are added.
*/
2017-07-28 05:44:15 +02:00
void addIncludeDirs(const QStringList &includeDirs, Settings &result);
2010-11-26 21:51:38 +01:00
/**
2016-10-02 18:23:51 +02:00
* @brief Handle command line parameters given to GUI.
* @param params List of string given to command line.
*/
2017-07-28 05:44:15 +02:00
void handleCLIParams(const QStringList &params);
2013-02-10 23:53:01 +01:00
/**
2016-10-02 18:23:51 +02:00
* @brief Load XML file to the GUI.
* @param selectedFile Filename (inc. path) of XML file to load.
2016-10-02 18:23:51 +02:00
*/
void loadResults(const QString &selectedFile);
/**
2016-10-02 18:23:51 +02:00
* @brief Load XML file to the GUI.
* @param selectedFile Filename (inc. path) of XML file to load.
* @param sourceDirectory Path to the directory that the results were generated for.
2016-10-02 18:23:51 +02:00
*/
void loadResults(const QString &selectedFile, const QString &sourceDirectory);
/**
2021-08-07 20:51:18 +02:00
* @brief Load last project results to the GUI.
* @return Returns true if last results was loaded
*/
bool loadLastResults();
/**
2016-10-02 18:23:51 +02:00
* @brief Load project file to the GUI.
* @param filePath Filename (inc. path) of project file to load.
*/
2017-07-28 05:44:15 +02:00
void loadProjectFile(const QString &filePath);
/**
* @brief Load library file
2014-01-01 20:46:00 +01:00
* @param library library to use
* @param filename filename (no path)
* @return error code
*/
Library::Error loadLibrary(Library *library, const QString &filename);
/**
2016-10-02 18:23:51 +02:00
* @brief Tries to load library file, prints message on error
* @param library library to use
* @param filename filename (no path)
* @return True if no error
*/
bool tryLoadLibrary(Library *library, const QString& filename);
/**
2016-10-02 18:23:51 +02:00
* @brief Update project MRU items in File-menu.
*/
2017-07-28 05:44:15 +02:00
void updateMRUMenuItems();
/**
2016-10-02 18:23:51 +02:00
* @brief Add project file (path) to the MRU list.
* @param project Full path to the project file to add.
*/
2017-07-28 05:44:15 +02:00
void addProjectMRU(const QString &project);
/**
2016-10-02 18:23:51 +02:00
* @brief Remove project file (path) from the MRU list.
* @param project Full path of the project file to remove.
*/
2017-07-28 05:44:15 +02:00
void removeProjectMRU(const QString &project);
2016-10-02 18:23:51 +02:00
/** @brief Program settings */
QSettings *mSettings;
2017-07-30 13:30:35 +02:00
/** @brief Thread to analyze files */
ThreadHandler *mThread;
2016-10-02 18:23:51 +02:00
/** @brief List of user defined applications to open errors with */
ApplicationList *mApplications;
2009-03-22 18:39:44 +01:00
2016-10-02 18:23:51 +02:00
/** @brief Class to handle translation changes */
TranslationHandler *mTranslation;
2016-10-02 18:23:51 +02:00
/** @brief Class holding all UI components */
Ui::MainWindow mUI;
2017-07-30 13:30:35 +02:00
/** @brief Current analyzed directory. */
QString mCurrentDirectory;
2016-10-02 18:23:51 +02:00
/** @brief Scratchpad. */
ScratchPad* mScratchPad;
2016-10-02 18:23:51 +02:00
/** @brief Project (file). */
2017-07-31 12:02:51 +02:00
ProjectFile *mProjectFile;
2016-10-02 18:23:51 +02:00
/** @brief Filter field in the Filter toolbar. */
QLineEdit* mLineEditFilter;
2016-10-02 18:23:51 +02:00
/** @brief Timer to delay filtering while typing. */
QTimer* mFilterTimer;
2017-07-30 13:30:35 +02:00
/** @brief GUI actions for selecting the analyzed platform. */
QActionGroup *mPlatformActions;
2016-10-02 18:23:51 +02:00
/** @brief GUI actions for selecting the coding standard. */
QActionGroup *mCStandardActions, *mCppStandardActions;
2016-10-02 18:23:51 +02:00
/** @brief GUI actions for selecting language. */
QActionGroup *mSelectLanguageActions;
/**
2016-10-02 18:23:51 +02:00
* @brief Are we exiting the cppcheck?
* If this is true then the cppcheck is waiting for check threads to exit
* so that the application can be closed.
*/
bool mExiting;
2016-10-02 18:23:51 +02:00
/** @brief Set to true in case of loading log file. */
bool mIsLogfileLoaded;
/**
* @brief Project MRU menu actions.
* List of MRU menu actions. Needs also to store the separator.
*/
QAction *mRecentProjectActs[MaxRecentProjects + 1];
};
/// @}
#endif // MAINWINDOW_H