From 2d669870453884ae3e675d502d3f25b56b13adbd Mon Sep 17 00:00:00 2001 From: luisangelsm Date: Mon, 2 Mar 2026 22:44:08 +0100 Subject: [PATCH] Make json keys display as human readable strings in the theme editor --- common/themes/theme_editor_dialog.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/common/themes/theme_editor_dialog.cpp b/common/themes/theme_editor_dialog.cpp index eaeed515..4f4ef7d4 100644 --- a/common/themes/theme_editor_dialog.cpp +++ b/common/themes/theme_editor_dialog.cpp @@ -32,6 +32,24 @@ static const int IsBoolRole = Qt::UserRole + 2; // Role used to distinguish numeric items. static const int IsNumberRole = Qt::UserRole + 3; +// Converts a camelCase JSON key to a human-readable display string. +// "metadataScraperDialog" → "Metadata scraper dialog" +// "navigationTreeQSS" → "Navigation tree qss" +// Consecutive uppercase letters (acronyms) are kept together as one word. +static QString displayKey(const QString &key) +{ + QString result; + for (int i = 0; i < key.size(); ++i) { + const bool isUpper = key[i].isUpper(); + const bool prevIsLower = (i > 0) && key[i - 1].isLower(); + const bool nextIsLower = (i + 1 < key.size()) && key[i + 1].isLower(); + if (i > 0 && isUpper && (prevIsLower || nextIsLower)) + result += ' '; + result += result.isEmpty() ? key[i].toUpper() : key[i].toLower(); + } + return result; +} + static bool isColorString(const QString &s) { // Accepts #RGB, #RRGGBB, #AARRGGBB @@ -171,14 +189,14 @@ void ThemeEditorDialog::populate(QTreeWidgetItem *parent, const QJsonObject &obj QFont bold = group->font(0); bold.setBold(true); group->setFont(0, bold); - group->setText(0, key); + group->setText(0, displayKey(key)); group->setFlags(group->flags() & ~Qt::ItemIsSelectable); populate(group, val.toObject(), childPath); } else { // Leaf row QTreeWidgetItem *item = parent ? new QTreeWidgetItem(parent) : new QTreeWidgetItem(tree); - item->setText(0, key); + item->setText(0, displayKey(key)); item->setData(0, PathRole, childPath); const QString strVal = val.toString();