1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "clangfileinfo.h" 29 #include "clangtoolsdiagnostic.h" 30 #include "clangtoolsdiagnosticmodel.h" 31 #include "clangtoolslogfilereader.h" 32 33 #include <debugger/debuggermainwindow.h> 34 35 #include <projectexplorer/runconfiguration.h> 36 #include <cpptools/projectinfo.h> 37 38 #include <utils/variant.h> 39 40 QT_BEGIN_NAMESPACE 41 class QFrame; 42 class QToolButton; 43 QT_END_NAMESPACE 44 45 namespace CppTools { 46 class ClangDiagnosticConfig; 47 } 48 namespace Debugger { 49 class DetailedErrorView; 50 } 51 namespace ProjectExplorer { 52 class RunControl; 53 } 54 namespace Utils { 55 class FilePath; 56 class FancyLineEdit; 57 } // namespace Utils 58 59 namespace ClangTools { 60 namespace Internal { 61 62 class InfoBarWidget; 63 class ClangToolsDiagnosticModel; 64 class ClangToolRunWorker; 65 class Diagnostic; 66 class DiagnosticFilterModel; 67 class DiagnosticView; 68 class RunSettings; 69 class SelectFixitsCheckBox; 70 71 const char ClangTidyClazyPerspectiveId[] = "ClangTidyClazy.Perspective"; 72 73 class ClangTool : public QObject 74 { 75 Q_OBJECT 76 77 public: 78 static ClangTool *instance(); 79 80 ClangTool(); 81 82 void selectPerspective(); 83 84 enum class FileSelectionType { 85 AllFiles, 86 CurrentFile, 87 AskUser, 88 }; 89 90 using FileSelection = Utils::variant<FileSelectionType, Utils::FilePath>; 91 92 void startTool(FileSelection fileSelection); 93 void startTool(FileSelection fileSelection, 94 const RunSettings &runSettings, 95 const CppTools::ClangDiagnosticConfig &diagnosticConfig); 96 97 Diagnostics read(OutputFileFormat outputFileFormat, 98 const QString &logFilePath, 99 const QSet<Utils::FilePath> &projectFiles, 100 QString *errorMessage) const; 101 102 FileInfos collectFileInfos(ProjectExplorer::Project *project, 103 FileSelection fileSelection); 104 105 // For testing. 106 QSet<Diagnostic> diagnostics() const; 107 108 const QString &name() const; 109 110 void onNewDiagnosticsAvailable(const Diagnostics &diagnostics, bool generateMarks); 111 startAction()112 QAction *startAction() const { return m_startAction; } startOnCurrentFileAction()113 QAction *startOnCurrentFileAction() const { return m_startOnCurrentFileAction; } 114 115 signals: 116 void finished(const QString &errorText); // For testing. 117 118 private: 119 enum class State { 120 Initial, 121 PreparationStarted, 122 PreparationFailed, 123 AnalyzerRunning, 124 StoppedByUser, 125 AnalyzerFinished, 126 ImportFinished, 127 }; 128 void setState(State state); 129 void update(); 130 void updateForCurrentState(); 131 void updateForInitialState(); 132 133 void help(); 134 135 void filter(); 136 void clearFilter(); 137 void filterForCurrentKind(); 138 void filterOutCurrentKind(); 139 void setFilterOptions(const OptionalFilterOptions &filterOptions); 140 141 void onBuildFailed(); 142 void onStartFailed(); 143 void onStarted(); 144 void onRunControlStopped(); 145 146 void initDiagnosticView(); 147 void loadDiagnosticsFromFiles(); 148 149 DiagnosticItem *diagnosticItem(const QModelIndex &index) const; 150 void showOutputPane(); 151 152 void reset(); 153 154 FileInfoProviders fileInfoProviders(ProjectExplorer::Project *project, 155 const FileInfos &allFileInfos); 156 157 ClangToolsDiagnosticModel *m_diagnosticModel = nullptr; 158 ProjectExplorer::RunControl *m_runControl = nullptr; 159 ClangToolRunWorker *m_runWorker = nullptr; 160 161 InfoBarWidget *m_infoBarWidget = nullptr; 162 DiagnosticView *m_diagnosticView = nullptr;; 163 164 QAction *m_startAction = nullptr; 165 QAction *m_startOnCurrentFileAction = nullptr; 166 QAction *m_stopAction = nullptr; 167 168 State m_state = State::Initial; 169 int m_filesCount = 0; 170 int m_filesSucceeded = 0; 171 int m_filesFailed = 0; 172 173 DiagnosticFilterModel *m_diagnosticFilterModel = nullptr; 174 175 QAction *m_showFilter = nullptr; 176 SelectFixitsCheckBox *m_selectFixitsCheckBox = nullptr; 177 QToolButton *m_applyFixitsButton = nullptr; 178 179 QAction *m_openProjectSettings = nullptr; 180 QAction *m_goBack = nullptr; 181 QAction *m_goNext = nullptr; 182 QAction *m_loadExported = nullptr; 183 QAction *m_clear = nullptr; 184 QAction *m_expandCollapse = nullptr; 185 186 Utils::Perspective m_perspective{ClangTidyClazyPerspectiveId, tr("Clang-Tidy and Clazy")}; 187 188 private: 189 const QString m_name; 190 }; 191 192 } // namespace Internal 193 } // namespace ClangTools 194