aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-18 21:45:52 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-19 22:03:57 +0100
commitddab4c862af610417eeb8e1510f3ff20aaa9d57c (patch)
treeb059430531aa9d79ae7b756fa866bc154a2ebbce
parentdb4d44aa0fb321179bc08d7fd12d2b27c0b682dc (diff)
Decouple pysidequickregistertype.cpp from the generated wrapper classes
The registering code determined the size of the generated wrapper class by using sizeof() on them. Replace that by PySide::getSizeOfQObject() as is done in pysideqmlregistertype.cpp. Remove the macro PY_REGISTER_IF_INHERITS_FROM. With that, the code can be moved into a library. Task-number: PYSIDE-1709 Change-Id: Id000a9afec8e94294d92a9d7c6e01fd4d2bf4c37 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r--sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp55
1 files changed, 26 insertions, 29 deletions
diff --git a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp
index df16b1162..6329dd73b 100644
--- a/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp
+++ b/sources/pyside6/PySide6/QtQuick/pysidequickregistertype.cpp
@@ -43,15 +43,12 @@
#include <pyside_p.h>
#include <shiboken.h>
+#include <QtQuick/QQuickPaintedItem>
+#include <QtQuick/QQuickFramebufferObject>
+
#include <QtQml/private/qqmlmetatype_p.h>
-// Auto generated headers.
-#include "qquickitem_wrapper.h"
-#include "qquickpainteditem_wrapper.h"
-#include "qquickframebufferobject_wrapper.h"
-#include "pyside6_qtcore_python.h"
-#include "pyside6_qtquick_python.h"
-#include "pyside6_qtqml_python.h"
+#include <QtCore/QMutex>
// Mutex used to avoid race condition on PySide::nextQObjectMemoryAddr.
static QMutex nextQmlElementMutex;
@@ -67,12 +64,6 @@ static void createQuickItem(void *memory, void *type)
PySide::setNextQObjectMemoryAddr(0);
}
-#define PY_REGISTER_IF_INHERITS_FROM(className, typeToRegister,typePointerName, \
- typeListName, typeMetaObject, type, registered) \
- registerTypeIfInheritsFromClass<className##Wrapper>(#className, typeToRegister, \
- typePointerName, typeListName, \
- typeMetaObject, type, registered)
-
bool pyTypeObjectInheritsFromClass(PyTypeObject *pyObjType, QByteArray className)
{
className.append('*');
@@ -98,9 +89,9 @@ struct QPysideQmlMetaTypeInterface : public QQmlMetaTypeInterface
}
};
-template <class WrapperClass>
+template <class WrappedClass>
void registerTypeIfInheritsFromClass(
- QByteArray className,
+ const QByteArray &className,
PyTypeObject *typeToRegister,
const QByteArray &typePointerName,
const QByteArray &typeListName,
@@ -111,22 +102,24 @@ void registerTypeIfInheritsFromClass(
bool shouldRegister = !registered && pyTypeObjectInheritsFromClass(typeToRegister, className);
if (shouldRegister) {
- QMetaType ptrType(new QPysideQmlMetaTypeInterface<WrapperClass *>(typePointerName, typeMetaObject));
+ QMetaType ptrType(new QPysideQmlMetaTypeInterface<WrappedClass *>(typePointerName, typeMetaObject));
- QMetaType lstType(new QQmlListMetaTypeInterface(typeListName, static_cast<QQmlListProperty<WrapperClass>*>(nullptr), ptrType.iface()));
+ QMetaType lstType(new QQmlListMetaTypeInterface(typeListName, static_cast<QQmlListProperty<WrappedClass>*>(nullptr), ptrType.iface()));
type->typeId = std::move(ptrType);
type->listId = std::move(lstType);
- type->attachedPropertiesFunction = QQmlPrivate::attachedPropertiesFunc<WrapperClass>();
+ type->attachedPropertiesFunction = QQmlPrivate::attachedPropertiesFunc<WrappedClass>();
type->attachedPropertiesMetaObject =
- QQmlPrivate::attachedPropertiesMetaObject<WrapperClass>();
+ QQmlPrivate::attachedPropertiesMetaObject<WrappedClass>();
type->parserStatusCast =
- QQmlPrivate::StaticCastSelector<WrapperClass, QQmlParserStatus>::cast();
+ QQmlPrivate::StaticCastSelector<WrappedClass, QQmlParserStatus>::cast();
type->valueSourceCast =
- QQmlPrivate::StaticCastSelector<WrapperClass, QQmlPropertyValueSource>::cast();
+ QQmlPrivate::StaticCastSelector<WrappedClass, QQmlPropertyValueSource>::cast();
type->valueInterceptorCast =
- QQmlPrivate::StaticCastSelector<WrapperClass, QQmlPropertyValueInterceptor>::cast();
- type->objectSize = sizeof(WrapperClass);
+ QQmlPrivate::StaticCastSelector<WrappedClass, QQmlPropertyValueInterceptor>::cast();
+ // Pass the size of the generated wrapper class (larger than the plain
+ // Qt class due to virtual method cache) since that is what is instantiated.
+ type->objectSize = int(PySide::getSizeOfQObject(typeToRegister));
registered = true;
}
}
@@ -163,12 +156,16 @@ bool quickRegisterType(PyObject *pyObj, const char *uri, int versionMajor, int v
listName.append('>');
bool registered = false;
- PY_REGISTER_IF_INHERITS_FROM(QQuickPaintedItem, pyObjType, pointerName, listName, metaObject,
- type, registered);
- PY_REGISTER_IF_INHERITS_FROM(QQuickFramebufferObject, pyObjType, pointerName, listName,
- metaObject, type, registered);
- PY_REGISTER_IF_INHERITS_FROM(QQuickItem, pyObjType, pointerName, listName, metaObject,
- type, registered);
+ // Pass the size of the generated wrapper class since that is what is instantiated.
+ registerTypeIfInheritsFromClass<QQuickPaintedItem>(
+ "QQuickPaintedItem", pyObjType, pointerName, listName,
+ metaObject, type, registered);
+ registerTypeIfInheritsFromClass<QQuickFramebufferObject>(
+ "QQuickFramebufferObject", pyObjType, pointerName, listName,
+ metaObject, type, registered);
+ registerTypeIfInheritsFromClass<QQuickItem>(
+ "QQuickItem", pyObjType, pointerName, listName,
+ metaObject, type, registered);
if (!registered)
return false;