A set of one-line C++ macros to simplify the creation of reccurent things (like Qt Meta Properties) so that doing them in C++ is not harder than in QML, and requires no boilerplate glue-code.
This fork aim is too add CMake support to this library. It also change the macros to match my naming convention.
Dependencies
- Doxygen : To generate the documentation.
- DoxygenBootstrapped : Integrate doxygen with CMake. v1.3.2.
API
- The documentation can be found here
Release
1.0.0
: Initial work1.1.0
: Reset functions
Convention
- Class attribute are
_<property>
. - Getter and Setter are
Get<Property>
,Set<Property>
. - Reset are
Reset<Property>
. - Signals are
<property>Changed
.
For one-line creation of QML properties
QSM_WRITABLE_***_PROPERTY
: a macro that takes a type and a name, and creates automatically the member attribute, the public getter and setter, and the Qt signal for notifier, and allow use in QML by exposing a read/writeQ_PROPERTY
.QSM_READONLY_***_PROPERTY
: another macro that does almost the same asQSM_WRITABLE_PROPERTY
except that the property is not modifiable from the QML side, only C++ can access the setter.QSM_CONSTANT_***_PROPERTY
: a simplified version of the previous macros, that exposes a constant property with no getter and no setter, from C++ or QML side.
The ***
can be either VAR
, PTR
, CSTREF
, or AUTO
. The three first are simple macros that you use by simply passing the non-qualified type (T
) and it'll add the qualifiers for var (none), pointer (*
), or constant-reference (const &
) where needed. The last one in the other hand, uses either T
or T*
and it's capable of adding constant-reference by deciding itself which type is the cheapest (using some template trickery internally).
INFO : by default, getters are named
Get<PropertyName>
, but if you want more Qt-compliant naming (no prefix) you can set theQSUPER_MACROS_USE_QT_GETTERS
flag in QMake or QBS or CMake.The same for setters that are named
Set<PropertyName>
. With the flagQSUPER_MACROS_USE_QT_SETTERS
the will be set asset<PropertyName>
.Same for signals they are default to
<PropertyName>Changed
. With the flagQSUPER_MACROS_USE_QT_SIGNALS
the will be set to<propertyName>Changed
. It is recommended for better to use the Qt-ish form of signals (they are default in CMake) because QML connections don't support signals starting with a Capital letter.The Prefix of member variable is default to nothing. So the attribute is
_attribute
. You can setQSUPER_MACROS_USE_QT_PREFIX
tom
to have a more Qt-ish naming convention.
Using default values for attribute
It is possible to set a default value for the attribute by using the macros <MACROS>_WDEFAULT
.
For easier QQmlListProperty from QList
QSM_LIST_PROPERTY
: a really handy macro to create a QML list property that maps to an internalQList
of objects, without having to declare and implement all static function pointers...
For simple enum class that can be used in C++ and QML
QSM_ENUM_CLASS
: a macro to declare aQObject
class that only contains aQ_ENUM
and can be exposed as is to QML.
For single property
QSM_SINGLETON_PROPERTY
: Macros to generate Singleton properties without the need to handle the factory.
CMake
Build
Input
- QSUPER_MACROS_TARGET : Name of the library target. Default : "QSuperMacros"
- QSUPER_MACROS_PROJECT : Name of the project. Default : "QSuperMacros"
- QSUPER_MACROS_BUILD_SHARED : Build shared library [ON OFF]. Default: OFF.
- QSUPER_MACROS_BUILD_STATIC : Build static library [ON OFF]. Default: ON.
- QSUPER_MACROS_USE_NAMESPACE : If the library compile with a namespace [ON OFF]. Default: OFF.
- QSUPER_MACROS_NAMESPACE : Namespace for the library. Only relevant if QSUPER_MACROS_USE_NAMESPACE is ON. Default: "Qsm".
- QSUPER_MACROS_BUILD_DOC : Build the QSuperMacros Doc [ON OFF]. Default: OFF.
Naming Convention
- QSUPER_MACROS_USE_QT_PREFIX : Use Qt-ish internal attribute prefix
m_attribute
[ON OFF]. Default = OFF. - QSUPER_MACROS_USE_QT_GETTERS : Use Qt-ish Getter naming convention
attribute()
[ON OFF]. Default = OFF. - QSUPER_MACROS_USE_QT_SETTERS : Use Qt-ish Setter naming convention
setAttribute
[ON OFF]. Default = OFF. - QSUPER_MACROS_USE_QT_RESET : Use Qt-ish Setter naming convention resetAttribute [ON OFF]. Default = OFF.
- QSUPER_MACROS_USE_QT_SIGNALS : Use Qt-ish signal naming convention
attributeChanged
. It is really recommended to leave this option ON because QML Connections don't handle signals starting with Capital Letter [ON OFF]. Default = ON.
Dependencies
- QSUPER_MACROS_DOXYGEN_BT_REPOSITORY : Repository of DoxygenBt. Default : "https://github.com/OlivierLDff/DoxygenBootstrapped.git"
- QSUPER_MACROS_DOXYGEN_BT_TAG : Git Tag of DoxygenBt. Default : "v1.3.2"
Output
- QSUPER_MACROS_TARGET : Output target to link to.
- QSUPER_MACROS_VERSION : Current version of the library
Integration in CMake project
The main goal of this CMake project is to big included into another CMake project.
It is also possible to download the repository with the scripts inside cmake/
. folder Simply call BuildQSuperMacros.cmake
.
You will need:
DownloadProject.cmake
DownloadProject.CMakeLists.cmake.in
BuildQSuperMacros.cmake
NOTE : If you want to donate to Thomas Boutroue, use this link :