From 4a695c78d9b361b36d00a58baa3e0a6050a24385 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 13 Jul 2010 00:10:48 +0300 Subject: [PATCH] GUI: Add two new files I forgot to add earlier. --- gui/project.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ gui/project.h | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 gui/project.cpp create mode 100644 gui/project.h diff --git a/gui/project.cpp b/gui/project.cpp new file mode 100644 index 000000000..5d4f89661 --- /dev/null +++ b/gui/project.cpp @@ -0,0 +1,108 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include "project.h" +#include "projectfile.h" +#include "projectfiledialog.h" + +Project::Project(QWidget *parent) : + QObject(parent), + mPFile(NULL), + mParentWidget(parent) +{ +} + +Project::Project(const QString &filename, QWidget *parent) : + QObject(parent), + mFilename(filename), + mPFile(NULL), + mParentWidget(parent) +{ +} + +Project::~Project() +{ + delete mPFile; +} + +void Project::SetFilename(const QString &filename) +{ + mFilename = filename; +} + +bool Project::Open() +{ + mPFile = new ProjectFile(mFilename, this); + if (QFile::exists(mFilename)) + { + if (!mPFile->Read()) + { + QMessageBox msg(QMessageBox::Critical, + tr("Cppcheck"), + tr("Could not read the project file."), + QMessageBox::Ok, + mParentWidget); + msg.exec(); + mFilename = QString(); + mPFile->SetFilename(mFilename); + return false; + } + return true; + } + return false; +} + +void Project::Edit() +{ + ProjectFileDialog dlg(mFilename, mParentWidget); + + QStringList includes = mPFile->GetIncludeDirs(); + dlg.SetIncludepaths(includes); + QStringList defines = mPFile->GetDefines(); + dlg.SetDefines(defines); + int rv = dlg.exec(); + if (rv == QDialog::Accepted) + { + QStringList includes = dlg.GetIncludePaths(); + mPFile->SetIncludes(includes); + QStringList defines = dlg.GetDefines(); + mPFile->SetDefines(defines); + bool writeSuccess = mPFile->Write(); + if (!writeSuccess) + { + QMessageBox msg(QMessageBox::Critical, + tr("Cppcheck"), + tr("Could not write the project file."), + QMessageBox::Ok, + mParentWidget); + msg.exec(); + } + } +} + +void Project::Create() +{ + mPFile = new ProjectFile(mFilename, this); +} diff --git a/gui/project.h b/gui/project.h new file mode 100644 index 000000000..146375d88 --- /dev/null +++ b/gui/project.h @@ -0,0 +1,74 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef PROJECT_H +#define PROJECT_H + +#include +#include + +class QWidget; +class ProjectFile; + +/// @addtogroup GUI +/// @{ + +/** +* @brief A class that contains project data and manages projects. +* Currently only project file creation and editing is implemented. +*/ +class Project : public QObject +{ + Q_OBJECT + +public: + Project(QWidget *parent = 0); + Project(const QString &filename, QWidget *parent = 0); + ~Project(); + + /** + * @brief Set filename for the project file. + * @param filename Filename. + */ + void SetFilename(const QString &filename); + + /** + * @brief Open existing project file. + */ + bool Open(); + + /** + * @brief Edit the project file. + */ + void Edit(); + + /** + * @brief Create new project file. + */ + void Create(); + +private: + + QString mFilename; + ProjectFile *mPFile; + QWidget *mParentWidget; +}; + +/// @} + +#endif // PROJECT_H