Skip to content

Commit 0561d59

Browse files
committed
GUI: Added checkbox 'Analyze all Visual Studio configurations' in the projectfile dialog
1 parent e675ede commit 0561d59

6 files changed

Lines changed: 117 additions & 2 deletions

File tree

gui/checkstatistics.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ CheckStatistics::CheckStatistics(QObject *parent)
2525
clear();
2626
}
2727

28-
static void addItem(QMap<QString,unsigned> &m, const QString &key) {
28+
static void addItem(QMap<QString,unsigned> &m, const QString &key)
29+
{
2930
if (m.contains(key))
3031
m[key]++;
3132
else

gui/mainwindow.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,35 @@ void MainWindow::doAnalyzeProject(ImportProject p)
384384
v.push_back(i.toStdString());
385385
}
386386
p.ignorePaths(v);
387+
388+
if (!mProjectFile->getAnalyzeAllVsConfigs()) {
389+
std::set<std::string> filenames;
390+
Settings::PlatformType platform = (Settings::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
391+
for (std::list<ImportProject::FileSettings>::iterator it = p.fileSettings.begin(); it != p.fileSettings.end();) {
392+
if (it->cfg.empty()) {
393+
++it;
394+
continue;
395+
}
396+
const ImportProject::FileSettings &fs = *it;
397+
bool remove = false;
398+
if (fs.cfg.compare(0,5,"Debug") != 0)
399+
remove = true;
400+
if (platform == Settings::Win64 && fs.platformType != platform)
401+
remove = true;
402+
else if ((platform == Settings::Win32A || platform == Settings::Win32W) && fs.platformType == Settings::Win64)
403+
remove = true;
404+
else if (fs.platformType != Settings::Win64 && platform == Settings::Win64)
405+
remove = true;
406+
else if (filenames.find(fs.filename) != filenames.end())
407+
remove = true;
408+
if (remove) {
409+
it = p.fileSettings.erase(it);
410+
} else {
411+
filenames.insert(fs.filename);
412+
++it;
413+
}
414+
}
415+
}
387416
} else {
388417
enableProjectActions(false);
389418
}

gui/projectfile.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const char ProjectVersionAttrib[] = "version";
2929
static const char ProjectFileVersion[] = "1";
3030
static const char BuildDirElementName[] = "builddir";
3131
static const char ImportProjectElementName[] = "importproject";
32+
static const char AnalyzeAllVsConfigsElementName[] = "analyze-all-vs-configs";
3233
static const char IncludeDirElementName[] = "includedir";
3334
static const char DirElementName[] = "dir";
3435
static const char DirNameAttrib[] = "name";
@@ -56,15 +57,32 @@ static const char AddonsElementName[] = "addons";
5657
ProjectFile::ProjectFile(QObject *parent) :
5758
QObject(parent)
5859
{
60+
clear();
5961
}
6062

6163
ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
6264
QObject(parent),
6365
mFilename(filename)
6466
{
67+
clear();
6568
read();
6669
}
6770

71+
void ProjectFile::clear()
72+
{
73+
mRootPath.clear();
74+
mBuildDir.clear();
75+
mImportProject.clear();
76+
mAnalyzeAllVsConfigs = true;
77+
mIncludeDirs.clear();
78+
mDefines.clear();
79+
mPaths.clear();
80+
mExcludedPaths.clear();
81+
mLibraries.clear();
82+
mSuppressions.clear();
83+
mAddons.clear();
84+
}
85+
6886
bool ProjectFile::read(const QString &filename)
6987
{
7088
if (!filename.isEmpty())
@@ -74,6 +92,8 @@ bool ProjectFile::read(const QString &filename)
7492
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
7593
return false;
7694

95+
clear();
96+
7797
QXmlStreamReader xmlReader(&file);
7898
bool insideProject = false;
7999
bool projectTagFound = false;
@@ -99,6 +119,9 @@ bool ProjectFile::read(const QString &filename)
99119
if (insideProject && xmlReader.name() == ImportProjectElementName)
100120
readImportProject(xmlReader);
101121

122+
if (insideProject && xmlReader.name() == AnalyzeAllVsConfigsElementName)
123+
readAnalyzeAllVsConfigs(xmlReader);
124+
102125
// Find include directory from inside project element
103126
if (insideProject && xmlReader.name() == IncludeDirElementName)
104127
readIncludeDirs(xmlReader);
@@ -211,6 +234,31 @@ void ProjectFile::readImportProject(QXmlStreamReader &reader)
211234
} while (1);
212235
}
213236

237+
void ProjectFile::readAnalyzeAllVsConfigs(QXmlStreamReader &reader)
238+
{
239+
mImportProject.clear();
240+
do {
241+
const QXmlStreamReader::TokenType type = reader.readNext();
242+
switch (type) {
243+
case QXmlStreamReader::Characters:
244+
mAnalyzeAllVsConfigs = (reader.text().toString() == "true");
245+
case QXmlStreamReader::EndElement:
246+
return;
247+
// Not handled
248+
case QXmlStreamReader::StartElement:
249+
case QXmlStreamReader::NoToken:
250+
case QXmlStreamReader::Invalid:
251+
case QXmlStreamReader::StartDocument:
252+
case QXmlStreamReader::EndDocument:
253+
case QXmlStreamReader::Comment:
254+
case QXmlStreamReader::DTD:
255+
case QXmlStreamReader::EntityReference:
256+
case QXmlStreamReader::ProcessingInstruction:
257+
break;
258+
}
259+
} while (1);
260+
}
261+
214262
void ProjectFile::readIncludeDirs(QXmlStreamReader &reader)
215263
{
216264
QXmlStreamReader::TokenType type;
@@ -477,6 +525,10 @@ bool ProjectFile::write(const QString &filename)
477525
xmlWriter.writeEndElement();
478526
}
479527

528+
xmlWriter.writeStartElement(AnalyzeAllVsConfigsElementName);
529+
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
530+
xmlWriter.writeEndElement();
531+
480532
if (!mIncludeDirs.isEmpty()) {
481533
xmlWriter.writeStartElement(IncludeDirElementName);
482534
foreach (QString incdir, mIncludeDirs) {

gui/projectfile.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class ProjectFile : public QObject {
6262
return mImportProject;
6363
}
6464

65+
bool getAnalyzeAllVsConfigs() const {
66+
return mAnalyzeAllVsConfigs;
67+
}
68+
6569
/**
6670
* @brief Get list of include directories.
6771
* @return list of directories.
@@ -143,6 +147,10 @@ class ProjectFile : public QObject {
143147
mImportProject = importProject;
144148
}
145149

150+
void setAnalyzeAllVsConfigs(bool b) {
151+
mAnalyzeAllVsConfigs = b;
152+
}
153+
146154
/**
147155
* @brief Set list of includes.
148156
* @param includes List of defines.
@@ -215,6 +223,8 @@ class ProjectFile : public QObject {
215223
*/
216224
void readImportProject(QXmlStreamReader &reader);
217225

226+
void readAnalyzeAllVsConfigs(QXmlStreamReader &reader);
227+
218228
/**
219229
* @brief Read list of include directories from XML.
220230
* @param reader XML stream reader.
@@ -258,6 +268,8 @@ class ProjectFile : public QObject {
258268

259269
private:
260270

271+
void clear();
272+
261273
/**
262274
* @brief Convert paths
263275
*/
@@ -282,6 +294,13 @@ class ProjectFile : public QObject {
282294
/** Visual studio project/solution , compile database */
283295
QString mImportProject;
284296

297+
/**
298+
* Should all visual studio configurations be analyzed?
299+
* If this is false then only the Debug configuration
300+
* for the set platform is analyzed.
301+
*/
302+
bool mAnalyzeAllVsConfigs;
303+
285304
/**
286305
* @brief List of include directories used to search include files.
287306
*/

gui/projectfiledialog.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
140140
setDefines(projectFile->getDefines());
141141
setCheckPaths(projectFile->getCheckPaths());
142142
setImportProject(projectFile->getImportProject());
143+
mUI.mChkAllVsConfigs->setChecked(projectFile->getAnalyzeAllVsConfigs());
143144
setExcludedPaths(projectFile->getExcludedPaths());
144145
setLibraries(projectFile->getLibraries());
145146
setSuppressions(projectFile->getSuppressions());
@@ -155,6 +156,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
155156
projectFile->setRootPath(getRootPath());
156157
projectFile->setBuildDir(getBuildDir());
157158
projectFile->setImportProject(getImportProject());
159+
projectFile->setAnalyzeAllVsConfigs(mUI.mChkAllVsConfigs->isChecked());
158160
projectFile->setIncludes(getIncludePaths());
159161
projectFile->setDefines(getDefines());
160162
projectFile->setCheckPaths(getCheckPaths());
@@ -218,7 +220,8 @@ void ProjectFileDialog::browseBuildDir()
218220

219221
void ProjectFileDialog::updatePathsAndDefines()
220222
{
221-
bool importProject = !mUI.mEditImportProject->text().isEmpty();
223+
const QString &fileName = mUI.mEditImportProject->text();
224+
bool importProject = !fileName.isEmpty();
222225
mUI.mBtnClearImportProject->setEnabled(importProject);
223226
mUI.mListCheckPaths->setEnabled(!importProject);
224227
mUI.mListIncludeDirs->setEnabled(!importProject);
@@ -231,6 +234,7 @@ void ProjectFileDialog::updatePathsAndDefines()
231234
mUI.mBtnRemoveInclude->setEnabled(!importProject);
232235
mUI.mBtnIncludeUp->setEnabled(!importProject);
233236
mUI.mBtnIncludeDown->setEnabled(!importProject);
237+
mUI.mChkAllVsConfigs->setEnabled(fileName.endsWith(".sln") || fileName.endsWith(".vcxproj"));
234238
}
235239

236240
void ProjectFileDialog::clearImportProject()

gui/projectfiledialog.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@
110110
</item>
111111
</layout>
112112
</item>
113+
<item>
114+
<widget class="QCheckBox" name="mChkAllVsConfigs">
115+
<property name="toolTip">
116+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You have a choice:&lt;/p&gt;&lt;p&gt; * Analyze all Debug and Release configurations&lt;/p&gt;&lt;p&gt; * Only analyze the first matching Debug configuration&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
117+
</property>
118+
<property name="text">
119+
<string>Analyze all Visual Studio configurations</string>
120+
</property>
121+
</widget>
122+
</item>
113123
</layout>
114124
</item>
115125
<item>

0 commit comments

Comments
 (0)