Two quick ideas to make working with properties faster, easier and more consistent:
First – integrate Q_PROPERTY support in Creator to automatically generate header declarations and cpp definitions for the property accessors. Pretty straightforward, saves some typing and helps avoid potential typos.
Second – standardize a naming convention for Q_PROPERTY accessor methods. Saves some more typing and enforces a fixed naming convention so you never really have to ever check how is a particular accessor named. Naturally, this means the actual accessors, singals and data types can and should be automatically generated.
So instead of:
Q_PROPERTY(int number READ number WRITE setNumber RESET resetNumber NOTIFY numberChanged)
you simply:
Q_PROPERTY(int number READ WRITE RESET NOTIFY)
The convention – rather simple and intuitive – so enforcing it should rise no problems and will ensure consistency and faster workflow
the READ method shall always be (property) name
the WRITE method shall always be setName (camel case)
the RESET method shall always be resetName
the NOTIFY method shall always be nameChanged
the property member shall always be m_name
Stuff like property revisioning, scriptable and so on should still be specified, since those appear to be rarely used and mostly relying on property defaults.
The two suggestions combined together should make for a considerable improvement when working with properties, which are pretty much mandatory for extending both C++ and QtQuick APIs in Qt.
Also, if backward compatibility is an issue, the Q_PROPERTY macro should remain the same and a new macro should be introduced to handle the automatic name generation.
↧