From 8731b3efddaf8df84a665a8c05b95db44ec7602e Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Wed, 25 Aug 2010 00:47:05 +0300 Subject: [PATCH] Fixed #1977 (GUI crashes when checking a directory) The GUI was crashing if no project files were in checked directory. I missed this case in my own testing because I had created test project files for each directory. Whoops! Anyway, this now also makes silently loaded project files (project file residing in directory but not load by the user) as normal projects in the GUI. --- gui/mainwindow.cpp | 31 ++++++++++++++++--------------- gui/mainwindow.h | 9 +++++++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 59568a44c..3baddf4a2 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -302,13 +302,13 @@ void MainWindow::CheckDirectory() DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly)); } -Settings MainWindow::GetCppcheckSettings() +bool MainWindow::GetCheckProject() { - ProjectFile *pfile = NULL; - Settings result; - bool projectRead = true; + // We have succesfully loaded project earlier and use that project + if (mProject) + return true; - if (!mCurrentDirectory.isEmpty() && !mProject) + if (!mCurrentDirectory.isEmpty()) { // Format project filename (directory name + .cppcheck) and load // the project file if it is found. @@ -316,18 +316,22 @@ Settings MainWindow::GetCppcheckSettings() QString projfile = mCurrentDirectory + "/" + parts[parts.count() - 1] + ".cppcheck"; if (QFile::exists(projfile)) { - qDebug() << "Reading project file " << projfile; - pfile = new ProjectFile(); - projectRead = pfile->Read(projfile); + qDebug() << "Opening project file: " << projfile; + mProject = new Project(); + mProject->SetFilename(projfile); + return mProject->Open(); } } - else if (mProject) - { - pfile = mProject->GetProjectFile(); - } + return false; +} +Settings MainWindow::GetCppcheckSettings() +{ + Settings result; + bool projectRead = GetCheckProject(); if (projectRead) { + ProjectFile *pfile = mProject->GetProjectFile(); QStringList dirs = pfile->GetIncludeDirs(); QString dir; foreach(dir, dirs) @@ -353,9 +357,6 @@ Settings MainWindow::GetCppcheckSettings() } } - if (!mProject) - delete pfile; - result._debug = false; result._checkCodingStyle = true; result._errorsOnly = false; diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 619fe71a6..144206870 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -266,6 +266,15 @@ protected: */ void DoCheckFiles(const QStringList &files); + /** + * @brief Check if we have a project for the checked directory. + * This method checks if there is open project for the directory. If no open + * project then we check if there is project file in the directory and load + * it. + * @return true if we have project, false if no project. + */ + bool MainWindow::GetCheckProject(); + /** * @brief Get our default cppcheck settings and read project file. *