Package: qpropgen
qpropgenA tool to generate QML-friendly QObject-based C++ classes from class definition
files.Install it with:pip install qpropgenQuick IntroDeclaring properties in a QObject class requires writing a lot of boilerplate
code. qpropgen goal is to write this boilerplate for you.Suppose we want to create aPersonclass, withfirstName,lastNameandbirthDateproperties.First we create a class definition file namedperson.yamlwith the following
content:class:Personproperties:-name:firstNametype:QString-name:lastNametype:QString-name:birthDatetype:QDateTimeNext, we generate its header and implementation withqpropgen person.yaml.
This produces two files:person.handperson.cpp(The filenames are based
on the filename of the class definition).Note: in practice, you probably want to inherit from the generated classes to
implement other aspects of the class to create and/or to override getters and
setters.Syntax of class definition filesA class definition filemustcontain the following fields:class: the name of the class to generate.properties: the list of its properties (see below).Itmayalso contain the following fields:includes: a list of files to include in the header.baseClass: name of the class to inherit from. Defaults toQObject.defaults: default values for some property attributes (see below).Thepropertiesfieldpropertiesis an array of property definitions.A property definitionmustcontain the following fields:typenameItmaycontain the following fields:access: Can beprivateorprotected. Defines the access modifier for
the generated member variables. Defaults toprivate.mutability: One ofconstant,readonly,readwrite. Defaults toreadwrite.argType: The type of the setter argument. If not set qpropgen uses const
references for types which are not pointers and not known scalars (int, bool,
qreal).varName: Name of the variable backing the property. Defaults tom<Name>,
so the variable of thefooproperty will bemFoo.setterName: Name of the setter. Defaults toset<Name>, so the setter of
thefooproperty will besetFoo.impl: One ofplain(getter and setter),virtual(virtual getter and
setter) orpure(virtual pure getter and setter).value: The default value of the property.ThedefaultsfieldAdding a field to thedefaultsobject lets you define default values for all
properties.For example you can define that all properties are of typeqrealby default
with:defaults:type:qrealOf course fields which require a unique value, likename, should not have a
default.Build system integrationThecmake/qpropgen.cmakecan be included in your project to integrate
qpropgen. It takes care of finding theqpropgenexecutable and provides aqpropgen()CMake function.This CMake function lets you define .yaml files to process. For example:set(prj_SRCSmain.cpp)qpropgen(prj_QPROPGENfoo.yamlbar.yaml)add_executable(prj${prj_SRCS}${prj_QPROPGEN})ExamplesTheexamples/directory contains examples of the various settings. The
produced executable does nothing, but you can look in the build directory at
the .h and .cpp files produced by qpropgen during the build.TestsThe project currently lacks real unit tests, so the examples serve as tests:
the./tests.shscript can be run to build the examples.TriviaI started this project when I was working on theSFXR-Qtsound generator (a
QtQuick port ofSFXR), and was finding it too tedious to declare all the
properties necessary to represent sounds :)