diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-10-17 14:23:35 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-11-04 13:49:39 +0000 |
commit | 4b9249dabf002e204298cfc3cd0e64e607905d54 (patch) | |
tree | 4c1d310ed9fac0de38db6b8672f98923878a96a0 /src/qml | |
parent | f9feaa20a8b8a875f9da5c8b561aca8bafd446ca (diff) |
Adjust to QPropertyBindingPrivate not using std::function anymore
Change-Id: Id197f3d4bf8ab60256040e0a177d5596ce78a0a8
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qqmlpropertybinding.cpp | 14 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertybinding_p.h | 39 |
2 files changed, 44 insertions, 9 deletions
diff --git a/src/qml/qml/qqmlpropertybinding.cpp b/src/qml/qml/qqmlpropertybinding.cpp index b691bf39a9..d56d41f834 100644 --- a/src/qml/qml/qqmlpropertybinding.cpp +++ b/src/qml/qml/qqmlpropertybinding.cpp @@ -63,12 +63,13 @@ QUntypedPropertyBinding QQmlPropertyBinding::create(const QQmlPropertyData *pd, QPropertyBindingSourceLocation()); } - auto binding = new QQmlPropertyBinding(QMetaType(pd->propType())); + auto buffer = new std::byte[sizeof(QQmlPropertyBinding)]; // QQmlPropertyBinding uses delete[] + auto binding = new (buffer) QQmlPropertyBinding(QMetaType(pd->propType())); binding->setNotifyOnValueChanged(true); binding->setContext(ctxt); binding->setScopeObject(obj); binding->setupFunction(scope, function); - return QUntypedPropertyBinding(QPropertyBindingPrivatePtr(binding).data()); + return QUntypedPropertyBinding(static_cast<QPropertyBindingPrivate *>(QPropertyBindingPrivatePtr(binding).data())); } void QQmlPropertyBinding::expressionChanged() @@ -89,15 +90,14 @@ void QQmlPropertyBinding::expressionChanged() m_error.setTag(currentTag); } -QQmlPropertyBinding::QQmlPropertyBinding(const QMetaType &mt) +QQmlPropertyBinding::QQmlPropertyBinding(QMetaType mt) : QPropertyBindingPrivate(mt, - [this](const QMetaType &metaType, void *dataPtr) -> bool { - return evaluate(metaType, dataPtr); - }, QPropertyBindingSourceLocation()) + &QtPrivate::bindingFunctionVTable<QQmlPropertyBinding>, + QPropertyBindingSourceLocation()) { } -bool QQmlPropertyBinding::evaluate(const QMetaType &metaType, void *dataPtr) +bool QQmlPropertyBinding::evaluate(QMetaType metaType, void *dataPtr) { const auto ctxt = context(); QQmlEngine *engine = ctxt ? ctxt->engine() : nullptr; diff --git a/src/qml/qml/qqmlpropertybinding_p.h b/src/qml/qml/qqmlpropertybinding_p.h index c3c684a753..1ea82b26be 100644 --- a/src/qml/qml/qqmlpropertybinding_p.h +++ b/src/qml/qml/qqmlpropertybinding_p.h @@ -63,19 +63,54 @@ QT_BEGIN_NAMESPACE class QQmlPropertyBinding : public QQmlJavaScriptExpression, public QPropertyBindingPrivate + { public: + static constexpr auto propertyBindingOffset() { + QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF + return offsetof(QQmlPropertyBinding, ref); + QT_WARNING_POP + } + static QUntypedPropertyBinding create(const QQmlPropertyData *pd, QV4::Function *function, QObject *obj, const QQmlRefPointer<QQmlContextData> &ctxt, QV4::ExecutionContext *scope); void expressionChanged() override; + + static bool doEvaluate(QMetaType metaType, QUntypedPropertyData *dataPtr, void *f) { + auto address = static_cast<std::byte*>(f); + address -= sizeof (QPropertyBindingPrivate); // f now points to QPropertyBindingPrivate suboject + address -= QQmlPropertyBinding::propertyBindingOffset(); // f now points to QQmlPropertyBinding + return reinterpret_cast<QQmlPropertyBinding *>(address)->evaluate(metaType, dataPtr); + } + private: - QQmlPropertyBinding(const QMetaType &metaType); + QQmlPropertyBinding(QMetaType metaType); + + bool evaluate(QMetaType metaType, void *dataPtr); + + +}; + +template <auto I> +struct Print {}; - bool evaluate(const QMetaType &metaType, void *dataPtr); +namespace QtPrivate { +template<> +inline constexpr BindingFunctionVTable bindingFunctionVTable<QQmlPropertyBinding> = { + &QQmlPropertyBinding::doEvaluate, + [](void *qpropertyBinding){ + auto address = static_cast<std::byte*>(qpropertyBinding); + address -= QQmlPropertyBinding::propertyBindingOffset(); // f now points to QQmlPropertyBinding + reinterpret_cast<QQmlPropertyBinding *>(address)->~QQmlPropertyBinding(); + delete[] address; + }, + [](void *, void *){}, + 0 }; +} class QQmlTranslationPropertyBinding { |