| 399 | } |
| 400 | |
| 401 | auto SourceFormatterController::stylesForFormatter(const ISourceFormatter& formatter) const -> StyleMap |
| 402 | { |
| 403 | StyleMap styles; |
| 404 | |
| 405 | const auto predefinedStyles = formatter.predefinedStyles(); |
| 406 | for (const auto& style : predefinedStyles) { |
| 407 | const auto [it, inserted] = styles.try_emplace(style.name(), style); |
| 408 | Q_ASSERT(it->second.name() == it->first); |
| 409 | Q_ASSERT_X(inserted, Q_FUNC_INFO, "Duplicate predefined style!"); |
| 410 | } |
| 411 | |
| 412 | const auto commonConfig = globalConfig(); |
| 413 | const QString formatterKey = formatter.name(); |
| 414 | if (commonConfig.hasGroup(formatterKey)) { |
| 415 | const auto formatterConfig = commonConfig.group(formatterKey); |
| 416 | const auto subgroups = formatterConfig.groupList(); |
| 417 | for (const QString& subgroup : subgroups) { |
| 418 | const auto [it, inserted] = styles.insert_or_assign(subgroup, SourceFormatterStyle{subgroup}); |
| 419 | Q_ASSERT(it->second.name() == it->first); |
| 420 | if (!inserted) { |
| 421 | // This overriding is an undocumented and possibly unintentional feature, which has existed |
| 422 | // for more than 10 years. Source Formatter configuration UI creates styles named "UserN", |
| 423 | // which cannot override predefined styles. But if the user edits kdeveloprc manually and |
| 424 | // renames a style, it correctly overrides the predefined style for all intents and purposes. |
| 425 | qCDebug(SHELL).noquote() << QStringLiteral( |
| 426 | "A user-defined style config group [%1][%2][%3] " |
| 427 | "overrides a predefined style with the same name.") |
| 428 | .arg(Config::Strings::sourceFormatter(), formatterKey, subgroup); |
| 429 | } |
| 430 | Config::populateStyleFromConfig(it->second, formatterConfig.group(subgroup)); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | return styles; |
| 435 | } |
| 436 | |
| 437 | SourceFormatterController::FileFormatter::FileFormatter(const IDocument& doc) |
| 438 | : m_url{doc.url()} |
no test coverage detected