GUI: Read include directories from project file.

This commit is contained in:
Kimmo Varis 2009-07-04 01:38:47 +03:00
parent 3132041de3
commit 462117485d
3 changed files with 81 additions and 0 deletions

View File

@ -293,6 +293,13 @@ Settings MainWindow::GetCppcheckSettings()
{ {
result.addAutoAllocClass(classname.toStdString()); result.addAutoAllocClass(classname.toStdString());
} }
QStringList dirs = pfile.GetIncludeDirs();
QString dir;
foreach(dir, dirs)
{
result._includePaths.push_back(dir.toStdString());
}
} }
} }

View File

@ -26,6 +26,9 @@ static const char ProjectElementName[] = "project";
static const char AllocElementName[] = "autodealloc"; static const char AllocElementName[] = "autodealloc";
static const char ClassElementName[] = "class"; static const char ClassElementName[] = "class";
static const char ClassNameAttrib[] = "name"; static const char ClassNameAttrib[] = "name";
static const char IncludDirElementName[] = "includedir";
static const char DirElementName[] = "dir";
static const char DirNameAttrib[] = "name";
ProjectFile::ProjectFile(QObject *parent) : ProjectFile::ProjectFile(QObject *parent) :
QObject(parent) QObject(parent)
@ -60,6 +63,9 @@ bool ProjectFile::Read(const QString &filename)
// Find allocelement from inside project element // Find allocelement from inside project element
if (insideProject && xmlReader.name() == AllocElementName) if (insideProject && xmlReader.name() == AllocElementName)
ReadAutoAllocClasses(xmlReader); ReadAutoAllocClasses(xmlReader);
if (insideProject && xmlReader.name() == IncludDirElementName)
ReadIncludeDirs(xmlReader);
break; break;
case QXmlStreamReader::EndElement: case QXmlStreamReader::EndElement:
@ -90,6 +96,11 @@ QStringList ProjectFile::GetDeAllocatedClasses() const
return mDeAllocatedClasses; return mDeAllocatedClasses;
} }
QStringList ProjectFile::GetIncludeDirs() const
{
return mIncludeDirs;
}
void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader) void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader)
{ {
QXmlStreamReader::TokenType type; QXmlStreamReader::TokenType type;
@ -131,3 +142,45 @@ void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader)
} }
while (!allRead); 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);
}

View File

@ -49,9 +49,25 @@ public:
*/ */
QStringList GetDeAllocatedClasses() const; QStringList GetDeAllocatedClasses() const;
/**
* @brief Get list of include directories.
* @return list of directories.
*/
QStringList GetIncludeDirs() const;
protected: protected:
/**
* @brief Read list of automatically deallocated classes from XML.
* @param reader XML stream reader.
*/
void ReadAutoAllocClasses(QXmlStreamReader &reader); void ReadAutoAllocClasses(QXmlStreamReader &reader);
/**
* @brief Read list of include directories from XML.
* @param reader XML stream reader.
*/
void ReadIncludeDirs(QXmlStreamReader &reader);
private: private:
/** /**
@ -63,6 +79,11 @@ private:
* @brief List of automatically deallocated classes. * @brief List of automatically deallocated classes.
*/ */
QStringList mDeAllocatedClasses; QStringList mDeAllocatedClasses;
/**
* @brief List of include directories used to search include files.
*/
QStringList mIncludeDirs;
}; };
#endif // PROJECT_FILE_H #endif // PROJECT_FILE_H