Skip to content

Commit

Permalink
Implement schema inheritance (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbek committed Dec 21, 2019
1 parent 3fe6b7f commit 05f42a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/utils/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,30 @@ QStringList Utils::Schema::Settings::getSchemaKeys(const QString& schema) const
* @param defaultValue
* @return
*/
QVariant Utils::Schema::Settings::getSchemaValue(const QString& key, const QVariant& defaultValue) const {
const QString& schema = currentSchemaKey();
if (_defaultSchemaSubkeys.contains(schema)) {
return _defaultSchemaSettings.value(schema + '/' + key, defaultValue);
} else {
return QSettings().value(schema + '/' + key, defaultValue);
QVariant Utils::Schema::Settings::getSchemaValue(const QString& key, const QVariant& defaultValue, QString schemaKey) const {
const bool schemaNotSet = schemaKey.isEmpty();

if (schemaNotSet) {
schemaKey = currentSchemaKey();
}

const bool isDefaultSchema = _defaultSchemaSubkeys.contains(schemaKey);

QVariant value = isDefaultSchema ?
_defaultSchemaSettings.value(schemaKey + QStringLiteral("/") + key, defaultValue) :
QSettings().value(schemaKey + QStringLiteral("/") + key, defaultValue);

if (!value.isValid() && schemaNotSet) {
QString fallbackSchemaKey = isDefaultSchema ?
_defaultSchemaSettings.value(schemaKey + QStringLiteral("/FallbackSchema")).toString() :
QSettings().value(schemaKey + QStringLiteral("/FallbackSchema")).toString();

if (!fallbackSchemaKey.isEmpty()) {
value = getSchemaValue(key, defaultValue, fallbackSchemaKey);
}
}

return value;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/utils/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ namespace Utils {
QStringList getSchemaKeys(const QString& schema) const;

QVariant getSchemaValue(const QString& key,
const QVariant& defaultValue = QVariant()) const;
const QVariant& defaultValue = QVariant(),
QString schemaKey = QString()) const;
QColor getForegroundColor(int index) const;
QColor getBackgroundColor(int index) const;

Expand Down

0 comments on commit 05f42a9

Please sign in to comment.