diff options
author | Méven Car <meven.car@enioka.com> | 2020-02-04 16:03:52 +0100 |
---|---|---|
committer | Méven Car <meven29@gmail.com> | 2020-02-04 16:09:29 +0100 |
commit | d46739294d04c72af1e434e414e1c012d7e78a42 (patch) | |
tree | 5a227069a6a1a110cc26b788ff8a3bd99005735e /src/kconfig_compiler/KConfigCodeGeneratorBase.cpp | |
parent | fd0e26ddb49122fa55bdc8f35e189c832cc138ad (diff) | |
download | kconfig-d46739294d04c72af1e434e414e1c012d7e78a42.tar.gz kconfig-d46739294d04c72af1e434e414e1c012d7e78a42.tar.bz2 |
Add an is<PropertyName>Immutable to know if a property is immutable
Summary:
Add a utility function is<Parameter>Immutable to access immutability quickly.
Generated classes uses them internally to avoid code redundance.
Sample:
```
/**
Set blocked-by-default
*/
void setBlockedByDefault( bool v )
{
if (v != mBlockedByDefault && !isBlockedByDefaultImmutable() ) {
mBlockedByDefault = v;
Q_EMIT blockedByDefaultChanged();
}
}
/**
Is blocked-by-default Immutable
*/
bool isBlockedByDefaultImmutable()
{
return isImmutable( QStringLiteral( "blockedByDefault" ) );
}
```
```
/**
Set org.kde.ActivityManager.ResourceScoringEnabled
*/
void setResourceScoringEnabled( bool v )
{
if (!isResourceScoringEnabledImmutable() )
mResourceScoringEnabled = v;
}
/**
Is org.kde.ActivityManager.ResourceScoringEnabled Immutable
*/
bool isResourceScoringEnabledImmutable()
{
return isImmutable( QStringLiteral( "resourceScoringEnabled" ) );
}
```
Reviewers: ervin, #frameworks, dfaure
Reviewed By: ervin
Subscribers: dfaure, tcanabrava, kde-frameworks-devel
Tags: #frameworks
Differential Revision: https://phabricator.kde.org/D26368
Diffstat (limited to 'src/kconfig_compiler/KConfigCodeGeneratorBase.cpp')
-rw-r--r-- | src/kconfig_compiler/KConfigCodeGeneratorBase.cpp | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp index 5a110b2e..239c906c 100644 --- a/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp +++ b/src/kconfig_compiler/KConfigCodeGeneratorBase.cpp @@ -184,39 +184,51 @@ QString KConfigCodeGeneratorBase::memberAccessorBody(const CfgEntry *e, bool glo return result; } -void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression) +void KConfigCodeGeneratorBase::memberImmutableBody(const CfgEntry *e, bool globalEnums) { - const QString n = e->name; - const QString t = e->type; - const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties; + QString n = e->name; + QString t = e->type; - m_stream << whitespace() << "if ("; - if (hasBody) { - m_stream << "v != " << varExpression << " && "; - } - m_stream << "!" << m_this << "isImmutable( QStringLiteral( \""; + stream() << whitespace() << "return " << m_this << "isImmutable( QStringLiteral( \""; if (!e->param.isEmpty()) { - QString paramName = e->paramName; - - m_stream << paramName.replace(QStringLiteral("$(") + e->param + QStringLiteral(")"), QLatin1String("%1")) << "\" ).arg( "; + stream() << QString(e->paramName).replace(QLatin1String("$(") + e->param + QLatin1Char(')'), QLatin1String("%1")) << "\" ).arg( "; if (e->paramType == QLatin1String("Enum")) { - m_stream << "QLatin1String( "; + stream() << "QLatin1String( "; - if (m_cfg.globalEnums) { - m_stream << enumName(e->param) << "ToString[i]"; + if (globalEnums) { + stream() << enumName(e->param) << "ToString[i]"; } else { - m_stream << enumName(e->param) << "::enumToString[i]"; + stream() << enumName(e->param) << "::enumToString[i]"; } - m_stream << " )"; + stream() << " )"; } else { - m_stream << "i"; + stream() << "i"; } - m_stream << " )"; + stream() << " )"; } else { - m_stream << n << "\" )"; + stream() << n << "\" )"; + } + stream() << " );" << endl; +} + +void KConfigCodeGeneratorBase::createIfSetLogic(const CfgEntry *e, const QString &varExpression) +{ + const QString n = e->name; + const QString t = e->type; + const bool hasBody = !e->signalList.empty() || m_cfg.generateProperties; + + m_stream << whitespace() << "if ("; + if (hasBody) { + m_stream << "v != " << varExpression << " && "; + } + + const auto immutablefunction = immutableFunction(n, m_cfg.dpointer ? m_cfg.className : QString()); + m_stream << "!" << m_this << immutablefunction << "("; + if (!e->param.isEmpty()) { + m_stream << " i "; } - m_stream << " ))"; + m_stream << "))"; } void KConfigCodeGeneratorBase::memberMutatorBody(const CfgEntry *e) |