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.
- Doxygen : To generate the documentation.
- DoxygenBootstrapped : Integrate doxygen with CMake. v1.3.2.
- The documentation can be found here
1.0.0: Initial work1.1.0: Reset functions
- Class attribute are
_<property>. - Getter and Setter are
Get<Property>,Set<Property>. - Reset are
Reset<Property>. - Signals are
<property>Changed.
-
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_PROPERTYexcept 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 theQSUPERMACROS_USE_QT_GETTERSflag in QMake or QBS or CMake.The same for setters that are named
Set<PropertyName>. With the flagQSUPERMACROS_USE_QT_SETTERSthe will be set asset<PropertyName>.Same for signals they are default to
<PropertyName>Changed. With the flagQSUPERMACROS_USE_QT_SIGNALSthe 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 setQSUPERMACROS_USE_QT_PREFIXtomto have a more Qt-ish naming convention.
It is possible to set a default value for the attribute by using the macros <MACROS>_WDEFAULT.
QSM_LIST_PROPERTY: a really handy macro to create a QML list property that maps to an internalQListof objects, without having to declare and implement all static function pointers...
QSM_ENUM_CLASS: a macro to declare aQObjectclass that only contains aQ_ENUMand can be exposed as is to QML.
QSM_SINGLETON_PROPERTY: Macros to generate Singleton properties without the need to handle the factory.
git clone https://github.com/OlivierLDff/QSuperMacros
cd QSuperMacros && mkdir build && cd build
cmake -DQT_DIR="path/to/Qt/toolchain" -DQSUPERMACROS_BUILD_SHARED=ON -DQSUPERMACROS_USE_NAMESPACE=ON -DQSUPERMACROS_BUILD_DOC=ON ..
make- QSUPERMACROS_TARGET : Name of the library target. Default : "QSuperMacros"
- QSUPERMACROS_PROJECT : Name of the project. Default : "QSuperMacros"
- QSUPERMACROS_BUILD_SHARED : Build shared library [ON OFF]. Default: OFF.
- QSUPERMACROS_BUILD_STATIC : Build static library [ON OFF]. Default: ON.
- QSUPERMACROS_USE_NAMESPACE : If the library compile with a namespace [ON OFF]. Default: ON.
- QSUPERMACROS_NAMESPACE : Namespace for the library. Only relevant if QSUPERMACROS_USE_NAMESPACE is ON. Default: "Qsm".
- QSUPERMACROS_BUILD_DOC : Build the QSuperMacros Doc [ON OFF]. Default: OFF.
- QSUPERMACROS_USE_QT_PREFIX : Use Qt-ish internal attribute prefix
m_attribute[ON OFF]. Default = OFF. - QSUPERMACROS_USE_QT_GETTERS : Use Qt-ish Getter naming convention
attribute()[ON OFF]. Default = OFF. - QSUPERMACROS_USE_QT_SETTERS : Use Qt-ish Setter naming convention
setAttribute[ON OFF]. Default = OFF. - QSUPERMACROS_USE_QT_RESETS : Use Qt-ish Setter naming convention resetAttribute [ON OFF]. Default = OFF.
- QSUPERMACROS_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.
- QSUPERMACROS_DOXYGEN_BT_REPOSITORY : Repository of DoxygenBt. Default : "https://github.com/OlivierLDff/DoxygenBootstrapped.git"
- QSUPERMACROS_DOXYGEN_BT_TAG : Git Tag of DoxygenBt. Default : "v1.3.2"
- QSUPERMACROS_TARGET : Output target to link to.
- QSUPERMACROS_VERSION : Current version of the library
The main goal of this CMake project is to big included into another CMake project.
SET( QSUPERMACROS_TARGET QSuperMacros )
SET( QSUPERMACROS_PROJECT QSuperMacros )
SET( QSUPERMACROS_BUILD_SHARED OFF )
SET( QSUPERMACROS_BUILD_STATIC ON )
SET( QSUPERMACROS_BUILD_DOC OFF )
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/path/to/QSuperMacros ${CMAKE_CURRENT_BINARY_DIR}/QSuperMacros_Build)It is also possible to download the repository with the scripts inside cmake/. folder Simply call BuildQSuperMacros.cmake.
You will need:
DownloadProject.cmakeDownloadProject.CMakeLists.cmake.inBuildQSuperMacros.cmake
SET( QSUPERMACROS_TARGET QSuperMacros )
SET( QSUPERMACROS_PROJECT QSuperMacros )
SET( QSUPERMACROS_BUILD_SHARED OFF )
SET( QSUPERMACROS_BUILD_STATIC ON )
SET( QSUPERMACROS_BUILD_DOC OFF )
SET( QSUPERMACROS_USE_NAMESPACE ON )
SET( QSUPERMACROS_REPOSITORY "https://github.com/OlivierLDff/QSuperMacros.git" )
SET( QSUPERMACROS_TAG v1.0.1 )
INCLUDE(path/to/BuildQSuperMacros.cmake)NOTE : If you want to donate to Thomas Boutroue, use this link :
