Use explicit flag values or explicit constructor instead of nullptr
ClosedPublic

Authored by kossebau on Jun 1 2017, 12:50 AM.

Details

Summary

The constructor of QFlags which was intended to handle literal "0"
as commonly used indicator of no-flags-set has been done with a
trick based on pointer types. Which these days of nullptr existing and
compilers pushing to use that sadly fired back and, instead of
allowing convenient code with commonly understood literal "0" values,
resulted in quite some code using "nullptr" to indicate a QFLags-based
type value with no flags set, which can be puzzling for humans
reading the code.

To improve the code again, instead of "nullptr" are used:

  • enum item representing the 0=no-flag-set value, if existing
  • explicit default constructor

Diff Detail

Repository
R278 KWindowSystem
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
kossebau created this revision.Jun 1 2017, 12:50 AM
Restricted Application added projects: Plasma, Frameworks. · View Herald TranscriptJun 1 2017, 12:50 AM
Restricted Application added subscribers: Frameworks, plasma-devel. · View Herald Transcript
kfunk accepted this revision.Jun 1 2017, 11:09 AM
This revision is now accepted and ready to land.Jun 1 2017, 11:09 AM
kossebau added a comment.EditedJun 1 2017, 6:15 PM

Checking the diff another time I find it would be even nicer to extend NET::Property, NET::Property2, NET::Action & Co. to have an entry for 0 value, named NoProperties, NoProperties2, NoActionFlags etc. (cmp. e.g. Qt::ItemFlags), so those enum values could be used instead of the default constructors.
Would both be more expressive and also more balanced when used next to other flag sets assembled by the enum values.

Something to consider for the future perhaps...

This revision was automatically updated to reflect the committed changes.