Fixed #1698 (Add define support to GUI)

This commit is contained in:
Robert Reif 2010-05-20 07:22:19 +02:00 committed by Daniel Marjamäki
parent 5dfbb38dc9
commit 1207531c21
4 changed files with 84 additions and 0 deletions

View File

@ -332,6 +332,15 @@ Settings MainWindow::GetCppcheckSettings()
incdir += "/";
result._includePaths.push_back(incdir.toStdString());
}
QStringList defines = pfile.GetDefines();
QString define;
foreach(define, defines)
{
if (!result.userDefines.empty())
result.userDefines += ";";
result.userDefines += define.toStdString();
}
}
}

View File

@ -29,6 +29,9 @@ static const char ClassNameAttrib[] = "name";
static const char IncludDirElementName[] = "includedir";
static const char DirElementName[] = "dir";
static const char DirNameAttrib[] = "name";
static const char DefinesElementName[] = "defines";
static const char DefineName[] = "define";
static const char DefineNameAttrib[] = "name";
ProjectFile::ProjectFile(QObject *parent) :
QObject(parent)
@ -66,6 +69,10 @@ bool ProjectFile::Read(const QString &filename)
if (insideProject && xmlReader.name() == IncludDirElementName)
ReadIncludeDirs(xmlReader);
if (insideProject && xmlReader.name() == DefinesElementName)
ReadDefines(xmlReader);
break;
case QXmlStreamReader::EndElement:
@ -101,6 +108,11 @@ QStringList ProjectFile::GetIncludeDirs() const
return mIncludeDirs;
}
QStringList ProjectFile::GetDefines() const
{
return mDefines;
}
void ProjectFile::ReadAutoAllocClasses(QXmlStreamReader &reader)
{
QXmlStreamReader::TokenType type;
@ -184,3 +196,44 @@ void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader)
}
while (!allRead);
}
void ProjectFile::ReadDefines(QXmlStreamReader &reader)
{
QXmlStreamReader::TokenType type;
bool allRead = false;
do
{
type = reader.readNext();
switch (type)
{
case QXmlStreamReader::StartElement:
// Read define-elements
if (reader.name().toString() == DefineName)
{
QXmlStreamAttributes attribs = reader.attributes();
QString name = attribs.value("", DefineNameAttrib).toString();
if (!name.isEmpty())
mDefines << name;
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == DefinesElementName)
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

@ -59,6 +59,12 @@ public:
*/
QStringList GetIncludeDirs() const;
/**
* @brief Get list of defines.
* @return list of defines.
*/
QStringList GetDefines() const;
protected:
/**
* @brief Read list of automatically deallocated classes from XML.
@ -72,6 +78,12 @@ protected:
*/
void ReadIncludeDirs(QXmlStreamReader &reader);
/**
* @brief Read list of defines from XML.
* @param reader XML stream reader.
*/
void ReadDefines(QXmlStreamReader &reader);
private:
/**
@ -88,6 +100,11 @@ private:
* @brief List of include directories used to search include files.
*/
QStringList mIncludeDirs;
/**
* @brief List of defines.
*/
QStringList mDefines;
};
/// @}
#endif // PROJECT_FILE_H

View File

@ -22,6 +22,11 @@ program. The format is:
<dir name="c:/projects/framework/" />
<dir name="c:/Program Files/Visual Studio 8/VC/include/" />
</includedir>
<defines>
<define name="__cplusplus" />
<define name="_MSC_VER=1400" />
<define name="_WIN32" />
</defines>
</project>
See also gui.cppcheck file in gui-directory of cppcheck sources.