qqmlhelpers.cpp 2.75 KB
Newer Older
Renaud Guezennec's avatar
Renaud Guezennec committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "qqmlhelpers.h"

/*!
    \defgroup QT_QML_HELPERS Qt helper macros

    Brings a couple of macros that can help saving development time,
    by avoiding manual code duplication, often leading to heavy copy-and-paste,
    which is largely error-prone and not productive at all.
*/

/*!
    \def QML_WRITABLE_PROPERTY(type, name)
    \ingroup QT_QML_HELPERS
    \hideinitializer
    \details Creates a \c Q_PROPERTY that will be readable / writable from QML.

    \param type The C++ type of the property
    \param name The name for the property

    It generates for this goal :
    \code
        {type} m_{name}; // private member variable
        {type} get_{name} () const; // public getter method
        void set_{name} ({type}); // public setter slot
        void {name}Changed ({type}); // notifier signal
    \endcode

    \b Note : Any change from either C++ or QML side will trigger the notification.
*/

/*!
    \def QML_READONLY_PROPERTY(type, name)
    \ingroup QT_QML_HELPERS
    \hideinitializer
    \details Creates a \c Q_PROPERTY that will be readable from QML and writable from C++.

    \param type The C++ type of the property
    \param name The name for the property

    It generates for this goal :
    \code
        {type} m_{name}; // private member variable
        {type} get_{name} () const; // public getter method
        void update_{name} ({type}); // public setter method
        void {name}Changed ({type}); // notifier signal
    \endcode

    \b Note : Any change from C++ side will trigger the notification to QML.
*/

/*!
    \def QML_CONSTANT_PROPERTY(type, name)
    \ingroup QT_QML_HELPERS
    \hideinitializer
    \details Creates a \c Q_PROPERTY for a constant value exposed from C++ to QML.

    \param type The C++ type of the property
    \param name The name for the property

    It generates for this goal :
    \code
        {type} m_{name}; // private member variable
        {type} get_{name} () const; // public getter method
    \endcode

    \b Note : There is no change notifier because value is constant.
*/

/*!
    \def QML_ENUM_CLASS(name, ...)
    \ingroup QT_QML_HELPERS
    \hideinitializer
    \details Creates a class that contains a C++ enum that can be exposed to QML.

    \param name The name for the class
    \param ... The variadic list of values for the enum (comma-separated)

    It generates for this goal :
    \li The \c {name} C++ QObject-derived class
    \li The \c {name}::Type enumeration containing the values list
    \li The \c Q_ENUMS macro call to allow QML usage

    Example in use :
    \code
        QML_ENUM_CLASS (DaysOfWeek, Monday = 1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
    \endcode

    \b Note : The QML registration using \c qmlRegisterUncreatableType() will still be needed.
*/