From cea63591d6edea1c97c688aa198dd9c8583a0fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 16 Aug 2024 21:36:06 +0200 Subject: [PATCH] Fix #13008 (GUI: Crash when I try to recheck a file) --- gui/mainwindow.cpp | 27 +++++++++++++++++++-------- gui/mainwindow.h | 3 ++- gui/manualtest/mainwindow.txt | 23 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 gui/manualtest/mainwindow.txt diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 32af92baad26..8303bd2090fc 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1304,7 +1304,7 @@ void MainWindow::reAnalyzeModified() void MainWindow::reAnalyzeAll() { if (mProjectFile) - analyzeProject(mProjectFile); + analyzeProject(mProjectFile, QStringList()); else reAnalyze(true); } @@ -1312,13 +1312,13 @@ void MainWindow::reAnalyzeAll() 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) @@ -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 checkSettingsPair = getCppcheckSettings(); if (!checkSettingsPair.first) return; @@ -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 @@ -1810,6 +1820,7 @@ 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); @@ -1817,7 +1828,7 @@ bool MainWindow::loadLastResults() 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); @@ -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 @@ -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(); } @@ -1991,7 +2002,7 @@ void MainWindow::editProjectFile() ProjectFileDialog dlg(mProjectFile, isCppcheckPremium(), this); if (dlg.exec() == QDialog::Accepted) { mProjectFile->write(); - analyzeProject(mProjectFile); + analyzeProject(mProjectFile, QStringList()); } } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 165e263246dc..9909ede53312 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -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, const bool checkLibrary = false, const bool checkConfiguration = false); + void analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool checkLibrary = false, const bool checkConfiguration = false); /** * @brief Set current language diff --git a/gui/manualtest/mainwindow.txt b/gui/manualtest/mainwindow.txt new file mode 100644 index 000000000000..6d1c0740c565 --- /dev/null +++ b/gui/manualtest/mainwindow.txt @@ -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