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/test5.h.ref | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'autotests/kconfig_compiler/test5.h.ref') diff --git a/autotests/kconfig_compiler/test5.h.ref b/autotests/kconfig_compiler/test5.h.ref index 07049cab..96e5c143 100644 --- a/autotests/kconfig_compiler/test5.h.ref +++ b/autotests/kconfig_compiler/test5.h.ref @@ -23,7 +23,7 @@ class Test5 : public KConfigSkeleton static void setColor( int i, const QColor & v ) { - if (!self()->isImmutable( QStringLiteral( "Color%1" ).arg( i ) )) + if (!self()->isColorImmutable( i )) self()->mColor[i] = v; } @@ -36,13 +36,22 @@ class Test5 : public KConfigSkeleton return self()->mColor[i]; } + /** + Is Block colors. Immutable + */ + static + bool isColorImmutable( int i ) + { + return self()->isImmutable( QStringLiteral( "Color%1" ).arg( i ) ); + } + /** Set Mouse actions. */ static void setMouseAction( int i, int v ) { - if (!self()->isImmutable( QStringLiteral( "MouseAction%1" ).arg( QLatin1String( EnumButtonToString[i] ) ) )) + if (!self()->isMouseActionImmutable( i )) self()->mMouseAction[i] = v; } @@ -55,13 +64,22 @@ class Test5 : public KConfigSkeleton return self()->mMouseAction[i]; } + /** + Is Mouse actions. Immutable + */ + static + bool isMouseActionImmutable( int i ) + { + return self()->isImmutable( QStringLiteral( "MouseAction%1" ).arg( QLatin1String( EnumButtonToString[i] ) ) ); + } + /** Set foo bar */ static void setFooBar( const QString & v ) { - if (!self()->isImmutable( QStringLiteral( "FooBar" ) )) + if (!self()->isFooBarImmutable()) self()->mFooBar = v; } @@ -74,6 +92,15 @@ class Test5 : public KConfigSkeleton return self()->mFooBar; } + /** + Is foo bar Immutable + */ + static + bool isFooBarImmutable() + { + return self()->isImmutable( QStringLiteral( "FooBar" ) ); + } + /** Set Age */ @@ -92,7 +119,7 @@ class Test5 : public KConfigSkeleton v = 88; } - if (!self()->isImmutable( QStringLiteral( "Age" ) )) + if (!self()->isAgeImmutable()) self()->mAge = v; } @@ -105,6 +132,15 @@ class Test5 : public KConfigSkeleton return self()->mAge; } + /** + Is Age Immutable + */ + static + bool isAgeImmutable() + { + return self()->isImmutable( QStringLiteral( "Age" ) ); + } + protected: Test5(QObject *parent = nullptr); friend class Test5Helper; -- cgit v1.2.1