Skip to main content

attr: qpropgen.DESCRIPTION

Project description

qpropgen

A tool to generate QML-friendly QObject-based C++ classes from class definition files.

Quick Intro

Declaring properties in a QObject class can be tedious: there is quite a lot of boilerplate code to write. qpropgen goal is to write this boilerplate for you.

Suppose we want to create a Person class, with firstName, lastName and birthDate properties.

First we create a class definition file named person.yaml with the following content:

class: Person
properties:
    - name: firstName
      type: QString
    - name: lastName
      type: QString
    - name: birthDate
      type: QDateTime

Next, we generate its header and implementation with qpropgen person.yaml

Now we can use person.h and person.cpp in our code. The filenames are defined from 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 files

A class definition file must contain the following fields:

  • class: the name of the class to generate.

  • properties: the list of its properties (see below).

It may also contain the following fields:

  • includes: a list of files to include in the header.

  • baseClass: name of the class to inherit from. Defaults to QObject.

  • defaults: default values for some property attributes (see below).

The properties field

properties is an array of property definitions.

A property definition must contain the following fields:

  • type
  • name

It may contain the following fields:

  • access: Can be private or protected. Defines the access modifier for the generated member variables. Defaults to private.

  • mutability: One of constant, readonly, readwrite. Defaults to readwrite.

  • 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).

  • setterName: Name of the setter. Defaults to set<Name>, so the setter of a property named foo will be named setFoo.

  • varName: Name of the variable backing the property. Defaults to m<Name>, so the variable of a property named foo will be named mFoo.

  • impl: One of plain (getter and setter), virtual (virtual getter and setter) or pure (virtual pure getter and setter).

  • value: The default value of the property.

The defaults field

Adding a field to the defaults object lets you define default values for all properties.

For example you can define that all properties are of type qreal by default with:

defaults:
    type: qreal

Of course some fields like name should not have a default.

Build system integration

The cmake/qpropgen.cmake can be included in your project to integrate qpropgen in. It takes care of finding the qpropgen executable and provides a qpropgen() CMake function.

This CMake function lets you define .yaml files to process. For example:

set(prj_SRCS main.cpp)
qpropgen(prj_QPROPGEN foo.yaml bar.yaml)
add_executable(prj ${prj_SRCS} ${prj_QPROPGEN})

Examples

The examples/ 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.

Tests

The project currently lacks real unit tests, so the examples serve as tests: the ./tests.sh script can be run to build the examples.

Trivia

I started this project when I was working on the SFXR-Qt sound generator (a QtQuick port of SFXR), and was finding it too tedious to declare all the properties necessary to represent sounds :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qpropgen-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file qpropgen-0.1.0.tar.gz.

File metadata

  • Download URL: qpropgen-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for qpropgen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c51512e352f7caeccf26e2e50cb34a67af35294d7a9fd3e80de93e6fc2319e22
MD5 a8ada4fd4396961fb8ad87d1f424ad6d
BLAKE2b-256 aa80607bab06df5e63ee88ddd1e2250a8409e2f3b1a4e5bc1c09a19e8d5c08d0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page