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 --- autotests/kconfig_compiler/test_notifiers.h.ref | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'autotests/kconfig_compiler/test_notifiers.h.ref') diff --git a/autotests/kconfig_compiler/test_notifiers.h.ref b/autotests/kconfig_compiler/test_notifiers.h.ref index 588427e2..6d73b7d0 100644 --- a/autotests/kconfig_compiler/test_notifiers.h.ref +++ b/autotests/kconfig_compiler/test_notifiers.h.ref @@ -19,7 +19,7 @@ class TestNotifiers : public KConfigSkeleton */ void setColor( const QColor & v ) { - if (!isImmutable( QStringLiteral( "Color" ) )) + if (!isColorImmutable()) mColor = v; } @@ -31,12 +31,20 @@ class TestNotifiers : public KConfigSkeleton return mColor; } + /** + Is Block colors. Immutable + */ + bool isColorImmutable() const + { + return isImmutable( QStringLiteral( "Color" ) ); + } + /** Set foo bar */ void setFooBar( const QString & v ) { - if (!isImmutable( QStringLiteral( "FooBar" ) )) + if (!isFooBarImmutable()) mFooBar = v; } @@ -48,6 +56,14 @@ class TestNotifiers : public KConfigSkeleton return mFooBar; } + /** + Is foo bar Immutable + */ + bool isFooBarImmutable() const + { + return isImmutable( QStringLiteral( "FooBar" ) ); + } + /** Set Age */ @@ -65,7 +81,7 @@ class TestNotifiers : public KConfigSkeleton v = 88; } - if (!isImmutable( QStringLiteral( "Age" ) )) + if (!isAgeImmutable()) mAge = v; } @@ -77,6 +93,14 @@ class TestNotifiers : public KConfigSkeleton return mAge; } + /** + Is Age Immutable + */ + bool isAgeImmutable() const + { + return isImmutable( QStringLiteral( "Age" ) ); + } + protected: int mParamNumber; -- cgit v1.2.1