From 1e7694d56b2335c8a6bb02962e71f7576501f024 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Fri, 20 Aug 2010 23:58:00 +0300 Subject: [PATCH] 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. --- gui/projectfile.cpp | 21 +++++++++++++++++++++ gui/projectfile.h | 33 +++++++++++++++++++++++++++++++++ gui/projectfile.txt | 4 +++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 857960cc4..d6c6e5037 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -35,6 +35,8 @@ static const char DefineNameAttrib[] = "name"; static const char PathsElementName[] = "paths"; static const char PathName[] = "dir"; static const char PathNameAttrib[] = "name"; +static const char RootPathName[] = "root"; +static const char RootPathNameAttrib[] = "name"; ProjectFile::ProjectFile(QObject *parent) : QObject(parent) @@ -69,6 +71,10 @@ bool ProjectFile::Read(const QString &filename) insideProject = 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 if (insideProject && xmlReader.name() == PathsElementName) ReadCheckPaths(xmlReader); @@ -124,6 +130,14 @@ QStringList ProjectFile::GetCheckPaths() const 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) { QXmlStreamReader::TokenType type; @@ -279,6 +293,13 @@ bool ProjectFile::Write(const QString &filename) xmlWriter.writeStartElement(ProjectElementName); xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion); + if (!mRootPath.isEmpty()) + { + xmlWriter.writeStartElement(RootPathName); + xmlWriter.writeAttribute(RootPathNameAttrib, mRootPath); + xmlWriter.writeEndElement(); + } + if (!mIncludeDirs.isEmpty()) { xmlWriter.writeStartElement(IncludDirElementName); diff --git a/gui/projectfile.h b/gui/projectfile.h index be69a1b2b..2243a7c20 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -47,6 +47,15 @@ public: */ 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. * @return list of directories. @@ -65,6 +74,15 @@ public: */ 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. * @param includes List of defines. @@ -99,6 +117,13 @@ public: } 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. * @param reader XML stream reader. @@ -124,6 +149,14 @@ private: */ 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. */ diff --git a/gui/projectfile.txt b/gui/projectfile.txt index 22944a97c..66bd67025 100644 --- a/gui/projectfile.txt +++ b/gui/projectfile.txt @@ -13,10 +13,12 @@ program. The format is: + - + +