GUI: Add libraries setting to project

This commit is contained in:
Daniel Marjamäki 2013-12-29 18:06:31 +01:00
parent 41e4194573
commit 9698387d3a
7 changed files with 170 additions and 0 deletions

View File

@ -530,6 +530,13 @@ Settings MainWindow::GetCppcheckSettings()
result.userDefines += define.toStdString();
}
QStringList libraries = pfile->GetLibraries();
foreach(QString library, libraries) {
const QString applicationFilePath = QCoreApplication::applicationFilePath();
if (!result.library.load(applicationFilePath.toLatin1(), (library+".cfg").toLatin1()))
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(library));
}
// Only check the given -D configuration
if (!defines.isEmpty())
result._maxConfigs = 1;

View File

@ -95,6 +95,7 @@ bool Project::Edit()
dlg.SetPaths(paths);
QStringList ignorepaths = mPFile->GetExcludedPaths();
dlg.SetExcludedPaths(ignorepaths);
dlg.SetLibraries(mPFile->GetLibraries());
int rv = dlg.exec();
if (rv == QDialog::Accepted) {
@ -108,6 +109,7 @@ bool Project::Edit()
mPFile->SetCheckPaths(paths);
QStringList excludedpaths = dlg.GetExcludedPaths();
mPFile->SetExcludedPaths(excludedpaths);
mPFile->SetLibraries(dlg.GetLibraries());
bool writeSuccess = mPFile->Write();
if (!writeSuccess) {

View File

@ -44,6 +44,8 @@ static const char IgnorePathNameAttrib[] = "name";
static const char ExcludeElementName[] = "exclude";
static const char ExcludePathName[] = "path";
static const char ExcludePathNameAttrib[] = "name";
static const char LibrariesElementName[] = "libraries";
static const char LibraryElementName[] = "library";
ProjectFile::ProjectFile(QObject *parent) :
QObject(parent)
@ -100,6 +102,10 @@ bool ProjectFile::Read(const QString &filename)
if (insideProject && xmlReader.name() == IgnoreElementName)
ReadExcludes(xmlReader);
// Find libraries list from insid project element
if (insideProject && xmlReader.name() == LibrariesElementName)
ReadLibraries(xmlReader);
break;
case QXmlStreamReader::EndElement:
@ -160,6 +166,15 @@ QStringList ProjectFile::GetExcludedPaths() const
return paths;
}
QStringList ProjectFile::GetLibraries() const
{
QStringList libraries;
foreach(QString library, mLibraries) {
libraries << library;
}
return libraries;
}
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
{
QXmlStreamAttributes attribs = reader.attributes();
@ -327,6 +342,45 @@ void ProjectFile::ReadExcludes(QXmlStreamReader &reader)
} while (!allRead);
}
void ProjectFile::ReadLibraries(QXmlStreamReader &reader)
{
QXmlStreamReader::TokenType type;
bool allRead = false;
do {
type = reader.readNext();
switch (type) {
case QXmlStreamReader::StartElement:
// Read library-elements
if (reader.name().toString() == LibraryElementName) {
type = reader.readNext();
if (type == QXmlStreamReader::Characters) {
QString library = reader.text().toString();
mLibraries << library;
}
}
break;
case QXmlStreamReader::EndElement:
if (reader.name().toString() == LibrariesElementName)
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(const QStringList &includes)
{
mIncludeDirs = includes;
@ -347,6 +401,11 @@ void ProjectFile::SetExcludedPaths(const QStringList &paths)
mExcludedPaths = paths;
}
void ProjectFile::SetLibraries(const QStringList &libraries)
{
mLibraries = libraries;
}
bool ProjectFile::Write(const QString &filename)
{
if (!filename.isEmpty())
@ -408,6 +467,16 @@ bool ProjectFile::Write(const QString &filename)
xmlWriter.writeEndElement();
}
if (!mLibraries.isEmpty()) {
xmlWriter.writeStartElement(LibrariesElementName);
foreach(QString library, mLibraries) {
xmlWriter.writeStartElement(LibraryElementName);
xmlWriter.writeCharacters(library);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
xmlWriter.writeEndDocument();
file.close();
return true;

View File

@ -78,6 +78,12 @@ public:
*/
QStringList GetExcludedPaths() const;
/**
* @brief Get list libraries.
* @return list of libraries.
*/
QStringList GetLibraries() const;
/**
* @brief Get filename for the project file.
* @return file name.
@ -118,6 +124,12 @@ public:
*/
void SetExcludedPaths(const QStringList &paths);
/**
* @brief Set list of libraries.
* @param paths List of libraries.
*/
void SetLibraries(const QStringList &libraries);
/**
* @brief Write project file (to disk).
* @param filename Filename to use.
@ -164,6 +176,12 @@ protected:
*/
void ReadExcludes(QXmlStreamReader &reader);
/**
* @brief Read list of libraries.
* @param reader XML stream reader.
*/
void ReadLibraries(QXmlStreamReader &reader);
private:
/**
@ -198,6 +216,11 @@ private:
* @brief Paths excluded from the check.
*/
QStringList mExcludedPaths;
/**
* @brief List of libraries.
*/
QStringList mLibraries;
};
/// @}
#endif // PROJECT_FILE_H

View File

@ -58,6 +58,45 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Libraries:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mChkboxGtk">
<property name="text">
<string>gtk</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mChkboxPosix">
<property name="text">
<string>posix</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mChkboxQt">
<property name="text">
<string>qt</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="mChkboxWindows">
<property name="text">
<string>windows</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>

View File

@ -160,6 +160,17 @@ QStringList ProjectFileDialog::GetExcludedPaths() const
return paths;
}
QStringList ProjectFileDialog::GetLibraries() const
{
QStringList libraries;
const QCheckBox *c[] = { mUI.mChkboxGtk, mUI.mChkboxPosix, mUI.mChkboxQt, mUI.mChkboxWindows };
for (unsigned int i = 0; i < sizeof(c) / sizeof(c[0]); i++) {
if (c[i]->isChecked())
libraries << c[i]->text();
}
return libraries;
}
void ProjectFileDialog::SetRootPath(const QString &root)
{
QString newroot = QDir::toNativeSeparators(root);
@ -201,6 +212,13 @@ void ProjectFileDialog::SetExcludedPaths(const QStringList &paths)
}
}
void ProjectFileDialog::SetLibraries(const QStringList &libraries)
{
QCheckBox *c[] = { mUI.mChkboxGtk, mUI.mChkboxPosix, mUI.mChkboxQt, mUI.mChkboxWindows };
for (unsigned int i = 0; i < sizeof(c) / sizeof(c[0]); i++)
c[i]->setChecked(libraries.contains(c[i]->text()));
}
void ProjectFileDialog::AddIncludeDir()
{
const QFileInfo inf(mFilePath);

View File

@ -70,6 +70,12 @@ public:
*/
QStringList GetExcludedPaths() const;
/**
* @brief Return selected libraries from the dialog control.
* @return List of libraries.
*/
QStringList GetLibraries() const;
/**
* @brief Set project root path to dialog control.
* @param root Project root path to set to dialog control.
@ -100,6 +106,12 @@ public:
*/
void SetExcludedPaths(const QStringList &paths);
/**
* @brief Set libraries to dialog control.
* @param paths List of libraries to set to dialog control.
*/
void SetLibraries(const QStringList &libraries);
protected slots:
/**
* @brief Browse for include directory.