From 024f84ea60a2424fb072908b46968ee14a9c86cb Mon Sep 17 00:00:00 2001 From: versat Date: Fri, 13 Apr 2018 15:28:05 +0200 Subject: [PATCH] GUI: Add "Check library" and "Check configuration" menu entries They both are only enabled when a project is loaded and when started they reanalyze the project one time with the according settings. --- gui/mainwindow.cpp | 33 +++++++++++++++++++++++++++------ gui/mainwindow.h | 18 +++++++++++++++--- gui/mainwindow.ui | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 1fe950bac..c0e83c870 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -114,6 +114,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : connect(mUI.mActionReanalyzeModified, &QAction::triggered, this, &MainWindow::reAnalyzeModified); connect(mUI.mActionReanalyzeAll, &QAction::triggered, this, &MainWindow::reAnalyzeAll); + connect(mUI.mActionCheckLibrary, &QAction::triggered, this, &MainWindow::checkLibrary); + connect(mUI.mActionCheckConfiguration, &QAction::triggered, this, &MainWindow::checkConfiguration); connect(mUI.mActionStop, &QAction::triggered, this, &MainWindow::stopAnalysis); connect(mUI.mActionSave, &QAction::triggered, this, &MainWindow::save); @@ -384,7 +386,7 @@ void MainWindow::saveSettings() const mUI.mResults->saveSettings(mSettings); } -void MainWindow::doAnalyzeProject(ImportProject p) +void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration) { clearResults(); @@ -442,6 +444,8 @@ void MainWindow::doAnalyzeProject(ImportProject p) mUI.mResults->setCheckDirectory(checkPath); Settings checkSettings = getCppcheckSettings(); checkSettings.force = false; + checkSettings.checkLibrary = checkLibrary; + checkSettings.checkConfiguration = checkConfiguration; if (mProjectFile) qDebug() << "Checking project file" << mProjectFile->getFilename(); @@ -462,7 +466,7 @@ void MainWindow::doAnalyzeProject(ImportProject p) mThread->check(checkSettings); } -void MainWindow::doAnalyzeFiles(const QStringList &files) +void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrary, const bool checkConfiguration) { if (files.isEmpty()) { return; @@ -495,7 +499,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files) mUI.mResults->checkingStarted(fileNames.count()); mThread->setFiles(fileNames); - if (mProjectFile) + if (mProjectFile && !checkConfiguration) mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString()); QDir inf(mCurrentDirectory); const QString checkPath = inf.canonicalPath(); @@ -505,6 +509,8 @@ void MainWindow::doAnalyzeFiles(const QStringList &files) mUI.mResults->setCheckDirectory(checkPath); Settings checkSettings = getCppcheckSettings(); + checkSettings.checkLibrary = checkLibrary; + checkSettings.checkConfiguration = checkConfiguration; if (mProjectFile) qDebug() << "Checking project file" << mProjectFile->getFilename(); @@ -1022,6 +1028,18 @@ void MainWindow::reAnalyzeAll() reAnalyze(true); } +void MainWindow::checkLibrary() +{ + if (mProjectFile) + analyzeProject(mProjectFile, true); +} + +void MainWindow::checkConfiguration() +{ + if (mProjectFile) + analyzeProject(mProjectFile, false, true); +} + void MainWindow::reAnalyzeSelected(QStringList files) { if (files.empty()) @@ -1078,6 +1096,7 @@ void MainWindow::reAnalyze(bool all) void MainWindow::clearResults() { mUI.mResults->clear(true); + Q_ASSERT(false == mUI.mResults->hasResults()); enableResultsButtons(); } @@ -1445,7 +1464,7 @@ bool MainWindow::loadLastResults() return true; } -void MainWindow::analyzeProject(const ProjectFile *projectFile) +void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool checkLibrary, const bool checkConfiguration) { Settings::terminate(false); @@ -1500,7 +1519,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile) msg.exec(); return; } - doAnalyzeProject(p); + doAnalyzeProject(p, checkLibrary, checkConfiguration); return; } @@ -1522,7 +1541,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile) paths[i] = QDir::cleanPath(path); } } - doAnalyzeFiles(paths); + doAnalyzeFiles(paths, checkLibrary, checkConfiguration); } void MainWindow::newProjectFile() @@ -1617,6 +1636,8 @@ void MainWindow::enableProjectActions(bool enable) { mUI.mActionCloseProjectFile->setEnabled(enable); mUI.mActionEditProjectFile->setEnabled(enable); + mUI.mActionCheckLibrary->setEnabled(enable); + mUI.mActionCheckConfiguration->setEnabled(enable); } void MainWindow::enableProjectOpenActions(bool enable) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 3f561ebcd..7c0bb5444 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -77,6 +77,12 @@ public slots: /** @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(); + /** * @brief Slot to reanalyze selected files * @param selectedFilesList list of selected files @@ -234,8 +240,10 @@ private: /** * @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); + void analyzeProject(const ProjectFile *projectFile, const bool checkLibrary = false, const bool checkConfiguration = false); /** * @brief Set current language @@ -271,15 +279,19 @@ private: /** * @brief Analyze project * @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. */ - void doAnalyzeProject(ImportProject p); + void doAnalyzeProject(ImportProject p, const bool checkLibrary = false, const bool checkConfiguration = false); /** * @brief Analyze all files specified in parameter files * * @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. */ - void doAnalyzeFiles(const QStringList &files); + void doAnalyzeFiles(const QStringList &files, const bool checkLibrary = false, const bool checkConfiguration = false); /** * @brief Get our default cppcheck settings and read project file. diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index a625df193..d61869952 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -150,6 +150,8 @@ + + @@ -793,6 +795,22 @@ C++14 + + + false + + + Reanalyze and check library + + + + + false + + + Check configuration (defines, includes) + +