Declaration for a single configuration key. More...
#include <phosphor-config/include/PhosphorConfig/Schema.h>
Public Attributes | |
| QString | key |
| QVariant | defaultValue |
| QMetaType::Type | expectedType = QMetaType::UnknownType |
| QString | description = {} |
| Human-readable description. | |
| std::function< QVariant(const QVariant &value)> | validator = {} |
| Coercion applied on every read and every write. | |
| QVector< ChoiceDef > | choices = {} |
| The legal values, for a key that takes one of a closed set. | |
Declaration for a single configuration key.
A consumer describes each key it persists once, and PhosphorConfig handles defaults, reset-to-default, export/import, and migration-friendly lookups.
expectedType is an optional hint used by Store::write() to warn when a caller supplies a value of a mismatched type. Leave as QMetaType::UnknownType to disable the check.
validator runs on both read and write paths, giving consumers a single place to clamp ranges (qBound), normalize enum-style strings, or log and fall back to the default on invalid input. The returned QVariant is the value the caller observes (on read) or persists (on write). When unset, values pass through unchanged.
| QVector<ChoiceDef> PhosphorConfig::KeyDef::choices = {} |
The legal values, for a key that takes one of a closed set.
Empty for an open-valued key (a width, a colour, free text).
Declaring these does NOT enforce them — validator remains the single coercion path, so a key with choices should still clamp or normalize there. What this adds is READABILITY: a caller can enumerate what a key accepts, which a validator lambda cannot answer.
Trailing position with an NSDMI is load-bearing for the same reason description documents above — aggregate initializers across consumers omit this field.
| QVariant PhosphorConfig::KeyDef::defaultValue |
| QString PhosphorConfig::KeyDef::description = {} |
Human-readable description.
Not used at runtime — consumers may surface it in settings UIs or generated documentation.
The default-member-initializer (= {}) is load-bearing: aggregate initializers across the codebase omit this trailing field, and GCC's -Wmissing-field-initializers fires when omitted fields lack an NSDMI. Keeping the explicit = {} here silences the warning without forcing every call site to spell out two trailing empties.
| QMetaType::Type PhosphorConfig::KeyDef::expectedType = QMetaType::UnknownType |
| QString PhosphorConfig::KeyDef::key |
| std::function<QVariant(const QVariant& value)> PhosphorConfig::KeyDef::validator = {} |
Coercion applied on every read and every write.
Typical uses:
CONTRACT: validators MUST be idempotent — validator(validator(x)) must equal validator(x) for every input. Store::write compares the already-coerced write value against the canonicalized on-disk value to decide whether to short-circuit the write; a non-idempotent validator (e.g. one that appends a character each call) would cause the comparison to never match, rewriting the file and firing changed() on every save even when no user change occurred.
description above documents why the = {} default matters here too.