GUI: Add new optional root-element to project file.

Add support for new root-element to project file. This element
defines project root directory if given. If not given then project
root is directory where the project file is located.
This commit is contained in:
Kimmo Varis 2010-08-20 23:58:00 +03:00
parent 5a65f4d55d
commit 1e7694d56b
3 changed files with 57 additions and 1 deletions

View File

@ -35,6 +35,8 @@ static const char DefineNameAttrib[] = "name";
static const char PathsElementName[] = "paths"; static const char PathsElementName[] = "paths";
static const char PathName[] = "dir"; static const char PathName[] = "dir";
static const char PathNameAttrib[] = "name"; static const char PathNameAttrib[] = "name";
static const char RootPathName[] = "root";
static const char RootPathNameAttrib[] = "name";
ProjectFile::ProjectFile(QObject *parent) : ProjectFile::ProjectFile(QObject *parent) :
QObject(parent) QObject(parent)
@ -69,6 +71,10 @@ bool ProjectFile::Read(const QString &filename)
insideProject = true; insideProject = true;
projectTagFound = true; projectTagFound = true;
} }
// Read root path from inside project element
if (insideProject && xmlReader.name() == RootPathName)
ReadRootPath(xmlReader);
// Find paths to check from inside project element // Find paths to check from inside project element
if (insideProject && xmlReader.name() == PathsElementName) if (insideProject && xmlReader.name() == PathsElementName)
ReadCheckPaths(xmlReader); ReadCheckPaths(xmlReader);
@ -124,6 +130,14 @@ QStringList ProjectFile::GetCheckPaths() const
return mPaths; return mPaths;
} }
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
{
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", RootPathNameAttrib).toString();
if (!name.isEmpty())
mRootPath = name;
}
void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader) void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader)
{ {
QXmlStreamReader::TokenType type; QXmlStreamReader::TokenType type;
@ -279,6 +293,13 @@ bool ProjectFile::Write(const QString &filename)
xmlWriter.writeStartElement(ProjectElementName); xmlWriter.writeStartElement(ProjectElementName);
xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion); xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion);
if (!mRootPath.isEmpty())
{
xmlWriter.writeStartElement(RootPathName);
xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath);
xmlWriter.writeEndElement();
}
if (!mIncludeDirs.isEmpty()) if (!mIncludeDirs.isEmpty())
{ {
xmlWriter.writeStartElement(IncludDirElementName); xmlWriter.writeStartElement(IncludDirElementName);

View File

@ -47,6 +47,15 @@ public:
*/ */
bool Read(const QString &filename = QString()); bool Read(const QString &filename = QString());
/**
* @brief Get project root path.
* @return project root path.
*/
QString GetRootPath() const
{
return mRootPath;
}
/** /**
* @brief Get list of include directories. * @brief Get list of include directories.
* @return list of directories. * @return list of directories.
@ -65,6 +74,15 @@ public:
*/ */
QStringList GetCheckPaths() const; QStringList GetCheckPaths() const;
/**
* @brief Set project root path.
* @param rootpath new project root path.
*/
void SetRootPath(const QString &rootpath)
{
mRootPath = rootpath;
}
/** /**
* @brief Set list of includes. * @brief Set list of includes.
* @param includes List of defines. * @param includes List of defines.
@ -99,6 +117,13 @@ public:
} }
protected: protected:
/**
* @brief Read optional root path from XML.
* @param reader XML stream reader.
*/
void ReadRootPath(QXmlStreamReader &reader);
/** /**
* @brief Read list of include directories from XML. * @brief Read list of include directories from XML.
* @param reader XML stream reader. * @param reader XML stream reader.
@ -124,6 +149,14 @@ private:
*/ */
QString mFilename; QString mFilename;
/**
* @brief Root path (optional) for the project.
* This is the project root path. If it is present then all relative paths in
* the project file are relative to this path. Otherwise paths are relative
* to project file's path.
*/
QString mRootPath;
/** /**
* @brief List of include directories used to search include files. * @brief List of include directories used to search include files.
*/ */

View File

@ -13,10 +13,12 @@ program. The format is:
<?xml version="1.0"?> <?xml version="1.0"?>
<project version="1"> <project version="1">
<root name="c:/projects/cppcheck/" />
<paths> <paths>
<dir name="c:/projects/cppcheck/src/" /> <dir name="lib/" />
</paths> </paths>
<includedir> <includedir>
<dir name="lib/" />
<dir name="c:/projects/framework/" /> <dir name="c:/projects/framework/" />
<dir name="c:/Program Files/Visual Studio 8/VC/include/" /> <dir name="c:/Program Files/Visual Studio 8/VC/include/" />
</includedir> </includedir>