GUI: Add check paths to project file.

Add new element containing paths to check into the project file. This
is for growing project files to real project files that can be loaded
and selected from the GUI. And decoupling project files from the
directory they reside. So you can put project file in any directory,
load it and it checks paths listed.
This commit is contained in:
Kimmo Varis 2010-08-14 18:42:37 +03:00
parent 0d8b74e538
commit a82edf5278
3 changed files with 98 additions and 0 deletions

View File

@ -32,6 +32,9 @@ static const char DirNameAttrib[] = "name";
static const char DefinesElementName[] = "defines";
static const char DefineName[] = "define";
static const char DefineNameAttrib[] = "name";
static const char PathsElementName[] = "paths";
static const char PathName[] = "dir";
static const char PathNameAttrib[] = "name";
ProjectFile::ProjectFile(QObject *parent) :
QObject(parent)
@ -66,6 +69,9 @@ bool ProjectFile::Read(const QString &filename)
insideProject = true;
projectTagFound = true;
}
// Find paths to check from inside project element
if (insideProject && xmlReader.name() == PathsElementName)
ReadCheckPaths(xmlReader);
// Find include directory from inside project element
if (insideProject && xmlReader.name() == IncludDirElementName)
@ -113,6 +119,11 @@ QStringList ProjectFile::GetDefines() const
return mDefines;
}
QStringList ProjectFile::GetCheckPaths() const
{
return mPaths;
}
void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader)
{
QXmlStreamReader::TokenType type;
@ -196,6 +207,48 @@ void ProjectFile::ReadDefines(QXmlStreamReader &reader)
while (!allRead);
}
void ProjectFile::ReadCheckPaths(QXmlStreamReader &reader)
{
QXmlStreamReader::TokenType type;
bool allRead = false;
do
{
type = reader.readNext();
switch (type)
{
case QXmlStreamReader::StartElement:
// Read dir-elements
if (reader.name().toString() == PathName)
{
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", PathNameAttrib).toString();
if (!name.isEmpty())
mPaths << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == PathsElementName)
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);
}
void ProjectFile::SetIncludes(QStringList includes)
{
mIncludeDirs = includes;
@ -206,6 +259,11 @@ void ProjectFile::SetDefines(QStringList defines)
mDefines = defines;
}
void ProjectFile::SetCheckPaths(QStringList paths)
{
mPaths = paths;
}
bool ProjectFile::Write(const QString &filename)
{
if (!filename.isEmpty())
@ -246,6 +304,20 @@ bool ProjectFile::Write(const QString &filename)
}
xmlWriter.writeEndElement();
}
if (!mPaths.isEmpty())
{
xmlWriter.writeStartElement(PathsElementName);
QString path;
foreach(path, mPaths)
{
xmlWriter.writeStartElement(PathName);
xmlWriter.writeAttribute(PathNameAttrib, path);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
xmlWriter.writeEndDocument();
file.close();
return true;

View File

@ -59,6 +59,12 @@ public:
*/
QStringList GetDefines() const;
/**
* @brief Get list of paths to check.
* @return list of paths.
*/
QStringList GetCheckPaths() const;
/**
* @brief Set list of includes.
* @param includes List of defines.
@ -71,6 +77,12 @@ public:
*/
void SetDefines(QStringList defines);
/**
* @brief Set list of paths to check.
* @param defines List of paths.
*/
void SetCheckPaths(QStringList paths);
/**
* @brief Write project file (to disk).
* @param filename Filename to use.
@ -99,6 +111,12 @@ protected:
*/
void ReadDefines(QXmlStreamReader &reader);
/**
* @brief Read list paths to check.
* @param reader XML stream reader.
*/
void ReadCheckPaths(QXmlStreamReader &reader);
private:
/**
@ -115,6 +133,11 @@ private:
* @brief List of defines.
*/
QStringList mDefines;
/**
* @brief List of paths to check.
*/
QStringList mPaths;
};
/// @}
#endif // PROJECT_FILE_H

View File

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