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.
This commit is contained in:
Kimmo Varis 2010-08-25 00:47:05 +03:00
parent e7f7c77eab
commit 8731b3efdd
2 changed files with 25 additions and 15 deletions

View File

@ -302,13 +302,13 @@ void MainWindow::CheckDirectory()
DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly)); DoCheckFiles(SelectFilesToCheck(QFileDialog::DirectoryOnly));
} }
Settings MainWindow::GetCppcheckSettings() bool MainWindow::GetCheckProject()
{ {
ProjectFile *pfile = NULL; // We have succesfully loaded project earlier and use that project
Settings result; if (mProject)
bool projectRead = true; return true;
if (!mCurrentDirectory.isEmpty() && !mProject) if (!mCurrentDirectory.isEmpty())
{ {
// Format project filename (directory name + .cppcheck) and load // Format project filename (directory name + .cppcheck) and load
// the project file if it is found. // the project file if it is found.
@ -316,18 +316,22 @@ Settings MainWindow::GetCppcheckSettings()
QString projfile = mCurrentDirectory + "/" + parts[parts.count() - 1] + ".cppcheck"; QString projfile = mCurrentDirectory + "/" + parts[parts.count() - 1] + ".cppcheck";
if (QFile::exists(projfile)) if (QFile::exists(projfile))
{ {
qDebug() << "Reading project file " << projfile; qDebug() << "Opening project file: " << projfile;
pfile = new ProjectFile(); mProject = new Project();
projectRead = pfile->Read(projfile); mProject->SetFilename(projfile);
return mProject->Open();
} }
} }
else if (mProject) return false;
{ }
pfile = mProject->GetProjectFile();
}
Settings MainWindow::GetCppcheckSettings()
{
Settings result;
bool projectRead = GetCheckProject();
if (projectRead) if (projectRead)
{ {
ProjectFile *pfile = mProject->GetProjectFile();
QStringList dirs = pfile->GetIncludeDirs(); QStringList dirs = pfile->GetIncludeDirs();
QString dir; QString dir;
foreach(dir, dirs) foreach(dir, dirs)
@ -353,9 +357,6 @@ Settings MainWindow::GetCppcheckSettings()
} }
} }
if (!mProject)
delete pfile;
result._debug = false; result._debug = false;
result._checkCodingStyle = true; result._checkCodingStyle = true;
result._errorsOnly = false; result._errorsOnly = false;

View File

@ -266,6 +266,15 @@ protected:
*/ */
void DoCheckFiles(const QStringList &files); 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. * @brief Get our default cppcheck settings and read project file.
* *