Skip to content

Commit 9698387

Browse files
committed
GUI: Add libraries setting to project
1 parent 41e4194 commit 9698387

7 files changed

Lines changed: 170 additions & 0 deletions

File tree

gui/mainwindow.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@ Settings MainWindow::GetCppcheckSettings()
530530
result.userDefines += define.toStdString();
531531
}
532532

533+
QStringList libraries = pfile->GetLibraries();
534+
foreach(QString library, libraries) {
535+
const QString applicationFilePath = QCoreApplication::applicationFilePath();
536+
if (!result.library.load(applicationFilePath.toLatin1(), (library+".cfg").toLatin1()))
537+
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(library));
538+
}
539+
533540
// Only check the given -D configuration
534541
if (!defines.isEmpty())
535542
result._maxConfigs = 1;

gui/project.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ bool Project::Edit()
9595
dlg.SetPaths(paths);
9696
QStringList ignorepaths = mPFile->GetExcludedPaths();
9797
dlg.SetExcludedPaths(ignorepaths);
98+
dlg.SetLibraries(mPFile->GetLibraries());
9899

99100
int rv = dlg.exec();
100101
if (rv == QDialog::Accepted) {
@@ -108,6 +109,7 @@ bool Project::Edit()
108109
mPFile->SetCheckPaths(paths);
109110
QStringList excludedpaths = dlg.GetExcludedPaths();
110111
mPFile->SetExcludedPaths(excludedpaths);
112+
mPFile->SetLibraries(dlg.GetLibraries());
111113

112114
bool writeSuccess = mPFile->Write();
113115
if (!writeSuccess) {

gui/projectfile.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static const char IgnorePathNameAttrib[] = "name";
4444
static const char ExcludeElementName[] = "exclude";
4545
static const char ExcludePathName[] = "path";
4646
static const char ExcludePathNameAttrib[] = "name";
47+
static const char LibrariesElementName[] = "libraries";
48+
static const char LibraryElementName[] = "library";
4749

4850
ProjectFile::ProjectFile(QObject *parent) :
4951
QObject(parent)
@@ -100,6 +102,10 @@ bool ProjectFile::Read(const QString &filename)
100102
if (insideProject && xmlReader.name() == IgnoreElementName)
101103
ReadExcludes(xmlReader);
102104

105+
// Find libraries list from insid project element
106+
if (insideProject && xmlReader.name() == LibrariesElementName)
107+
ReadLibraries(xmlReader);
108+
103109
break;
104110

105111
case QXmlStreamReader::EndElement:
@@ -160,6 +166,15 @@ QStringList ProjectFile::GetExcludedPaths() const
160166
return paths;
161167
}
162168

169+
QStringList ProjectFile::GetLibraries() const
170+
{
171+
QStringList libraries;
172+
foreach(QString library, mLibraries) {
173+
libraries << library;
174+
}
175+
return libraries;
176+
}
177+
163178
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
164179
{
165180
QXmlStreamAttributes attribs = reader.attributes();
@@ -327,6 +342,45 @@ void ProjectFile::ReadExcludes(QXmlStreamReader &reader)
327342
} while (!allRead);
328343
}
329344

345+
346+
void ProjectFile::ReadLibraries(QXmlStreamReader &reader)
347+
{
348+
QXmlStreamReader::TokenType type;
349+
bool allRead = false;
350+
do {
351+
type = reader.readNext();
352+
switch (type) {
353+
case QXmlStreamReader::StartElement:
354+
// Read library-elements
355+
if (reader.name().toString() == LibraryElementName) {
356+
type = reader.readNext();
357+
if (type == QXmlStreamReader::Characters) {
358+
QString library = reader.text().toString();
359+
mLibraries << library;
360+
}
361+
}
362+
break;
363+
364+
case QXmlStreamReader::EndElement:
365+
if (reader.name().toString() == LibrariesElementName)
366+
allRead = true;
367+
break;
368+
369+
// Not handled
370+
case QXmlStreamReader::NoToken:
371+
case QXmlStreamReader::Invalid:
372+
case QXmlStreamReader::StartDocument:
373+
case QXmlStreamReader::EndDocument:
374+
case QXmlStreamReader::Characters:
375+
case QXmlStreamReader::Comment:
376+
case QXmlStreamReader::DTD:
377+
case QXmlStreamReader::EntityReference:
378+
case QXmlStreamReader::ProcessingInstruction:
379+
break;
380+
}
381+
} while (!allRead);
382+
}
383+
330384
void ProjectFile::SetIncludes(const QStringList &includes)
331385
{
332386
mIncludeDirs = includes;
@@ -347,6 +401,11 @@ void ProjectFile::SetExcludedPaths(const QStringList &paths)
347401
mExcludedPaths = paths;
348402
}
349403

404+
void ProjectFile::SetLibraries(const QStringList &libraries)
405+
{
406+
mLibraries = libraries;
407+
}
408+
350409
bool ProjectFile::Write(const QString &filename)
351410
{
352411
if (!filename.isEmpty())
@@ -408,6 +467,16 @@ bool ProjectFile::Write(const QString &filename)
408467
xmlWriter.writeEndElement();
409468
}
410469

470+
if (!mLibraries.isEmpty()) {
471+
xmlWriter.writeStartElement(LibrariesElementName);
472+
foreach(QString library, mLibraries) {
473+
xmlWriter.writeStartElement(LibraryElementName);
474+
xmlWriter.writeCharacters(library);
475+
xmlWriter.writeEndElement();
476+
}
477+
xmlWriter.writeEndElement();
478+
}
479+
411480
xmlWriter.writeEndDocument();
412481
file.close();
413482
return true;

gui/projectfile.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ class ProjectFile : public QObject {
7878
*/
7979
QStringList GetExcludedPaths() const;
8080

81+
/**
82+
* @brief Get list libraries.
83+
* @return list of libraries.
84+
*/
85+
QStringList GetLibraries() const;
86+
8187
/**
8288
* @brief Get filename for the project file.
8389
* @return file name.
@@ -118,6 +124,12 @@ class ProjectFile : public QObject {
118124
*/
119125
void SetExcludedPaths(const QStringList &paths);
120126

127+
/**
128+
* @brief Set list of libraries.
129+
* @param paths List of libraries.
130+
*/
131+
void SetLibraries(const QStringList &libraries);
132+
121133
/**
122134
* @brief Write project file (to disk).
123135
* @param filename Filename to use.
@@ -164,6 +176,12 @@ class ProjectFile : public QObject {
164176
*/
165177
void ReadExcludes(QXmlStreamReader &reader);
166178

179+
/**
180+
* @brief Read list of libraries.
181+
* @param reader XML stream reader.
182+
*/
183+
void ReadLibraries(QXmlStreamReader &reader);
184+
167185
private:
168186

169187
/**
@@ -198,6 +216,11 @@ class ProjectFile : public QObject {
198216
* @brief Paths excluded from the check.
199217
*/
200218
QStringList mExcludedPaths;
219+
220+
/**
221+
* @brief List of libraries.
222+
*/
223+
QStringList mLibraries;
201224
};
202225
/// @}
203226
#endif // PROJECT_FILE_H

gui/projectfile.ui

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,45 @@
5858
</item>
5959
</layout>
6060
</item>
61+
<item>
62+
<layout class="QHBoxLayout" name="horizontalLayout_6">
63+
<item>
64+
<widget class="QLabel" name="label_6">
65+
<property name="text">
66+
<string>Libraries:</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item>
71+
<widget class="QCheckBox" name="mChkboxGtk">
72+
<property name="text">
73+
<string>gtk</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item>
78+
<widget class="QCheckBox" name="mChkboxPosix">
79+
<property name="text">
80+
<string>posix</string>
81+
</property>
82+
</widget>
83+
</item>
84+
<item>
85+
<widget class="QCheckBox" name="mChkboxQt">
86+
<property name="text">
87+
<string>qt</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item>
92+
<widget class="QCheckBox" name="mChkboxWindows">
93+
<property name="text">
94+
<string>windows</string>
95+
</property>
96+
</widget>
97+
</item>
98+
</layout>
99+
</item>
61100
<item>
62101
<layout class="QHBoxLayout" name="horizontalLayout_3">
63102
<item>

gui/projectfiledialog.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ QStringList ProjectFileDialog::GetExcludedPaths() const
160160
return paths;
161161
}
162162

163+
QStringList ProjectFileDialog::GetLibraries() const
164+
{
165+
QStringList libraries;
166+
const QCheckBox *c[] = { mUI.mChkboxGtk, mUI.mChkboxPosix, mUI.mChkboxQt, mUI.mChkboxWindows };
167+
for (unsigned int i = 0; i < sizeof(c) / sizeof(c[0]); i++) {
168+
if (c[i]->isChecked())
169+
libraries << c[i]->text();
170+
}
171+
return libraries;
172+
}
173+
163174
void ProjectFileDialog::SetRootPath(const QString &root)
164175
{
165176
QString newroot = QDir::toNativeSeparators(root);
@@ -201,6 +212,13 @@ void ProjectFileDialog::SetExcludedPaths(const QStringList &paths)
201212
}
202213
}
203214

215+
void ProjectFileDialog::SetLibraries(const QStringList &libraries)
216+
{
217+
QCheckBox *c[] = { mUI.mChkboxGtk, mUI.mChkboxPosix, mUI.mChkboxQt, mUI.mChkboxWindows };
218+
for (unsigned int i = 0; i < sizeof(c) / sizeof(c[0]); i++)
219+
c[i]->setChecked(libraries.contains(c[i]->text()));
220+
}
221+
204222
void ProjectFileDialog::AddIncludeDir()
205223
{
206224
const QFileInfo inf(mFilePath);

gui/projectfiledialog.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class ProjectFileDialog : public QDialog {
7070
*/
7171
QStringList GetExcludedPaths() const;
7272

73+
/**
74+
* @brief Return selected libraries from the dialog control.
75+
* @return List of libraries.
76+
*/
77+
QStringList GetLibraries() const;
78+
7379
/**
7480
* @brief Set project root path to dialog control.
7581
* @param root Project root path to set to dialog control.
@@ -100,6 +106,12 @@ class ProjectFileDialog : public QDialog {
100106
*/
101107
void SetExcludedPaths(const QStringList &paths);
102108

109+
/**
110+
* @brief Set libraries to dialog control.
111+
* @param paths List of libraries to set to dialog control.
112+
*/
113+
void SetLibraries(const QStringList &libraries);
114+
103115
protected slots:
104116
/**
105117
* @brief Browse for include directory.

0 commit comments

Comments
 (0)