Skip to content

Commit c8b6532

Browse files
committed
Fix #13008 (GUI: Crash when I try to recheck a file)
1 parent 1b7dd3a commit c8b6532

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

gui/mainwindow.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,21 +1304,21 @@ void MainWindow::reAnalyzeModified()
13041304
void MainWindow::reAnalyzeAll()
13051305
{
13061306
if (mProjectFile)
1307-
analyzeProject(mProjectFile);
1307+
analyzeProject(mProjectFile, QStringList());
13081308
else
13091309
reAnalyze(true);
13101310
}
13111311

13121312
void MainWindow::checkLibrary()
13131313
{
13141314
if (mProjectFile)
1315-
analyzeProject(mProjectFile, true);
1315+
analyzeProject(mProjectFile, QStringList(), true);
13161316
}
13171317

13181318
void MainWindow::checkConfiguration()
13191319
{
13201320
if (mProjectFile)
1321-
analyzeProject(mProjectFile, false, true);
1321+
analyzeProject(mProjectFile, QStringList(), false, true);
13221322
}
13231323

13241324
void MainWindow::reAnalyzeSelected(const QStringList& files)
@@ -1328,6 +1328,16 @@ void MainWindow::reAnalyzeSelected(const QStringList& files)
13281328
if (mThread->isChecking())
13291329
return;
13301330

1331+
if (mProjectFile) {
1332+
// Clear details, statistics and progress
1333+
mUI->mResults->clear(false);
1334+
for (int i = 0; i < files.size(); ++i)
1335+
mUI->mResults->clearRecheckFile(files[i]);
1336+
1337+
analyzeProject(mProjectFile, files);
1338+
return;
1339+
}
1340+
13311341
const QPair<bool, Settings> checkSettingsPair = getCppcheckSettings();
13321342
if (!checkSettingsPair.first)
13331343
return;
@@ -1793,7 +1803,7 @@ void MainWindow::loadProjectFile(const QString &filePath)
17931803
mProjectFile = new ProjectFile(filePath, this);
17941804
mProjectFile->setActiveProject();
17951805
if (!loadLastResults())
1796-
analyzeProject(mProjectFile);
1806+
analyzeProject(mProjectFile, QStringList());
17971807
}
17981808

17991809
QString MainWindow::getLastResults() const
@@ -1810,14 +1820,15 @@ bool MainWindow::loadLastResults()
18101820
return false;
18111821
if (!QFileInfo::exists(lastResults))
18121822
return false;
1823+
mUI->mResults->clear(true);
18131824
mUI->mResults->readErrorsXml(lastResults);
18141825
mUI->mResults->setCheckDirectory(mSettings->value(SETTINGS_LAST_CHECK_PATH,QString()).toString());
18151826
mUI->mActionViewStats->setEnabled(true);
18161827
enableResultsButtons();
18171828
return true;
18181829
}
18191830

1820-
void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool checkLibrary, const bool checkConfiguration)
1831+
void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool checkLibrary, const bool checkConfiguration)
18211832
{
18221833
Settings::terminate(false);
18231834

@@ -1919,7 +1930,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
19191930
return;
19201931
}
19211932

1922-
QStringList paths = projectFile->getCheckPaths();
1933+
QStringList paths = recheckFiles.isEmpty() ? projectFile->getCheckPaths() : recheckFiles;
19231934

19241935
// If paths not given then check the root path (which may be the project
19251936
// file's location, see above). This is to keep the compatibility with
@@ -1960,7 +1971,7 @@ void MainWindow::newProjectFile()
19601971
ProjectFileDialog dlg(mProjectFile, isCppcheckPremium(), this);
19611972
if (dlg.exec() == QDialog::Accepted) {
19621973
addProjectMRU(filepath);
1963-
analyzeProject(mProjectFile);
1974+
analyzeProject(mProjectFile, QStringList());
19641975
} else {
19651976
closeProjectFile();
19661977
}
@@ -1991,7 +2002,7 @@ void MainWindow::editProjectFile()
19912002
ProjectFileDialog dlg(mProjectFile, isCppcheckPremium(), this);
19922003
if (dlg.exec() == QDialog::Accepted) {
19932004
mProjectFile->write();
1994-
analyzeProject(mProjectFile);
2005+
analyzeProject(mProjectFile, QStringList());
19952006
}
19962007
}
19972008

gui/mainwindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,11 @@ private slots:
262262
/**
263263
* @brief Analyze the project.
264264
* @param projectFile Pointer to the project to analyze.
265+
* @param recheckFiles files to recheck, empty => check all files
265266
* @param checkLibrary Flag to indicate if the library should be checked.
266267
* @param checkConfiguration Flag to indicate if the configuration should be checked.
267268
*/
268-
void analyzeProject(const ProjectFile *projectFile, bool checkLibrary = false, bool checkConfiguration = false);
269+
void analyzeProject(const ProjectFile *projectFile, const QStringList& recheckFiles, const bool checkLibrary = false, const bool checkConfiguration = false);
269270

270271
/**
271272
* @brief Set current language

gui/manualtest/mainwindow.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
===========
3+
Main window
4+
===========
5+
6+
Some manual testing in the main window interface
7+
8+
9+
Recheck file
10+
============
11+
12+
Load a project with results.
13+
Restart the GUI.
14+
Right click on a file and click on "Recheck".
15+
EXPECTED: Results for that file should be refreshed.
16+
17+
18+
Switch project
19+
==============
20+
21+
Open project #1
22+
Open project #2 that has different results
23+
EXPECTED: Results for project #1 should go away, results for project #2 should be shown

0 commit comments

Comments
 (0)