Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13008 (GUI: Crash when I try to recheck a file) #6705

Merged
merged 2 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,21 +1304,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 @@ -1328,6 +1328,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 @@ -1793,7 +1803,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 @@ -1810,14 +1820,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 @@ -1919,7 +1930,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 @@ -1960,7 +1971,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 @@ -1991,7 +2002,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
Loading