From 9698387d3adf7c0150abec65b1af4d27e8e95c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 29 Dec 2013 18:06:31 +0100 Subject: [PATCH] GUI: Add libraries setting to project --- gui/mainwindow.cpp | 7 ++++ gui/project.cpp | 2 ++ gui/projectfile.cpp | 69 +++++++++++++++++++++++++++++++++++++++ gui/projectfile.h | 23 +++++++++++++ gui/projectfile.ui | 39 ++++++++++++++++++++++ gui/projectfiledialog.cpp | 18 ++++++++++ gui/projectfiledialog.h | 12 +++++++ 7 files changed, 170 insertions(+) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 4cc329d6a..0ab92ba83 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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; diff --git a/gui/project.cpp b/gui/project.cpp index 25a625d1f..75f53daa2 100644 --- a/gui/project.cpp +++ b/gui/project.cpp @@ -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) { diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 972346c60..96df1da3a 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -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; diff --git a/gui/projectfile.h b/gui/projectfile.h index 6c9305e76..fa9a1dc66 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -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 diff --git a/gui/projectfile.ui b/gui/projectfile.ui index 91e11de30..8d6f9100a 100644 --- a/gui/projectfile.ui +++ b/gui/projectfile.ui @@ -58,6 +58,45 @@ + + + + + + Libraries: + + + + + + + gtk + + + + + + + posix + + + + + + + qt + + + + + + + windows + + + + + diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index ad292451f..15fbf28ae 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -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); diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h index dbf48bbef..e760e51e9 100644 --- a/gui/projectfiledialog.h +++ b/gui/projectfiledialog.h @@ -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.