GUI: load/save data automatically in the ProjectFileDialog
This commit is contained in:
parent
17d9f88d9e
commit
c4ee9799bc
|
@ -1410,7 +1410,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile)
|
||||||
|
|
||||||
void MainWindow::newProjectFile()
|
void MainWindow::newProjectFile()
|
||||||
{
|
{
|
||||||
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
|
const QString filter = tr("Project files (*.cppcheck)");
|
||||||
QString filepath = QFileDialog::getSaveFileName(this,
|
QString filepath = QFileDialog::getSaveFileName(this,
|
||||||
tr("Select Project Filename"),
|
tr("Select Project Filename"),
|
||||||
getPath(SETTINGS_LAST_PROJECT_PATH),
|
getPath(SETTINGS_LAST_PROJECT_PATH),
|
||||||
|
@ -1418,6 +1418,8 @@ void MainWindow::newProjectFile()
|
||||||
|
|
||||||
if (filepath.isEmpty())
|
if (filepath.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
if (!filepath.endsWith(".cppcheck", Qt::CaseInsensitive))
|
||||||
|
filepath += ".cppcheck";
|
||||||
|
|
||||||
setPath(SETTINGS_LAST_PROJECT_PATH, filepath);
|
setPath(SETTINGS_LAST_PROJECT_PATH, filepath);
|
||||||
|
|
||||||
|
@ -1427,12 +1429,10 @@ void MainWindow::newProjectFile()
|
||||||
|
|
||||||
delete mProjectFile;
|
delete mProjectFile;
|
||||||
mProjectFile = new ProjectFile(this);
|
mProjectFile = new ProjectFile(this);
|
||||||
|
mProjectFile->setFilename(filepath);
|
||||||
|
|
||||||
ProjectFileDialog dlg(filepath, this);
|
ProjectFileDialog dlg(mProjectFile, this);
|
||||||
dlg.loadFromProjectFile(mProjectFile);
|
|
||||||
if (dlg.exec() == QDialog::Accepted) {
|
if (dlg.exec() == QDialog::Accepted) {
|
||||||
dlg.saveToProjectFile(mProjectFile);
|
|
||||||
mProjectFile->write();
|
|
||||||
addProjectMRU(filepath);
|
addProjectMRU(filepath);
|
||||||
analyzeProject(mProjectFile);
|
analyzeProject(mProjectFile);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1461,10 +1461,8 @@ void MainWindow::editProjectFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectFileDialog dlg(mProjectFile->getFilename(), this);
|
ProjectFileDialog dlg(mProjectFile, this);
|
||||||
dlg.loadFromProjectFile(mProjectFile);
|
|
||||||
if (dlg.exec() == QDialog::Accepted) {
|
if (dlg.exec() == QDialog::Accepted) {
|
||||||
dlg.saveToProjectFile(mProjectFile);
|
|
||||||
mProjectFile->write();
|
mProjectFile->write();
|
||||||
analyzeProject(mProjectFile);
|
analyzeProject(mProjectFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,13 @@
|
||||||
#include "cppcheck.h"
|
#include "cppcheck.h"
|
||||||
#include "errorlogger.h"
|
#include "errorlogger.h"
|
||||||
|
|
||||||
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, mFilePath(path)
|
, mProjectFile(projectFile)
|
||||||
{
|
{
|
||||||
mUI.setupUi(this);
|
mUI.setupUi(this);
|
||||||
|
|
||||||
const QFileInfo inf(path);
|
const QFileInfo inf(projectFile->getFilename());
|
||||||
QString filename = inf.fileName();
|
QString filename = inf.fileName();
|
||||||
QString title = tr("Project file: %1").arg(filename);
|
QString title = tr("Project file: %1").arg(filename);
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
|
@ -90,7 +90,7 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
mLibraryCheckboxes << checkbox;
|
mLibraryCheckboxes << checkbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &ProjectFileDialog::accept);
|
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &ProjectFileDialog::ok);
|
||||||
connect(mUI.mBtnBrowseBuildDir, &QPushButton::clicked, this, &ProjectFileDialog::browseBuildDir);
|
connect(mUI.mBtnBrowseBuildDir, &QPushButton::clicked, this, &ProjectFileDialog::browseBuildDir);
|
||||||
connect(mUI.mBtnClearImportProject, &QPushButton::clicked, this, &ProjectFileDialog::clearImportProject);
|
connect(mUI.mBtnClearImportProject, &QPushButton::clicked, this, &ProjectFileDialog::clearImportProject);
|
||||||
connect(mUI.mBtnBrowseImportProject, &QPushButton::clicked, this, &ProjectFileDialog::browseImportProject);
|
connect(mUI.mBtnBrowseImportProject, &QPushButton::clicked, this, &ProjectFileDialog::browseImportProject);
|
||||||
|
@ -107,6 +107,8 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
connect(mUI.mBtnIncludeDown, &QPushButton::clicked, this, &ProjectFileDialog::moveIncludePathDown);
|
connect(mUI.mBtnIncludeDown, &QPushButton::clicked, this, &ProjectFileDialog::moveIncludePathDown);
|
||||||
connect(mUI.mBtnAddSuppression, &QPushButton::clicked, this, &ProjectFileDialog::addSuppression);
|
connect(mUI.mBtnAddSuppression, &QPushButton::clicked, this, &ProjectFileDialog::addSuppression);
|
||||||
connect(mUI.mBtnRemoveSuppression, &QPushButton::clicked, this, &ProjectFileDialog::removeSuppression);
|
connect(mUI.mBtnRemoveSuppression, &QPushButton::clicked, this, &ProjectFileDialog::removeSuppression);
|
||||||
|
|
||||||
|
loadFromProjectFile(projectFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectFileDialog::~ProjectFileDialog()
|
ProjectFileDialog::~ProjectFileDialog()
|
||||||
|
@ -155,9 +157,16 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
|
||||||
projectFile->setSuppressions(getSuppressions());
|
projectFile->setSuppressions(getSuppressions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectFileDialog::ok()
|
||||||
|
{
|
||||||
|
saveToProjectFile(mProjectFile);
|
||||||
|
mProjectFile->write();
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
QString ProjectFileDialog::getExistingDirectory(const QString &caption, bool trailingSlash)
|
QString ProjectFileDialog::getExistingDirectory(const QString &caption, bool trailingSlash)
|
||||||
{
|
{
|
||||||
const QFileInfo inf(mFilePath);
|
const QFileInfo inf(mProjectFile->getFilename());
|
||||||
const QString rootpath = inf.absolutePath();
|
const QString rootpath = inf.absolutePath();
|
||||||
QString selectedDir = QFileDialog::getExistingDirectory(this,
|
QString selectedDir = QFileDialog::getExistingDirectory(this,
|
||||||
caption,
|
caption,
|
||||||
|
@ -211,7 +220,7 @@ void ProjectFileDialog::clearImportProject()
|
||||||
|
|
||||||
void ProjectFileDialog::browseImportProject()
|
void ProjectFileDialog::browseImportProject()
|
||||||
{
|
{
|
||||||
const QFileInfo inf(mFilePath);
|
const QFileInfo inf(mProjectFile->getFilename());
|
||||||
const QDir &dir = inf.absoluteDir();
|
const QDir &dir = inf.absoluteDir();
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Import Project"),
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Import Project"),
|
||||||
dir.canonicalPath(),
|
dir.canonicalPath(),
|
||||||
|
|
|
@ -40,13 +40,13 @@ class ProjectFile;
|
||||||
class ProjectFileDialog : public QDialog {
|
class ProjectFileDialog : public QDialog {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ProjectFileDialog(const QString &path, QWidget *parent = 0);
|
ProjectFileDialog(ProjectFile *projectFile, QWidget *parent = 0);
|
||||||
virtual ~ProjectFileDialog();
|
virtual ~ProjectFileDialog();
|
||||||
|
|
||||||
|
private:
|
||||||
void loadFromProjectFile(const ProjectFile *projectFile);
|
void loadFromProjectFile(const ProjectFile *projectFile);
|
||||||
void saveToProjectFile(ProjectFile *projectFile) const;
|
void saveToProjectFile(ProjectFile *projectFile) const;
|
||||||
|
|
||||||
private:
|
|
||||||
/** Enable and disable widgets in the 'Paths and Defines' tab */
|
/** Enable and disable widgets in the 'Paths and Defines' tab */
|
||||||
void updatePathsAndDefines();
|
void updatePathsAndDefines();
|
||||||
|
|
||||||
|
@ -146,6 +146,9 @@ private:
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
|
|
||||||
|
/** ok button pressed, save changes and accept */
|
||||||
|
void ok();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Browse for build dir.
|
* @brief Browse for build dir.
|
||||||
*/
|
*/
|
||||||
|
@ -263,7 +266,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* @brief Projectfile path.
|
* @brief Projectfile path.
|
||||||
*/
|
*/
|
||||||
QString mFilePath;
|
ProjectFile *mProjectFile;
|
||||||
|
|
||||||
/** @brief Library checkboxes */
|
/** @brief Library checkboxes */
|
||||||
QList<QCheckBox*> mLibraryCheckboxes;
|
QList<QCheckBox*> mLibraryCheckboxes;
|
||||||
|
|
Loading…
Reference in New Issue