|
33 | 33 | #include "library.h" |
34 | 34 | #include "cppcheck.h" |
35 | 35 | #include "errorlogger.h" |
| 36 | +#include "platforms.h" |
| 37 | + |
| 38 | +/** Platforms shown in the platform combobox */ |
| 39 | +static const cppcheck::Platform::PlatformType builtinPlatforms[] = { |
| 40 | + cppcheck::Platform::Native, |
| 41 | + cppcheck::Platform::Win32A, |
| 42 | + cppcheck::Platform::Win32W, |
| 43 | + cppcheck::Platform::Win64, |
| 44 | + cppcheck::Platform::Unix32, |
| 45 | + cppcheck::Platform::Unix64 |
| 46 | +}; |
| 47 | + |
| 48 | +static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]); |
36 | 49 |
|
37 | 50 | ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent) |
38 | 51 | : QDialog(parent) |
@@ -94,6 +107,32 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent) |
94 | 107 | mLibraryCheckboxes << checkbox; |
95 | 108 | } |
96 | 109 |
|
| 110 | + // Platforms.. |
| 111 | + Platforms p; |
| 112 | + for (int i = 0; i < numberOfBuiltinPlatforms; i++) |
| 113 | + mUI.mComboBoxPlatform->addItem(p.get(builtinPlatforms[i]).mTitle); |
| 114 | + QStringList platformFiles; |
| 115 | + foreach (QString sp, searchPaths) { |
| 116 | + if (sp.endsWith("/cfg")) |
| 117 | + sp = sp.mid(0,sp.length()-3) + "platforms"; |
| 118 | + QDir dir(sp); |
| 119 | + dir.setSorting(QDir::Name); |
| 120 | + dir.setNameFilters(QStringList("*.xml")); |
| 121 | + dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
| 122 | + foreach (QFileInfo item, dir.entryInfoList()) { |
| 123 | + const QString platformFile = item.fileName(); |
| 124 | + |
| 125 | + cppcheck::Platform p; |
| 126 | + if (!p.loadPlatformFile(appPath.toStdString().c_str(), platformFile.toStdString())) |
| 127 | + continue; |
| 128 | + |
| 129 | + if (platformFiles.indexOf(platformFile) == -1) |
| 130 | + platformFiles << platformFile; |
| 131 | + } |
| 132 | + } |
| 133 | + qSort(platformFiles); |
| 134 | + mUI.mComboBoxPlatform->addItems(platformFiles); |
| 135 | + |
97 | 136 | mUI.mEditTags->setValidator(new QRegExpValidator(QRegExp("[a-zA-Z0-9 ;]*"),this)); |
98 | 137 |
|
99 | 138 | connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &ProjectFileDialog::ok); |
@@ -156,6 +195,33 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile) |
156 | 195 | mUI.mChkAllVsConfigs->setChecked(projectFile->getAnalyzeAllVsConfigs()); |
157 | 196 | setExcludedPaths(projectFile->getExcludedPaths()); |
158 | 197 | setLibraries(projectFile->getLibraries()); |
| 198 | + const QString platform = projectFile->getPlatform(); |
| 199 | + if (platform.endsWith(".xml")) { |
| 200 | + int i; |
| 201 | + for (i = numberOfBuiltinPlatforms; i < mUI.mComboBoxPlatform->count(); ++i) { |
| 202 | + if (mUI.mComboBoxPlatform->itemText(i) == platform) |
| 203 | + break; |
| 204 | + } |
| 205 | + if (i < mUI.mComboBoxPlatform->count()) |
| 206 | + mUI.mComboBoxPlatform->setCurrentIndex(i); |
| 207 | + else { |
| 208 | + mUI.mComboBoxPlatform->addItem(platform); |
| 209 | + mUI.mComboBoxPlatform->setCurrentIndex(i); |
| 210 | + } |
| 211 | + } else { |
| 212 | + int i; |
| 213 | + for (i = 0; i < numberOfBuiltinPlatforms; ++i) { |
| 214 | + const cppcheck::Platform::PlatformType p = builtinPlatforms[i]; |
| 215 | + if (platform == cppcheck::Platform::platformString(p)) |
| 216 | + break; |
| 217 | + } |
| 218 | + if (i < numberOfBuiltinPlatforms) |
| 219 | + mUI.mComboBoxPlatform->setCurrentIndex(i); |
| 220 | + else |
| 221 | + mUI.mComboBoxPlatform->setCurrentIndex(-1); |
| 222 | + } |
| 223 | + |
| 224 | + mUI.mComboBoxPlatform->setCurrentText(projectFile->getPlatform()); |
159 | 225 | setSuppressions(projectFile->getSuppressions()); |
160 | 226 |
|
161 | 227 | QSettings settings; |
@@ -193,6 +259,15 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const |
193 | 259 | projectFile->setCheckPaths(getCheckPaths()); |
194 | 260 | projectFile->setExcludedPaths(getExcludedPaths()); |
195 | 261 | projectFile->setLibraries(getLibraries()); |
| 262 | + if (mUI.mComboBoxPlatform->currentText().endsWith(".xml")) |
| 263 | + projectFile->setPlatform(mUI.mComboBoxPlatform->currentText()); |
| 264 | + else { |
| 265 | + int i = mUI.mComboBoxPlatform->currentIndex(); |
| 266 | + if (i < numberOfBuiltinPlatforms) |
| 267 | + projectFile->setPlatform(cppcheck::Platform::platformString(builtinPlatforms[i])); |
| 268 | + else |
| 269 | + projectFile->setPlatform(QString()); |
| 270 | + } |
196 | 271 | projectFile->setSuppressions(getSuppressions()); |
197 | 272 | QStringList list; |
198 | 273 | if (mUI.mAddonThreadSafety->isChecked()) |
|
0 commit comments