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/test1.h.ref | 90 ++++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 9 deletions(-) (limited to 'autotests/kconfig_compiler/test1.h.ref') diff --git a/autotests/kconfig_compiler/test1.h.ref b/autotests/kconfig_compiler/test1.h.ref index 52921ac6..24500176 100644 --- a/autotests/kconfig_compiler/test1.h.ref +++ b/autotests/kconfig_compiler/test1.h.ref @@ -26,7 +26,7 @@ class Test1 : public KConfigSkeleton */ void setOneOption( bool v ) { - if (!isImmutable( QStringLiteral( "OneOption" ) )) + if (!isOneOptionImmutable()) mOneOption = v; } @@ -38,12 +38,20 @@ class Test1 : public KConfigSkeleton return mOneOption; } + /** + Is One option Immutable + */ + bool isOneOptionImmutable() const + { + return isImmutable( QStringLiteral( "OneOption" ) ); + } + /** Set Another option */ void setAnotherOption( int v ) { - if (!isImmutable( QStringLiteral( "AnotherOption" ) )) + if (!isAnotherOptionImmutable()) mAnotherOption = v; } @@ -55,12 +63,20 @@ class Test1 : public KConfigSkeleton return mAnotherOption; } + /** + Is Another option Immutable + */ + bool isAnotherOptionImmutable() const + { + return isImmutable( QStringLiteral( "AnotherOption" ) ); + } + /** Set This is some funky option */ void setListOption( int v ) { - if (!isImmutable( QStringLiteral( "ListOption" ) )) + if (!isListOptionImmutable()) mListOption = v; } @@ -72,12 +88,20 @@ class Test1 : public KConfigSkeleton return mListOption; } + /** + Is This is some funky option Immutable + */ + bool isListOptionImmutable() const + { + return isImmutable( QStringLiteral( "ListOption" ) ); + } + /** Set This is a string */ void setMyString( const QString & v ) { - if (!isImmutable( QStringLiteral( "MyString" ) )) + if (!isMyStringImmutable()) mMyString = v; } @@ -89,12 +113,20 @@ class Test1 : public KConfigSkeleton return mMyString; } + /** + Is This is a string Immutable + */ + bool isMyStringImmutable() const + { + return isImmutable( QStringLiteral( "MyString" ) ); + } + /** Set This is a path */ void setMyPath( const QString & v ) { - if (!isImmutable( QStringLiteral( "MyPath" ) )) + if (!isMyPathImmutable()) mMyPath = v; } @@ -106,12 +138,20 @@ class Test1 : public KConfigSkeleton return mMyPath; } + /** + Is This is a path Immutable + */ + bool isMyPathImmutable() const + { + return isImmutable( QStringLiteral( "MyPath" ) ); + } + /** Set Another option */ void setAnotherOption2( int v ) { - if (!isImmutable( QStringLiteral( "AnotherOption2" ) )) + if (!isAnotherOption2Immutable()) mAnotherOption2 = v; } @@ -123,12 +163,20 @@ class Test1 : public KConfigSkeleton return mAnotherOption2; } + /** + Is Another option Immutable + */ + bool isAnotherOption2Immutable() const + { + return isImmutable( QStringLiteral( "AnotherOption2" ) ); + } + /** Set MyStringList */ void setMyStringList( const QStringList & v ) { - if (!isImmutable( QStringLiteral( "MyStringList" ) )) + if (!isMyStringListImmutable()) mMyStringList = v; } @@ -140,12 +188,20 @@ class Test1 : public KConfigSkeleton return mMyStringList; } + /** + Is MyStringList Immutable + */ + bool isMyStringListImmutable() const + { + return isImmutable( QStringLiteral( "MyStringList" ) ); + } + /** Set MyStringListHidden */ void setMyStringListHidden( const QStringList & v ) { - if (!isImmutable( QStringLiteral( "MyStringListHidden" ) )) + if (!isMyStringListHiddenImmutable()) mMyStringListHidden = v; } @@ -157,12 +213,20 @@ class Test1 : public KConfigSkeleton return mMyStringListHidden; } + /** + Is MyStringListHidden Immutable + */ + bool isMyStringListHiddenImmutable() const + { + return isImmutable( QStringLiteral( "MyStringListHidden" ) ); + } + /** Set List Number */ void setMyNumber( int v ) { - if (!isImmutable( QStringLiteral( "MyNumber" ) )) + if (!isMyNumberImmutable()) mMyNumber = v; } @@ -174,6 +238,14 @@ class Test1 : public KConfigSkeleton return mMyNumber; } + /** + Is List Number Immutable + */ + bool isMyNumberImmutable() const + { + return isImmutable( QStringLiteral( "MyNumber" ) ); + } + protected: QString mParamtransport; QString mParamfolder; -- cgit v1.2.1