mirror of
https://github.com/YACReader/yacreader
synced 2026-04-12 15:49:53 -04:00
Make json keys display as human readable strings in the theme editor
This commit is contained in:
@ -32,6 +32,24 @@ static const int IsBoolRole = Qt::UserRole + 2;
|
|||||||
// Role used to distinguish numeric items.
|
// Role used to distinguish numeric items.
|
||||||
static const int IsNumberRole = Qt::UserRole + 3;
|
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)
|
static bool isColorString(const QString &s)
|
||||||
{
|
{
|
||||||
// Accepts #RGB, #RRGGBB, #AARRGGBB
|
// Accepts #RGB, #RRGGBB, #AARRGGBB
|
||||||
@ -171,14 +189,14 @@ void ThemeEditorDialog::populate(QTreeWidgetItem *parent, const QJsonObject &obj
|
|||||||
QFont bold = group->font(0);
|
QFont bold = group->font(0);
|
||||||
bold.setBold(true);
|
bold.setBold(true);
|
||||||
group->setFont(0, bold);
|
group->setFont(0, bold);
|
||||||
group->setText(0, key);
|
group->setText(0, displayKey(key));
|
||||||
group->setFlags(group->flags() & ~Qt::ItemIsSelectable);
|
group->setFlags(group->flags() & ~Qt::ItemIsSelectable);
|
||||||
populate(group, val.toObject(), childPath);
|
populate(group, val.toObject(), childPath);
|
||||||
} else {
|
} else {
|
||||||
// Leaf row
|
// Leaf row
|
||||||
QTreeWidgetItem *item = parent ? new QTreeWidgetItem(parent)
|
QTreeWidgetItem *item = parent ? new QTreeWidgetItem(parent)
|
||||||
: new QTreeWidgetItem(tree);
|
: new QTreeWidgetItem(tree);
|
||||||
item->setText(0, key);
|
item->setText(0, displayKey(key));
|
||||||
item->setData(0, PathRole, childPath);
|
item->setData(0, PathRole, childPath);
|
||||||
|
|
||||||
const QString strVal = val.toString();
|
const QString strVal = val.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user