GUI: Implement writing project file data to disk from dialog.
This commit implements writing data in the project file dialog back to project file.
This commit is contained in:
parent
34d0ff73d8
commit
9d0c080697
|
@ -1,9 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!-- cppcheck project file -->
|
||||
|
||||
<project version="1">
|
||||
<includedir>
|
||||
<dir name="../lib" />
|
||||
</includedir>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="1">
|
||||
<includedir>
|
||||
<dir name="../lib"/>
|
||||
<dir name="C:\"/>
|
||||
<dir name=""/>
|
||||
</includedir>
|
||||
<defines>
|
||||
<define name="WIN32"/>
|
||||
<define name="UNICODE"/>
|
||||
</defines>
|
||||
</project>
|
||||
|
|
|
@ -19,10 +19,13 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <QFile>
|
||||
#include "projectfile.h"
|
||||
|
||||
static const char ProjectElementName[] = "project";
|
||||
static const char ProjectVersionAttrib[] = "version";
|
||||
static const char ProjectFileVersion[] = "1";
|
||||
static const char IncludDirElementName[] = "includedir";
|
||||
static const char DirElementName[] = "dir";
|
||||
static const char DirNameAttrib[] = "name";
|
||||
|
@ -185,3 +188,55 @@ void ProjectFile::ReadDefines(QXmlStreamReader &reader)
|
|||
}
|
||||
while (!allRead);
|
||||
}
|
||||
|
||||
void ProjectFile::SetIncludes(QStringList includes)
|
||||
{
|
||||
mIncludeDirs = includes;
|
||||
}
|
||||
|
||||
void ProjectFile::SetDefines(QStringList defines)
|
||||
{
|
||||
mDefines = defines;
|
||||
}
|
||||
|
||||
bool ProjectFile::Write(const QString &filename)
|
||||
{
|
||||
QFile file(mFilename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument("1.0");
|
||||
xmlWriter.writeStartElement(ProjectElementName);
|
||||
xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);
|
||||
|
||||
if (!mIncludeDirs.isEmpty())
|
||||
{
|
||||
xmlWriter.writeStartElement(IncludDirElementName);
|
||||
QString incdir;
|
||||
foreach(incdir, mIncludeDirs)
|
||||
{
|
||||
xmlWriter.writeStartElement(DirElementName);
|
||||
xmlWriter.writeAttribute(DirNameAttrib, incdir);
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
|
||||
if (!mDefines.isEmpty())
|
||||
{
|
||||
xmlWriter.writeStartElement(DefinesElementName);
|
||||
QString define;
|
||||
foreach(define, mDefines)
|
||||
{
|
||||
xmlWriter.writeStartElement(DefineName);
|
||||
xmlWriter.writeAttribute(DefineNameAttrib, define);
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
xmlWriter.writeEndElement();
|
||||
}
|
||||
xmlWriter.writeEndDocument();
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,24 @@ public:
|
|||
*/
|
||||
QStringList GetDefines() const;
|
||||
|
||||
/**
|
||||
* @brief Set list of includes.
|
||||
* @param includes List of defines.
|
||||
*/
|
||||
void SetIncludes(QStringList includes);
|
||||
|
||||
/**
|
||||
* @brief Set list of defines.
|
||||
* @param defines List of defines.
|
||||
*/
|
||||
void SetDefines(QStringList defines);
|
||||
|
||||
/**
|
||||
* @brief Write project file (to disk).
|
||||
* @param filename Filename to use.
|
||||
*/
|
||||
bool Write(const QString &filename = QString());
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Read list of include directories from XML.
|
||||
|
|
|
@ -50,4 +50,23 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
|||
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)
|
||||
{
|
||||
if (result == QDialog::Accepted)
|
||||
{
|
||||
UpdateProjectFileData();
|
||||
mPFile->Write();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectFileDialog::UpdateProjectFileData()
|
||||
{
|
||||
QStringList includes = mUI.mEditIncludePaths->text().split(";");
|
||||
mPFile->SetIncludes(includes);
|
||||
|
||||
QStringList defines = mUI.mEditDefines->text().split(";");
|
||||
mPFile->SetDefines(defines);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,12 @@ class ProjectFileDialog : public QDialog
|
|||
public:
|
||||
ProjectFileDialog(const QString &path, QWidget *parent = 0);
|
||||
|
||||
protected slots:
|
||||
void DialogFinished(int result);
|
||||
|
||||
protected:
|
||||
void UpdateProjectFileData();
|
||||
|
||||
private:
|
||||
Ui::ProjectFile mUI;
|
||||
QString mFileName;
|
||||
|
|
Loading…
Reference in New Issue