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