cppcheck/gui/mainwindow.h

445 lines
12 KiB
C
Raw Normal View History

/*
* Cppcheck - A tool for static C/C++ code analysis
2016-01-01 14:34:45 +01:00
* Copyright (C) 2007-2016 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
#include <QMainWindow>
#include <QSettings>
#include <QFileDialog>
#include <QActionGroup>
#include <QTimer>
2010-11-26 21:51:38 +01:00
#include <QStringList>
#include "settings.h"
#include "platforms.h"
2016-11-19 23:07:48 +01:00
#include "ui_mainwindow.h"
class ThreadHandler;
class TranslationHandler;
class ScratchPad;
class LogView;
class Project;
class ErrorItem;
class QAction;
/// @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);
virtual ~MainWindow();
/**
* List of checked platforms.
*/
Platforms mPlatforms;
/**
2016-10-02 18:23:51 +02:00
* @brief Checks given code
*
* @param code Content of the (virtual) file to be checked
* @param filename Name of the (virtual) file to be checked - determines language.
*/
void CheckCode(const QString& code, const QString& filename);
public slots:
2016-10-02 18:23:51 +02:00
/** @brief Slot for check files menu item */
void CheckFiles();
2016-10-02 18:23:51 +02:00
/** @brief Slot to recheck all files */
void ReCheckAll();
/**
2016-10-02 18:23:51 +02:00
* @brief Slot to recheck selected files
* @param selectedFilesList list of selected files
*/
void PerformSelectedFilesCheck(QStringList selectedFilesList);
2016-10-02 18:23:51 +02:00
/** @brief Slot to recheck modified files */
void ReCheckModified();
2016-10-02 18:23:51 +02:00
/** @brief Slot to clear all search results */
void ClearResults();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open XML report file */
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)
*/
2009-03-22 18:39:44 +01: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)
*/
2009-03-22 18:39:44 +01: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)
*/
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)
*/
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)
*/
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)
*/
void ShowInformation(bool checked);
2016-10-02 18:23:51 +02:00
/** @brief Slot to check all "Show errors" menu items */
void CheckAll();
2016-10-02 18:23:51 +02:00
/** @brief Slot to uncheck all "Show errors" menu items */
void UncheckAll();
2009-03-22 18:39:44 +01:00
2016-10-02 18:23:51 +02:00
/** @brief Slot for check directory menu item */
void CheckDirectory();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open program's settings dialog */
void ProgramSettings();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open program's about dialog */
void About();
2016-10-02 18:23:51 +02:00
/** @brief Slot to to show license text */
void ShowLicense();
2016-10-02 18:23:51 +02:00
/** @brief Slot to to show authors list */
void ShowAuthors();
2016-10-02 18:23:51 +02:00
/** @brief Slot to save results */
void Save();
2016-10-02 18:23:51 +02:00
/** @brief Slot to create new project file */
void NewProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot to open project file and start checking contained paths. */
void OpenProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot to show scratchpad. */
void ShowScratchpad();
2016-10-02 18:23:51 +02:00
/** @brief Slot to close open project file. */
void CloseProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot to edit project file. */
void EditProjectFile();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing the log view. */
void ShowLogView();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing the scan and project statistics. */
void ShowStatistics();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing the library editor */
2015-08-16 17:36:10 +02:00
void ShowLibraryEditor();
protected slots:
2016-10-02 18:23:51 +02:00
/** @brief Slot for checkthread's done signal */
void CheckDone();
2016-10-02 18:23:51 +02:00
/** @brief Lock down UI while checking */
void CheckLockDownUI();
2016-10-02 18:23:51 +02:00
/** @brief Slot for enabling save and clear button */
void ResultsAdded();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding standard toolbar */
void ToggleMainToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding Categories toolbar */
void ToggleViewToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for showing/hiding Filter toolbar */
void ToggleFilterToolBar();
2016-10-02 18:23:51 +02:00
/** @brief Slot for updating View-menu before it is shown. */
void AboutToShowViewMenu();
2016-10-02 18:23:51 +02:00
/** @brief Slot when stop checking button is pressed */
void StopChecking();
2016-10-02 18:23:51 +02:00
/** @brief Open help file contents */
void OpenHelpContents();
2016-10-02 18:23:51 +02:00
/** @brief Add new line to log. */
void Log(const QString &logline);
2016-10-02 18:23:51 +02:00
/** @brief Handle new debug error. */
void DebugError(const ErrorItem &item);
2016-10-02 18:23:51 +02:00
/** @brief Filters the results in the result list. */
void FilterResults();
2016-10-02 18:23:51 +02:00
/** @brief Opens recently opened project file. */
void OpenRecentProject();
2016-10-02 18:23:51 +02:00
/** @brief Selects the platform as checked platform. */
void SelectPlatform();
private:
2016-10-02 18:23:51 +02:00
/** @brief Rechecks files */
void ReCheck(bool all);
/**
2016-10-02 18:23:51 +02:00
* @brief Recheck selected files
* @param files list of selected files
* @param all true if all files of list, false if modified files of list
*/
void ReCheckSelected(QStringList files, bool all);
/**
* @brief Check the project.
* @param project Pointer to the project to check.
*/
void CheckProject(Project *project);
/**
2016-10-02 18:23:51 +02:00
* @brief Set current language
* @param code Language code of the language to set (e.g. "en").
*/
void SetLanguage(const QString &code);
2016-10-02 18:23:51 +02:00
/** @brief Event coming when application is about to close. */
virtual void closeEvent(QCloseEvent *event);
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)
*/
void ToggleAllChecked(bool checked);
2016-10-02 18:23:51 +02:00
/** @brief Helper function to enable/disable all check,recheck buttons */
void EnableCheckButtons(bool enable);
2009-06-01 23:54:21 +02:00
/**
2016-10-02 18:23:51 +02:00
* @brief Select files/or directory to check.
* Helper function to open a dialog to ask user to select files or
* directory to check. Use native dialogs instead of Qt:s own dialogs.
*
* @param mode Dialog open mode (files or directories)
* @return QStringList of files or directories that were selected to check
*/
QStringList SelectFilesToCheck(QFileDialog::FileMode mode);
2016-08-18 21:58:50 +02:00
/**
2016-10-02 18:23:51 +02:00
* @brief Check project
* @param p imported project
*/
2016-08-18 21:58:50 +02:00
void DoCheckProject(ImportProject p);
/**
2016-10-02 18:23:51 +02:00
* @brief Check all files specified in parameter files
*
* @param files List of files and/or directories to check
*/
void DoCheckFiles(const QStringList &files);
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
*/
Settings GetCppcheckSettings();
2016-10-02 18:23:51 +02:00
/** @brief Load program settings */
void LoadSettings();
2016-10-02 18:23:51 +02:00
/** @brief Save program settings */
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.
*/
void FormatAndSetTitle(const QString &text = QString());
2016-10-02 18:23:51 +02:00
/** @brief Show help contents */
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
* open and we are not checking files.
* @param enable If true then actions are enabled.
*/
void EnableProjectActions(bool enable);
/**
2016-10-02 18:23:51 +02:00
* @brief Enable or disable project file actions.
* Project opening and creating actions should be disabled when checking.
* @param enable If true then actions are enabled.
*/
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.
*/
2010-11-26 21:51:38 +01:00
void AddIncludeDirs(const QStringList &includeDirs, Settings &result);
/**
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.
*/
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 file Filename (inc. path) of XML file to load.
*/
void LoadResults(const QString file);
/**
2016-10-02 18:23:51 +02:00
* @brief Load XML file to the GUI.
* @param file Filename (inc. path) of XML file to load.
* @param checkedDirectory Path to the directory that the results were generated for.
*/
void LoadResults(const QString file, const QString checkedDirectory);
/**
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.
*/
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, 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, QString filename);
/**
2016-10-02 18:23:51 +02:00
* @brief Update project MRU items in File-menu.
*/
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.
*/
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.
*/
void RemoveProjectMRU(const QString &project);
2016-10-02 18:23:51 +02:00
/** @brief Program settings */
QSettings *mSettings;
2016-10-02 18:23:51 +02:00
/** @brief Thread to check 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;
2016-10-02 18:23:51 +02:00
/** @brief Current checked directory. */
QString mCurrentDirectory;
2016-10-02 18:23:51 +02:00
/** @brief Log view. */
LogView *mLogView;
2016-10-02 18:23:51 +02:00
/** @brief Scratchpad. */
ScratchPad* mScratchPad;
2016-10-02 18:23:51 +02:00
/** @brief Project (file). */
Project *mProject;
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;
2016-10-02 18:23:51 +02:00
/** @brief GUI actions for selecting the checked 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