From 462117485debb939c23225c412ef61609f754aee Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 4 Jul 2009 01:38:47 +0300 Subject: [PATCH] GUI: Read include directories from project file. --- gui/mainwindow.cpp | 7 ++++++ gui/projectfile.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++ gui/projectfile.h | 21 ++++++++++++++++++ 3 files changed, 81 insertions(+) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b201dfa28..a21c6e9f3 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -293,6 +293,13 @@ Settings MainWindow::GetCppcheckSettings() { result.addAutoAllocClass(classname.toStdString()); } + + QStringList dirs = pfile.GetIncludeDirs(); + QString dir; + foreach(dir, dirs) + { + result._includePaths.push_back(dir.toStdString()); + } } } diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index d9711a6dc..bee7723b3 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -26,6 +26,9 @@ static const char ProjectElementName[] = "project"; static const char AllocElementName[] = "autodealloc"; static const char ClassElementName[] = "class"; static const char ClassNameAttrib[] = "name"; +static const char IncludDirElementName[] = "includedir"; +static const char DirElementName[] = "dir"; +static const char DirNameAttrib[] = "name"; ProjectFile::ProjectFile(QObject *parent) : QObject(parent) @@ -60,6 +63,9 @@ bool ProjectFile::Read(const QString &filename) // Find allocelement from inside project element if (insideProject && xmlReader.name() == AllocElementName) ReadAutoAllocClasses(xmlReader); + + if (insideProject && xmlReader.name() == IncludDirElementName) + ReadIncludeDirs(xmlReader); break; case QXmlStreamReader::EndElement: @@ -90,6 +96,11 @@ QStringList ProjectFile::GetDeAllocatedClasses() const return mDeAllocatedClasses; } +QStringList ProjectFile::GetIncludeDirs() const +{ + return mIncludeDirs; +} + void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader) { QXmlStreamReader::TokenType type; @@ -131,3 +142,45 @@ void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader) } while (!allRead); } + +void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader) +{ + QXmlStreamReader::TokenType type; + bool allRead = false; + do + { + type = reader.readNext(); + switch (type) + { + case QXmlStreamReader::StartElement: + + // Read dir-elements + if (reader.name().toString() == DirElementName) + { + QXmlStreamAttributes attribs = reader.attributes(); + QString name = attribs.value("", DirNameAttrib).toString(); + if (!name.isEmpty()) + mIncludeDirs << name; + } + break; + + case QXmlStreamReader::EndElement: + if (reader.name().toString() == IncludDirElementName) + allRead = true; + break; + + // Not handled + case QXmlStreamReader::NoToken: + case QXmlStreamReader::Invalid: + case QXmlStreamReader::StartDocument: + case QXmlStreamReader::EndDocument: + case QXmlStreamReader::Characters: + case QXmlStreamReader::Comment: + case QXmlStreamReader::DTD: + case QXmlStreamReader::EntityReference: + case QXmlStreamReader::ProcessingInstruction: + break; + } + } + while (!allRead); +} diff --git a/gui/projectfile.h b/gui/projectfile.h index 2c132cc6c..c20e8a2a5 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -49,9 +49,25 @@ public: */ QStringList GetDeAllocatedClasses() const; + /** + * @brief Get list of include directories. + * @return list of directories. + */ + QStringList GetIncludeDirs() const; + protected: + /** + * @brief Read list of automatically deallocated classes from XML. + * @param reader XML stream reader. + */ void ReadAutoAllocClasses(QXmlStreamReader &reader); + /** + * @brief Read list of include directories from XML. + * @param reader XML stream reader. + */ + void ReadIncludeDirs(QXmlStreamReader &reader); + private: /** @@ -63,6 +79,11 @@ private: * @brief List of automatically deallocated classes. */ QStringList mDeAllocatedClasses; + + /** + * @brief List of include directories used to search include files. + */ + QStringList mIncludeDirs; }; #endif // PROJECT_FILE_H