Skip to content

Commit

Permalink
GUI: Add libraries setting to project
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Dec 29, 2013
1 parent 41e4194 commit 9698387
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gui/mainwindow.cpp
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions gui/project.cpp
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
69 changes: 69 additions & 0 deletions gui/projectfile.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions gui/projectfile.h
Expand Up @@ -78,6 +78,12 @@ class ProjectFile : public QObject {
*/
QStringList GetExcludedPaths() const;

/**
* @brief Get list libraries.
* @return list of libraries.
*/
QStringList GetLibraries() const;

/**
* @brief Get filename for the project file.
* @return file name.
Expand Down Expand Up @@ -118,6 +124,12 @@ class ProjectFile : public QObject {
*/
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.
Expand Down Expand Up @@ -164,6 +176,12 @@ class ProjectFile : public QObject {
*/
void ReadExcludes(QXmlStreamReader &reader);

/**
* @brief Read list of libraries.
* @param reader XML stream reader.
*/
void ReadLibraries(QXmlStreamReader &reader);

private:

/**
Expand Down Expand Up @@ -198,6 +216,11 @@ class ProjectFile : public QObject {
* @brief Paths excluded from the check.
*/
QStringList mExcludedPaths;

/**
* @brief List of libraries.
*/
QStringList mLibraries;
};
/// @}
#endif // PROJECT_FILE_H
39 changes: 39 additions & 0 deletions gui/projectfile.ui
Expand Up @@ -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>
Expand Down
18 changes: 18 additions & 0 deletions gui/projectfiledialog.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions gui/projectfiledialog.h
Expand Up @@ -70,6 +70,12 @@ class ProjectFileDialog : public QDialog {
*/
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.
Expand Down Expand Up @@ -100,6 +106,12 @@ class ProjectFileDialog : public QDialog {
*/
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.
Expand Down

8 comments on commit 9698387

@IOBYTE
Copy link
Contributor

@IOBYTE IOBYTE commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for adding this much needed feature to the GUI.

Can you add a search path for the config files. I can't figure out where to copy the config files to silence the new warnings. The directory where the cppcheck executable is doesn't work and the directory where the project files is doesn't work.

Also could we support user defined config files? It's easy to edit the project file but it would be nice to do it through the GUI.

Thanks again for this new feature.

@danmar
Copy link
Owner Author

@danmar danmar commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments.

It's very weird that it does not work to put the config files in the same folder as the cppcheck-gui executable.

Also could we support user defined config files?

I'll look at it

@IOBYTE
Copy link
Contributor

@IOBYTE IOBYTE commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I run cppcheck on ubuntu from the gnome desktop menu so I guess the default directory is not necessarily the same as the directory where the executable is. I copied the config files to my home directory and it works now but being able to tell cppcheck where to look for them would be better.

@danmar
Copy link
Owner Author

@danmar danmar commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not very sure.. normally the installer should install the cfg files and the user should not have to worry where it puts them. The CLI has an option to specify an alternate path at compile time but the GUI doesn't have such an option.

@danmar
Copy link
Owner Author

@danmar danmar commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the dialog is more dynamic so you should be able to select any library file you have. It still searches the application path. And it should also search the folder where the project file is located.

@danmar
Copy link
Owner Author

@danmar danmar commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. I discovered that my code didn't work well. Maybe it works better now?

@IOBYTE
Copy link
Contributor

@IOBYTE IOBYTE commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the config files in the project file directory and it found everything but std.cfg.

@IOBYTE
Copy link
Contributor

@IOBYTE IOBYTE commented on 9698387 Dec 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also finds all but std.cfg if I move them to the executable directory.

Please sign in to comment.