GUI: Allow creating new project file.

Add new "New project file" item to File-menu and rename existing
"Project File" item to "Open Project File". Selecting new file
opens empty project file dialog. When the dialog is then closed
the user is asked to select a filename for the new project file.
This commit is contained in:
Kimmo Varis 2010-07-08 18:59:06 +03:00
parent 4958424adc
commit 25a9c75287
5 changed files with 430 additions and 377 deletions

View File

@ -73,7 +73,8 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="mActionProjectFile"/>
<addaction name="mActionNewProjectFile"/>
<addaction name="mActionOpenProjectFile"/>
<addaction name="mActionSave"/>
<addaction name="mActionQuit"/>
</widget>
@ -348,9 +349,14 @@
<string>Error categories</string>
</property>
</action>
<action name="mActionProjectFile">
<action name="mActionOpenProjectFile">
<property name="text">
<string>P&amp;roject File...</string>
<string>Open P&amp;roject File...</string>
</property>
</action>
<action name="mActionNewProjectFile">
<property name="text">
<string>&amp;New Project File...</string>
</property>
</action>
</widget>

View File

@ -80,7 +80,8 @@ MainWindow::MainWindow() :
connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded()));
connect(mUI.mMenuView, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu()));
connect(mUI.mActionProjectFile, SIGNAL(triggered()), this, SLOT(ShowProjectFileDialog()));
connect(mUI.mActionNewProjectFile, SIGNAL(triggered()), this, SLOT(NewProjectFileDialog()));
connect(mUI.mActionOpenProjectFile, SIGNAL(triggered()), this, SLOT(ShowProjectFileDialog()));
#ifdef WIN32
connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents()));
@ -679,3 +680,9 @@ void MainWindow::ShowProjectFileDialog()
dlg.exec();
}
}
void MainWindow::NewProjectFileDialog()
{
ProjectFileDialog dlg(QString(), this);
dlg.exec();
}

View File

@ -125,6 +125,16 @@ public slots:
*/
void Save();
/**
* @brief Slot to shown project file dialog for new project file.
*
*/
void NewProjectFileDialog();
/**
* @brief Slot to shown project file dialog for existing project file.
*
*/
void ShowProjectFileDialog();
protected slots:

View File

@ -17,16 +17,30 @@
*/
#include <QStringList>
#include <QFile>
#include <QFileDialog>
#include "projectfiledialog.h"
#include "projectfile.h"
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
: QDialog(parent)
, mFileName(path)
, mDataSaved(false)
{
mUI.setupUi(this);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(this, SIGNAL(accepted()), this, SLOT(DialogAccepted()));
mPFile = new ProjectFile(path, this);
if (QFile::exists(path))
{
ReadProjectFile();
}
}
void ProjectFileDialog::ReadProjectFile()
{
mPFile->Read();
QStringList includes = mPFile->GetIncludeDirs();
@ -48,18 +62,32 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
definestr += ";";
}
mUI.mEditDefines->setText(definestr);
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
connect(this, SIGNAL(finished(int)), this, SLOT(DialogFinished(int)));
}
void ProjectFileDialog::DialogFinished(int result)
void ProjectFileDialog::DialogAccepted()
{
if (result == QDialog::Accepted)
if (mDataSaved)
return;
UpdateProjectFileData();
if (mFileName.isEmpty())
{
const QString filter = tr("Project files (*.cppcheck);;All files(*.*)");
QString filepath = QFileDialog::getSaveFileName(this,
tr("Save Project File"),
QString(),
filter);
if (!filepath.isEmpty())
{
mPFile->Write(filepath);
}
}
else
{
UpdateProjectFileData();
mPFile->Write();
}
mDataSaved = true;
}
void ProjectFileDialog::UpdateProjectFileData()

View File

@ -36,15 +36,17 @@ public:
ProjectFileDialog(const QString &path, QWidget *parent = 0);
protected slots:
void DialogFinished(int result);
void DialogAccepted();
protected:
void ReadProjectFile();
void UpdateProjectFileData();
private:
Ui::ProjectFile mUI;
QString mFileName;
ProjectFile *mPFile;
bool mDataSaved;
};
/// @}