// 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 #include "pysidequickregistertype.h" #include #include #include #include #include #if QT_CONFIG(opengl) || QT_CONFIG(opengles2) || QT_CONFIG(opengles3) # include #endif bool pyTypeObjectInheritsFromClass(PyTypeObject *pyObjType, const char *classPtrName) { PyTypeObject *classPyType = Shiboken::Conversions::getPythonTypeObject(classPtrName); bool isDerived = PySequence_Contains(pyObjType->tp_mro, reinterpret_cast(classPyType)); return isDerived; } template bool registerTypeIfInheritsFromClass(const char *classPtrName, PyTypeObject *typeToRegister, QQmlPrivate::RegisterTypeAndRevisions *type) { if (!pyTypeObjectInheritsFromClass(typeToRegister, classPtrName)) return false; type->parserStatusCast = QQmlPrivate::StaticCastSelector::cast(); type->valueSourceCast = QQmlPrivate::StaticCastSelector::cast(); type->valueInterceptorCast = QQmlPrivate::StaticCastSelector::cast(); return true; } bool quickRegisterType(PyObject *pyObj, QQmlPrivate::RegisterTypeAndRevisions *type) { using namespace Shiboken; PyTypeObject *pyObjType = reinterpret_cast(pyObj); PyTypeObject *qQuickItemPyType = Shiboken::Conversions::getPythonTypeObject("QQuickItem*"); bool isQuickItem = PySequence_Contains(pyObjType->tp_mro, reinterpret_cast(qQuickItemPyType)); // Register only classes that inherit QQuickItem or its children. if (!isQuickItem) return false; return registerTypeIfInheritsFromClass("QQuickPaintedItem*", pyObjType, type) #if QT_CONFIG(opengl) || QT_CONFIG(opengles2) || QT_CONFIG(opengles3) || registerTypeIfInheritsFromClass("QQuickFramebufferObject*", pyObjType, type) #endif || registerTypeIfInheritsFromClass("QQuickItem*", pyObjType, type); } void PySide::initQuickSupport(PyObject *module) { Q_UNUSED(module); // We need to manually register a pointer version of these types in order for them to be used as property types. qRegisterMetaType("QQuickPaintedItem*"); #if QT_CONFIG(opengl) || QT_CONFIG(opengles2) || QT_CONFIG(opengles3) qRegisterMetaType("QQuickFramebufferObject*"); #endif qRegisterMetaType("QQuickItem*"); Qml::setQuickRegisterItemFunction(quickRegisterType); }