From d46739294d04c72af1e434e414e1c012d7e78a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Tue, 4 Feb 2020 16:03:52 +0100 Subject: Add an isImmutable to know if a property is immutable Summary: Add a utility function isImmutable 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 --- src/kconfig_compiler/kconfig_compiler.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/kconfig_compiler/kconfig_compiler.cpp') diff --git a/src/kconfig_compiler/kconfig_compiler.cpp b/src/kconfig_compiler/kconfig_compiler.cpp index 11becf5c..989e2609 100644 --- a/src/kconfig_compiler/kconfig_compiler.cpp +++ b/src/kconfig_compiler/kconfig_compiler.cpp @@ -154,6 +154,18 @@ QString getFunction(const QString &n, const QString &className) return result; } +QString immutableFunction(const QString &n, const QString &className) +{ + QString result = QLatin1String("is") + n; + result[2] = result[2].toUpper(); + result += "Immutable"; + + if (!className.isEmpty()) { + result = className + QLatin1String("::") + result; + } + return result; +} + void addQuotes(QString &s) { if (!s.startsWith(QLatin1Char('"'))) { -- cgit v1.2.1