aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml/pysideqmlregistertype.h
blob: 1e6c7d28d539f95e62b6eace6d7b18680a7830dd (plain)
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
90
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef PYSIDEQMLREGISTERTYPE_H
#define PYSIDEQMLREGISTERTYPE_H

#include "pysideqmlmacros.h"

#include <sbkpython.h>

namespace QQmlPrivate
{
struct RegisterType;
}

namespace PySide::Qml
{

/**
 * PySide implementation of qmlRegisterType<T> function.
 *
 * \param pyObj Python type to be registered.
 * \param uri QML element uri.
 * \param versionMajor QML component major version.
 * \param versionMinor QML component minor version.
 * \param qmlName QML element name
 * \return the metatype id of the registered type.
 */
PYSIDEQML_API int qmlRegisterType(PyObject *pyObj, const char *uri,
                                  int versionMajor, int versionMinor,
                                  const char *qmlName, const char *noCreationReason = nullptr,
                                  bool creatable = true);

/**
 * PySide implementation of qmlRegisterSingletonType<T> function.
 *
 * \param pyObj Python type to be registered.
 * \param uri QML element uri.
 * \param versionMajor QML component major version.
 * \param versionMinor QML component minor version.
 * \param qmlName QML element name
 * \param callback Registration callback
 * \return the metatype id of the registered type.
 */
PYSIDEQML_API int qmlRegisterSingletonType(PyObject *pyObj,const char *uri,
                                           int versionMajor, int versionMinor, const char *qmlName,
                                           PyObject *callback, bool isQObject, bool hasCallback);

/**
 * PySide implementation of qmlRegisterSingletonInstance<T> function.
 *
 * \param pyObj Python type to be registered.
 * \param uri QML element uri.
 * \param versionMajor QML component major version.
 * \param versionMinor QML component minor version.
 * \param qmlName QML element name
 * \param instanceObject singleton object to be registered.
 * \return the metatype id of the registered type.
 */
PYSIDEQML_API int qmlRegisterSingletonInstance(PyObject *pyObj, const char *uri,
                                               int versionMajor, int versionMinor,
                                               const char *qmlName, PyObject *instanceObject);

/**
 * PySide implementation of the QML_ELEMENT macro
 *
 * \param pyObj Python type to be registered
 */
PYSIDEQML_API PyObject *qmlElementMacro(PyObject *pyObj);

/// PySide implementation of the QML_ANONYMOUS macro
/// \param pyObj Python type to be registered
PYSIDEQML_API PyObject *qmlAnonymousMacro(PyObject *pyObj);

/// PySide implementation of the QML_SINGLETON macro
/// \param pyObj Python type to be registered
PYSIDEQML_API PyObject *qmlSingletonMacro(PyObject *pyObj);


// Used by QtQuick module to fill the QQmlPrivate::RegisterType::parserStatusCast,
// valueSourceCast and valueInterceptorCast fields with the correct values.
using QuickRegisterItemFunction =
    bool (*)(PyObject *pyObj, QQmlPrivate::RegisterType *);

PYSIDEQML_API QuickRegisterItemFunction getQuickRegisterItemFunction();
PYSIDEQML_API void setQuickRegisterItemFunction(QuickRegisterItemFunction function);

} // namespace PySide::Qml

#endif // PYSIDEQMLREGISTERTYPE_H