Skip to content

Commit

Permalink
Fix #13008 (GUI: Crash when I try to recheck a file) (#6705)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar authored Aug 17, 2024
1 parent befe62d commit dbd1647
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
27 changes: 19 additions & 8 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,21 +1306,21 @@ void MainWindow::reAnalyzeModified()
void MainWindow::reAnalyzeAll()
{
if (mProjectFile)
analyzeProject(mProjectFile);
analyzeProject(mProjectFile, QStringList());
else
reAnalyze(true);
}

void MainWindow::checkLibrary()
{
if (mProjectFile)
analyzeProject(mProjectFile, true);
analyzeProject(mProjectFile, QStringList(), true);
}

void MainWindow::checkConfiguration()
{
if (mProjectFile)
analyzeProject(mProjectFile, false, true);
analyzeProject(mProjectFile, QStringList(), false, true);
}

void MainWindow::reAnalyzeSelected(const QStringList& files)
Expand All @@ -1330,6 +1330,16 @@ void MainWindow::reAnalyzeSelected(const QStringList& files)
if (mThread->isChecking())
return;

if (mProjectFile) {
// Clear details, statistics and progress
mUI->mResults->clear(false);
for (int i = 0; i < files.size(); ++i)
mUI->mResults->clearRecheckFile(files[i]);

analyzeProject(mProjectFile, files);
return;
}

const QPair<bool, Settings> checkSettingsPair = getCppcheckSettings();
if (!checkSettingsPair.first)
return;
Expand Down Expand Up @@ -1795,7 +1805,7 @@ void MainWindow::loadProjectFile(const QString &filePath)
mProjectFile = new ProjectFile(filePath, this);
mProjectFile->setActiveProject();
if (!loadLastResults())
analyzeProject(mProjectFile);
analyzeProject(mProjectFile, QStringList());
}

QString MainWindow::getLastResults() const
Expand All @@ -1812,14 +1822,15 @@ bool MainWindow::loadLastResults()
return false;
if (!QFileInfo::exists(lastResults))
return false;
mUI->mResults->clear(true);
mUI->mResults->readErrorsXml(lastResults);
mUI->mResults->setCheckDirectory(mSettings->value(SETTINGS_LAST_CHECK_PATH,QString()).toString());
mUI->mActionViewStats->setEnabled(true);
enableResultsButtons();
return true;
}

void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool checkLibrary, const bool checkConfiguration)
void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool checkLibrary, const bool checkConfiguration)
{
Settings::terminate(false);

Expand Down Expand Up @@ -1921,7 +1932,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
return;
}

QStringList paths = projectFile->getCheckPaths();
QStringList paths = recheckFiles.isEmpty() ? projectFile->getCheckPaths() : recheckFiles;

// If paths not given then check the root path (which may be the project
// file's location, see above). This is to keep the compatibility with
Expand Down Expand Up @@ -1962,7 +1973,7 @@ void MainWindow::newProjectFile()
ProjectFileDialog dlg(mProjectFile, isCppcheckPremium(), this);
if (dlg.exec() == QDialog::Accepted) {
addProjectMRU(filepath);
analyzeProject(mProjectFile);
analyzeProject(mProjectFile, QStringList());
} else {
closeProjectFile();
}
Expand Down Expand Up @@ -1993,7 +2004,7 @@ void MainWindow::editProjectFile()
ProjectFileDialog dlg(mProjectFile, isCppcheckPremium(), this);
if (dlg.exec() == QDialog::Accepted) {
mProjectFile->write();
analyzeProject(mProjectFile);
analyzeProject(mProjectFile, QStringList());
}
}

Expand Down
3 changes: 2 additions & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,11 @@ private slots:
/**
* @brief Analyze the project.
* @param projectFile Pointer to the project to analyze.
* @param recheckFiles files to recheck, empty => check all files
* @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, bool checkLibrary = false, bool checkConfiguration = false);
void analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, bool checkLibrary = false, bool checkConfiguration = false);

/**
* @brief Set current language
Expand Down
23 changes: 23 additions & 0 deletions gui/manualtest/mainwindow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

===========
Main window
===========

Some manual testing in the main window interface


Recheck file
============

Load a project with results.
Restart the GUI.
Right click on a file and click on "Recheck".
EXPECTED: Results for that file should be refreshed.


Switch project
==============

Open project #1
Open project #2 that has different results
EXPECTED: Results for project #1 should go away, results for project #2 should be shown

0 comments on commit dbd1647

Please sign in to comment.