GUI: Add libraries setting to project
This commit is contained in:
parent
41e4194573
commit
9698387d3a
|
@ -530,6 +530,13 @@ Settings MainWindow::GetCppcheckSettings()
|
||||||
result.userDefines += define.toStdString();
|
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
|
// Only check the given -D configuration
|
||||||
if (!defines.isEmpty())
|
if (!defines.isEmpty())
|
||||||
result._maxConfigs = 1;
|
result._maxConfigs = 1;
|
||||||
|
|
|
@ -95,6 +95,7 @@ bool Project::Edit()
|
||||||
dlg.SetPaths(paths);
|
dlg.SetPaths(paths);
|
||||||
QStringList ignorepaths = mPFile->GetExcludedPaths();
|
QStringList ignorepaths = mPFile->GetExcludedPaths();
|
||||||
dlg.SetExcludedPaths(ignorepaths);
|
dlg.SetExcludedPaths(ignorepaths);
|
||||||
|
dlg.SetLibraries(mPFile->GetLibraries());
|
||||||
|
|
||||||
int rv = dlg.exec();
|
int rv = dlg.exec();
|
||||||
if (rv == QDialog::Accepted) {
|
if (rv == QDialog::Accepted) {
|
||||||
|
@ -108,6 +109,7 @@ bool Project::Edit()
|
||||||
mPFile->SetCheckPaths(paths);
|
mPFile->SetCheckPaths(paths);
|
||||||
QStringList excludedpaths = dlg.GetExcludedPaths();
|
QStringList excludedpaths = dlg.GetExcludedPaths();
|
||||||
mPFile->SetExcludedPaths(excludedpaths);
|
mPFile->SetExcludedPaths(excludedpaths);
|
||||||
|
mPFile->SetLibraries(dlg.GetLibraries());
|
||||||
|
|
||||||
bool writeSuccess = mPFile->Write();
|
bool writeSuccess = mPFile->Write();
|
||||||
if (!writeSuccess) {
|
if (!writeSuccess) {
|
||||||
|
|
|
@ -44,6 +44,8 @@ static const char IgnorePathNameAttrib[] = "name";
|
||||||
static const char ExcludeElementName[] = "exclude";
|
static const char ExcludeElementName[] = "exclude";
|
||||||
static const char ExcludePathName[] = "path";
|
static const char ExcludePathName[] = "path";
|
||||||
static const char ExcludePathNameAttrib[] = "name";
|
static const char ExcludePathNameAttrib[] = "name";
|
||||||
|
static const char LibrariesElementName[] = "libraries";
|
||||||
|
static const char LibraryElementName[] = "library";
|
||||||
|
|
||||||
ProjectFile::ProjectFile(QObject *parent) :
|
ProjectFile::ProjectFile(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
|
@ -100,6 +102,10 @@ bool ProjectFile::Read(const QString &filename)
|
||||||
if (insideProject && xmlReader.name() == IgnoreElementName)
|
if (insideProject && xmlReader.name() == IgnoreElementName)
|
||||||
ReadExcludes(xmlReader);
|
ReadExcludes(xmlReader);
|
||||||
|
|
||||||
|
// Find libraries list from insid project element
|
||||||
|
if (insideProject && xmlReader.name() == LibrariesElementName)
|
||||||
|
ReadLibraries(xmlReader);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
|
@ -160,6 +166,15 @@ QStringList ProjectFile::GetExcludedPaths() const
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ProjectFile::GetLibraries() const
|
||||||
|
{
|
||||||
|
QStringList libraries;
|
||||||
|
foreach(QString library, mLibraries) {
|
||||||
|
libraries << library;
|
||||||
|
}
|
||||||
|
return libraries;
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
|
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
|
||||||
{
|
{
|
||||||
QXmlStreamAttributes attribs = reader.attributes();
|
QXmlStreamAttributes attribs = reader.attributes();
|
||||||
|
@ -327,6 +342,45 @@ void ProjectFile::ReadExcludes(QXmlStreamReader &reader)
|
||||||
} while (!allRead);
|
} 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)
|
void ProjectFile::SetIncludes(const QStringList &includes)
|
||||||
{
|
{
|
||||||
mIncludeDirs = includes;
|
mIncludeDirs = includes;
|
||||||
|
@ -347,6 +401,11 @@ void ProjectFile::SetExcludedPaths(const QStringList &paths)
|
||||||
mExcludedPaths = paths;
|
mExcludedPaths = paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectFile::SetLibraries(const QStringList &libraries)
|
||||||
|
{
|
||||||
|
mLibraries = libraries;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectFile::Write(const QString &filename)
|
bool ProjectFile::Write(const QString &filename)
|
||||||
{
|
{
|
||||||
if (!filename.isEmpty())
|
if (!filename.isEmpty())
|
||||||
|
@ -408,6 +467,16 @@ bool ProjectFile::Write(const QString &filename)
|
||||||
xmlWriter.writeEndElement();
|
xmlWriter.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mLibraries.isEmpty()) {
|
||||||
|
xmlWriter.writeStartElement(LibrariesElementName);
|
||||||
|
foreach(QString library, mLibraries) {
|
||||||
|
xmlWriter.writeStartElement(LibraryElementName);
|
||||||
|
xmlWriter.writeCharacters(library);
|
||||||
|
xmlWriter.writeEndElement();
|
||||||
|
}
|
||||||
|
xmlWriter.writeEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
xmlWriter.writeEndDocument();
|
xmlWriter.writeEndDocument();
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -78,6 +78,12 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList GetExcludedPaths() const;
|
QStringList GetExcludedPaths() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get list libraries.
|
||||||
|
* @return list of libraries.
|
||||||
|
*/
|
||||||
|
QStringList GetLibraries() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get filename for the project file.
|
* @brief Get filename for the project file.
|
||||||
* @return file name.
|
* @return file name.
|
||||||
|
@ -118,6 +124,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetExcludedPaths(const QStringList &paths);
|
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).
|
* @brief Write project file (to disk).
|
||||||
* @param filename Filename to use.
|
* @param filename Filename to use.
|
||||||
|
@ -164,6 +176,12 @@ protected:
|
||||||
*/
|
*/
|
||||||
void ReadExcludes(QXmlStreamReader &reader);
|
void ReadExcludes(QXmlStreamReader &reader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read list of libraries.
|
||||||
|
* @param reader XML stream reader.
|
||||||
|
*/
|
||||||
|
void ReadLibraries(QXmlStreamReader &reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,6 +216,11 @@ private:
|
||||||
* @brief Paths excluded from the check.
|
* @brief Paths excluded from the check.
|
||||||
*/
|
*/
|
||||||
QStringList mExcludedPaths;
|
QStringList mExcludedPaths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief List of libraries.
|
||||||
|
*/
|
||||||
|
QStringList mLibraries;
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
#endif // PROJECT_FILE_H
|
#endif // PROJECT_FILE_H
|
||||||
|
|
|
@ -58,6 +58,45 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -160,6 +160,17 @@ QStringList ProjectFileDialog::GetExcludedPaths() const
|
||||||
return paths;
|
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)
|
void ProjectFileDialog::SetRootPath(const QString &root)
|
||||||
{
|
{
|
||||||
QString newroot = QDir::toNativeSeparators(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()
|
void ProjectFileDialog::AddIncludeDir()
|
||||||
{
|
{
|
||||||
const QFileInfo inf(mFilePath);
|
const QFileInfo inf(mFilePath);
|
||||||
|
|
|
@ -70,6 +70,12 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList GetExcludedPaths() const;
|
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.
|
* @brief Set project root path to dialog control.
|
||||||
* @param root Project root path to set to dialog control.
|
* @param root Project root path to set to dialog control.
|
||||||
|
@ -100,6 +106,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetExcludedPaths(const QStringList &paths);
|
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:
|
protected slots:
|
||||||
/**
|
/**
|
||||||
* @brief Browse for include directory.
|
* @brief Browse for include directory.
|
||||||
|
|
Loading…
Reference in New Issue