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. *