MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / getCppcheckSettings

Method getCppcheckSettings

gui/mainwindow.cpp:1066–1255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1064}
1065
1066bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
1067{
1068 saveSettings(); // Save settings
1069
1070 Settings::terminate(true);
1071
1072 settings.exename = QCoreApplication::applicationFilePath().toStdString();
1073 settings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
1074 settings.reportProgress = 10;
1075
1076 // default to --check-level=normal for GUI for now
1077 settings.setCheckLevel(Settings::CheckLevel::normal);
1078
1079 const bool std = tryLoadLibrary(settings.library, "std.cfg");
1080 if (!std) {
1081 QMessageBox::critical(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir=<directory> at the command line to specify where this file is located. Please note that --data-dir is supposed to be used by installation scripts and therefore the GUI does not start when it is used, all that happens is that the setting is configured.\n\nAnalysis is aborted.").arg("std.cfg"));
1082 return false;
1083 }
1084
1085 const QString filesDir(getDataDir());
1086 const QString pythonCmd = fromNativePath(mSettings->value(SETTINGS_PYTHON_PATH).toString());
1087
1088 {
1089 const QString cfgErr = QString::fromStdString(Settings::loadCppcheckCfg(settings, supprs));
1090 if (!cfgErr.isEmpty()) {
1091 QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2\n\nAnalysis is aborted.").arg("cppcheck.cfg").arg(cfgErr));
1092 return false;
1093 }
1094
1095 settings.premium = startsWith(settings.cppcheckCfgProductName, "Cppcheck Premium");
1096
1097 const auto cfgAddons = settings.addons;
1098 settings.addons.clear();
1099 for (const std::string& addon : cfgAddons) {
1100 // TODO: support addons which are a script and not a file
1101 const QString addonError = loadAddon(settings, filesDir, pythonCmd, QString::fromStdString(addon));
1102 if (!addonError.isEmpty()) {
1103 QMessageBox::critical(this, tr("Error"), tr("%1\n\nAnalysis is aborted.").arg(addonError));
1104 return false;
1105 }
1106 }
1107 }
1108
1109 // If project file loaded, read settings from it
1110 if (mProjectFile) {
1111 QStringList dirs = mProjectFile->getIncludeDirs();
1112 addIncludeDirs(dirs, settings);
1113
1114 settings.inlineSuppressions = mProjectFile->getInlineSuppression();
1115
1116 const QStringList defines = mProjectFile->getDefines();
1117 for (const QString& define : defines) {
1118 if (!settings.userDefines.empty())
1119 settings.userDefines += ";";
1120 settings.userDefines += define.toStdString();
1121 }
1122
1123 settings.clang = mProjectFile->clangParser;

Callers

nothing calls this directly

Calls 15

terminateFunction · 0.85
getDataDirFunction · 0.85
fromNativePathFunction · 0.85
isEmptyMethod · 0.80
getIncludeDirsMethod · 0.80
getDefinesMethod · 0.80
getUndefinesMethod · 0.80
getLibrariesMethod · 0.80
endsWithMethod · 0.80
getImportProjectMethod · 0.80

Tested by

no test coverage detected