aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpysideqml
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-02-28 10:33:36 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-02-28 16:27:50 +0100
commitf017d4abe8199e203a5e625738d312932804601d (patch)
tree51932b873bbc7577a1ae7803076c3ada43842f50 /sources/pyside6/libpysideqml
parent9ef3c0041c489bd9f939c45a571026c3e2227685 (diff)
Implement QQmlPropertyValueSource
As is done with the other interfaces, add a class QPyQmlPropertyValueSource inheriting from QObject and QQmlPropertyValueSource. Store its offset in QQmlPrivate::RegisterType::valueSourceCast if it is found as a base class. [ChangeLog][PySide6] class QPyQmlPropertyValueSource for implementing QML value sources for properties has been added. Task-number: PYSIDE-1709 Change-Id: Icd1bd57972f339f9839ccd8d9bf6ff9e5e16ec62 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/libpysideqml')
-rw-r--r--sources/pyside6/libpysideqml/pysideqmlregistertype.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
index e935b5627..ad839ec96 100644
--- a/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
+++ b/sources/pyside6/libpysideqml/pysideqmlregistertype.cpp
@@ -98,6 +98,16 @@ static PyTypeObject *qQJSValueType()
return result;
}
+// Check if o inherits from QPyQmlPropertyValueSource.
+static bool isQmlPropertyValueSource(const QMetaObject *o)
+{
+ for (auto *base = o->superClass(); base ; base = base->superClass()) {
+ if (qstrcmp(base->className(), "QPyQmlPropertyValueSource") == 0)
+ return true;
+ }
+ return false;
+}
+
namespace PySide::Qml {
int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor,
@@ -146,8 +156,13 @@ int qmlRegisterType(PyObject *pyObj, const char *uri, int versionMajor,
type.parserStatusCast =
QQmlPrivate::StaticCastSelector<QObject, QQmlParserStatus>::cast();
- type.valueSourceCast =
- QQmlPrivate::StaticCastSelector<QObject, QQmlPropertyValueSource>::cast();
+ // QPyQmlPropertyValueSource inherits QObject, QmlPropertyValueSource, so,
+ // it is found behind the QObject. The size of a plain QObject is
+ // the wrapper size - 8 bools from the method cache array.
+ const int qObjectSize = int(PySide::getSizeOfQObject(qobjectType)) - 8;
+ type.valueSourceCast = isQmlPropertyValueSource(metaObject)
+ ? qObjectSize
+ : QQmlPrivate::StaticCastSelector<QObject, QQmlPropertyValueSource>::cast();
type.valueInterceptorCast =
QQmlPrivate::StaticCastSelector<QObject, QQmlPropertyValueInterceptor>::cast();