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.
This commit is contained in:
versat 2018-04-13 15:28:05 +02:00 committed by Sebastian
parent 7031cc7e22
commit 024f84ea60
3 changed files with 60 additions and 9 deletions

View File

@ -114,6 +114,8 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mUI.mActionReanalyzeModified, &QAction::triggered, this, &MainWindow::reAnalyzeModified); connect(mUI.mActionReanalyzeModified, &QAction::triggered, this, &MainWindow::reAnalyzeModified);
connect(mUI.mActionReanalyzeAll, &QAction::triggered, this, &MainWindow::reAnalyzeAll); 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.mActionStop, &QAction::triggered, this, &MainWindow::stopAnalysis);
connect(mUI.mActionSave, &QAction::triggered, this, &MainWindow::save); connect(mUI.mActionSave, &QAction::triggered, this, &MainWindow::save);
@ -384,7 +386,7 @@ void MainWindow::saveSettings() const
mUI.mResults->saveSettings(mSettings); mUI.mResults->saveSettings(mSettings);
} }
void MainWindow::doAnalyzeProject(ImportProject p) void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration)
{ {
clearResults(); clearResults();
@ -442,6 +444,8 @@ void MainWindow::doAnalyzeProject(ImportProject p)
mUI.mResults->setCheckDirectory(checkPath); mUI.mResults->setCheckDirectory(checkPath);
Settings checkSettings = getCppcheckSettings(); Settings checkSettings = getCppcheckSettings();
checkSettings.force = false; checkSettings.force = false;
checkSettings.checkLibrary = checkLibrary;
checkSettings.checkConfiguration = checkConfiguration;
if (mProjectFile) if (mProjectFile)
qDebug() << "Checking project file" << mProjectFile->getFilename(); qDebug() << "Checking project file" << mProjectFile->getFilename();
@ -462,7 +466,7 @@ void MainWindow::doAnalyzeProject(ImportProject p)
mThread->check(checkSettings); mThread->check(checkSettings);
} }
void MainWindow::doAnalyzeFiles(const QStringList &files) void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrary, const bool checkConfiguration)
{ {
if (files.isEmpty()) { if (files.isEmpty()) {
return; return;
@ -495,7 +499,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files)
mUI.mResults->checkingStarted(fileNames.count()); mUI.mResults->checkingStarted(fileNames.count());
mThread->setFiles(fileNames); mThread->setFiles(fileNames);
if (mProjectFile) if (mProjectFile && !checkConfiguration)
mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString()); mThread->setAddonsAndTools(mProjectFile->getAddonsAndTools(), mSettings->value(SETTINGS_MISRA_FILE).toString());
QDir inf(mCurrentDirectory); QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath(); const QString checkPath = inf.canonicalPath();
@ -505,6 +509,8 @@ void MainWindow::doAnalyzeFiles(const QStringList &files)
mUI.mResults->setCheckDirectory(checkPath); mUI.mResults->setCheckDirectory(checkPath);
Settings checkSettings = getCppcheckSettings(); Settings checkSettings = getCppcheckSettings();
checkSettings.checkLibrary = checkLibrary;
checkSettings.checkConfiguration = checkConfiguration;
if (mProjectFile) if (mProjectFile)
qDebug() << "Checking project file" << mProjectFile->getFilename(); qDebug() << "Checking project file" << mProjectFile->getFilename();
@ -1022,6 +1028,18 @@ void MainWindow::reAnalyzeAll()
reAnalyze(true); reAnalyze(true);
} }
void MainWindow::checkLibrary()
{
if (mProjectFile)
analyzeProject(mProjectFile, true);
}
void MainWindow::checkConfiguration()
{
if (mProjectFile)
analyzeProject(mProjectFile, false, true);
}
void MainWindow::reAnalyzeSelected(QStringList files) void MainWindow::reAnalyzeSelected(QStringList files)
{ {
if (files.empty()) if (files.empty())
@ -1078,6 +1096,7 @@ void MainWindow::reAnalyze(bool all)
void MainWindow::clearResults() void MainWindow::clearResults()
{ {
mUI.mResults->clear(true); mUI.mResults->clear(true);
Q_ASSERT(false == mUI.mResults->hasResults());
enableResultsButtons(); enableResultsButtons();
} }
@ -1445,7 +1464,7 @@ bool MainWindow::loadLastResults()
return true; return true;
} }
void MainWindow::analyzeProject(const ProjectFile *projectFile) void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool checkLibrary, const bool checkConfiguration)
{ {
Settings::terminate(false); Settings::terminate(false);
@ -1500,7 +1519,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile)
msg.exec(); msg.exec();
return; return;
} }
doAnalyzeProject(p); doAnalyzeProject(p, checkLibrary, checkConfiguration);
return; return;
} }
@ -1522,7 +1541,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile)
paths[i] = QDir::cleanPath(path); paths[i] = QDir::cleanPath(path);
} }
} }
doAnalyzeFiles(paths); doAnalyzeFiles(paths, checkLibrary, checkConfiguration);
} }
void MainWindow::newProjectFile() void MainWindow::newProjectFile()
@ -1617,6 +1636,8 @@ void MainWindow::enableProjectActions(bool enable)
{ {
mUI.mActionCloseProjectFile->setEnabled(enable); mUI.mActionCloseProjectFile->setEnabled(enable);
mUI.mActionEditProjectFile->setEnabled(enable); mUI.mActionEditProjectFile->setEnabled(enable);
mUI.mActionCheckLibrary->setEnabled(enable);
mUI.mActionCheckConfiguration->setEnabled(enable);
} }
void MainWindow::enableProjectOpenActions(bool enable) void MainWindow::enableProjectOpenActions(bool enable)

View File

@ -77,6 +77,12 @@ public slots:
/** @brief Slot to reanalyze all files */ /** @brief Slot to reanalyze all files */
void reAnalyzeAll(); 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 * @brief Slot to reanalyze selected files
* @param selectedFilesList list of selected files * @param selectedFilesList list of selected files
@ -234,8 +240,10 @@ private:
/** /**
* @brief Analyze the project. * @brief Analyze the project.
* @param projectFile Pointer to the project to analyze. * @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 * @brief Set current language
@ -271,15 +279,19 @@ private:
/** /**
* @brief Analyze project * @brief Analyze project
* @param p imported 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 * @brief Analyze all files specified in parameter files
* *
* @param files List of files and/or directories to analyze * @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. * @brief Get our default cppcheck settings and read project file.

View File

@ -150,6 +150,8 @@
<addaction name="mActionAnalyzeDirectory"/> <addaction name="mActionAnalyzeDirectory"/>
<addaction name="mActionReanalyzeModified"/> <addaction name="mActionReanalyzeModified"/>
<addaction name="mActionReanalyzeAll"/> <addaction name="mActionReanalyzeAll"/>
<addaction name="mActionCheckLibrary"/>
<addaction name="mActionCheckConfiguration"/>
<addaction name="mActionStop"/> <addaction name="mActionStop"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menuC_standard"/> <addaction name="menuC_standard"/>
@ -793,6 +795,22 @@
<string>C++14</string> <string>C++14</string>
</property> </property>
</action> </action>
<action name="mActionCheckLibrary">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Reanalyze and check library</string>
</property>
</action>
<action name="mActionCheckConfiguration">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Check configuration (defines, includes)</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>