Add an is<PropertyName>Immutable to know if a property is immutable
ClosedPublic

Authored by meven on Jan 2 2020, 2:46 PM.

Details

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" ) );
}

Diff Detail

Repository
R237 KConfig
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
meven created this revision.Jan 2 2020, 2:46 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 2 2020, 2:46 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
meven requested review of this revision.Jan 2 2020, 2:46 PM
meven edited the summary of this revision. (Show Details)Jan 2 2020, 2:47 PM
ervin added a comment.Jan 29 2020, 9:17 AM

Now that the refactoring landed, what about rebasing this one?

meven added a comment.Jan 29 2020, 9:52 AM

Now that the refactoring landed, what about rebasing this one?

That's almost a complete rewrite ^^

ervin added a comment.Jan 29 2020, 9:58 AM

Now that the refactoring landed, what about rebasing this one?

That's almost a complete rewrite ^^

I guessed so. ;-)

meven updated this revision to Diff 74561.Jan 29 2020, 1:10 PM

Rebase & update tests

meven updated this revision to Diff 74563.Jan 29 2020, 1:12 PM

Clean unnecessary files

LGTM but lets' wait for a second pair of eyes. Mines are definitely not sharp today. :-)

@tcanabrava @dfaure, opinions?

I like it, but considering that this adds a new method, I'd like to see it exposed to Qml too o the generated code if GenerateProperties is set to true, currently we write this kind of code in Qml:

          enabled: !kcm.balooSettings.isImmutable("indexingEnabled")

something in the lines of `settings.indexingEnabledIsImmutable` would be of great help.

(I would go further and try to add a class for each property with a .isImmutable, .name, .value and so on but this is out of scope and *maybe* only for KF6.)

meven added a comment.Jan 29 2020, 3:05 PM

I like it, but considering that this adds a new method, I'd like to see it exposed to Qml too o the generated code if GenerateProperties is set to true, currently we write this kind of code in Qml:

          enabled: !kcm.balooSettings.isImmutable("indexingEnabled")
 
something in the lines of `settings.indexingEnabledIsImmutable` would be of great help.

That's what I had in mind. I am missing the Q_INVOKABLE, will add.

(I would go further and try to add a class for each property with a .isImmutable, .name, .value and so on but this is out of scope and *maybe* only for KF6.)

Let's see what Qt 6 reserves. That'd be very nice, quite expressive.

meven updated this revision to Diff 74582.Jan 29 2020, 3:14 PM

Allow the isImmutable to be invokable from Qml when generateProperties is set

meven updated this revision to Diff 74589.Jan 29 2020, 4:01 PM

Make isImmutable function constant PROPERTY when generateProperties is passed

it's a +1 for me. @dfaure and @ervin ?

ervin accepted this revision.Jan 31 2020, 10:44 AM
This revision is now accepted and ready to land.Jan 31 2020, 10:44 AM
meven added a reviewer: dfaure.Feb 3 2020, 8:50 AM
This revision was automatically updated to reflect the committed changes.