GUI: Open project file and check contained paths.

Now we load user-selected project file and start checking paths it
contains. Project file can be anywhere as long as it contains valid
path(s) to check.
This commit is contained in:
Kimmo Varis 2010-08-15 11:35:46 +03:00
parent a82edf5278
commit c98d398398
3 changed files with 53 additions and 26 deletions

View File

@ -48,7 +48,8 @@ MainWindow::MainWindow() :
mTranslation(new TranslationHandler(this)),
mLanguages(new QActionGroup(this)),
mLogView(NULL),
mExiting(false)
mExiting(false),
mProject(NULL)
{
mUI.setupUi(this);
mUI.mResults->Initialize(mSettings, mApplications);
@ -120,6 +121,7 @@ MainWindow::MainWindow() :
MainWindow::~MainWindow()
{
delete mLogView;
delete mProject;
}
void MainWindow::CreateLanguageMenuItems()
@ -297,25 +299,30 @@ void MainWindow::CheckDirectory()
Settings MainWindow::GetCppcheckSettings()
{
ProjectFile pfile;
ProjectFile *pfile = NULL;
Settings result;
bool projectRead = true;
if (!mCurrentDirectory.isEmpty())
if (!mCurrentDirectory.isEmpty() && !mProject)
{
// Format project filename (directory name + .cppcheck) and load
// the project file if it is found.
QStringList parts = mCurrentDirectory.split("/");
QString projfile = mCurrentDirectory + "/" + parts[parts.count() - 1] + ".cppcheck";
bool projectRead = false;
if (QFile::exists(projfile))
{
qDebug() << "Reading project file " << projfile;
projectRead = pfile.Read(projfile);
projectRead = pfile->Read(projfile);
}
}
else if (mProject)
{
pfile = mProject->GetProjectFile();
}
if (projectRead)
{
QStringList dirs = pfile.GetIncludeDirs();
QStringList dirs = pfile->GetIncludeDirs();
QString dir;
foreach(dir, dirs)
{
@ -329,9 +336,8 @@ Settings MainWindow::GetCppcheckSettings()
if (!incdir.endsWith("/"))
incdir += "/";
result._includePaths.push_back(incdir.toStdString());
}
QStringList defines = pfile.GetDefines();
QStringList defines = pfile->GetDefines();
QString define;
foreach(define, defines)
{
@ -673,6 +679,9 @@ void MainWindow::OpenHtmlHelpContents()
void MainWindow::OpenProjectFile()
{
if (mProject != NULL)
delete mProject;
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
QString filepath = QFileDialog::getOpenFileName(this,
tr("Select Project File"),
@ -681,9 +690,11 @@ void MainWindow::OpenProjectFile()
if (!filepath.isEmpty())
{
Project prj(filepath, this);
if (prj.Open())
prj.Edit();
mProject = new Project(filepath, this);
mProject->Open();
QStringList paths = mProject->GetProjectFile()->GetCheckPaths();
if (!paths.isEmpty())
DoCheckFiles(paths);
}
}

View File

@ -31,8 +31,10 @@
#include "translationhandler.h"
#include "settings.h"
#include "ui_main.h"
class ThreadHandler;
class LogView;
class Project;
/// @addtogroup GUI
/// @{
@ -139,7 +141,7 @@ public slots:
void NewProjectFile();
/**
* @brief Slot to edit existing project file.
* @brief Slot to open project file and start checking contained paths.
*
*/
void OpenProjectFile();
@ -323,10 +325,15 @@ protected:
QString mCurrentDirectory;
/**
* @brief Log view..
* @brief Log view.
*/
LogView *mLogView;
/**
* @brief Project (file).
*/
Project *mProject;
private:
/**

View File

@ -62,6 +62,15 @@ public:
*/
void Create();
/**
* @brief Return current project file.
* @return project file.
*/
ProjectFile * GetProjectFile() const
{
return mPFile;
}
private:
QString mFilename;