diff options
author | Albert Astals Cid <albert.astals@canonical.com> | 2013-11-13 13:31:46 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-18 15:53:57 +0100 |
commit | 96ee6860163bba1e86b032c9c66cb893c666770a (patch) | |
tree | c2519c647f388a305a89d4463c6128da0e32fe3b /src | |
parent | 14518ca23766e407a31c2b5abaf8ba1d195a73d8 (diff) |
Make comparison of singletons and qobjects work
Otherwise you can end up with some weird situation in which you have
two objects, you print them and then you print the comparison and get
a Foo(0x858480) b Foo(0x858480) a == b false
Task-number: QTBUG-34651
Change-Id: Id2444d919f039be085eb5ed9112345db691540a5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 9 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper.cpp | 11 | ||||
-rw-r--r-- | src/qml/qml/qqmltypewrapper_p.h | 3 |
4 files changed, 26 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index ad3ebe5f0c..f1b0e0bdc4 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -646,6 +646,15 @@ void QObjectWrapper::setProperty(ExecutionContext *ctx, int propertyIndex, const return setProperty(m_object, ctx, property, value); } +bool QObjectWrapper::isEqualTo(Managed *a, Managed *b) +{ + QV4::QObjectWrapper *qobjectWrapper = a->as<QV4::QObjectWrapper>(); + if (QV4::QmlTypeWrapper *qmlTypeWrapper = b->asObject()->as<QV4::QmlTypeWrapper>()) + return qmlTypeWrapper->toVariant().value<QObject*>() == qobjectWrapper->object(); + + return false; +} + ReturnedValue QObjectWrapper::create(ExecutionEngine *engine, QQmlData *ddata, QObject *object) { QQmlEngine *qmlEngine = engine->v8Engine->engine(); diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h index 3a420abedb..a73c96d098 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper_p.h +++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h @@ -97,6 +97,9 @@ struct Q_QML_EXPORT QObjectWrapper : public QV4::Object ReturnedValue getProperty(ExecutionContext *ctx, int propertyIndex, bool captureRequired); void setProperty(ExecutionContext *ctx, int propertyIndex, const ValueRef value); +protected: + static bool isEqualTo(Managed *that, Managed *o); + private: ReturnedValue getProperty(ExecutionContext *ctx, QQmlPropertyData *property, bool captureRequired = true); static void setProperty(QObject *object, ExecutionContext *ctx, QQmlPropertyData *property, const ValueRef value); diff --git a/src/qml/qml/qqmltypewrapper.cpp b/src/qml/qml/qqmltypewrapper.cpp index 3fd39754e5..258442bc1d 100644 --- a/src/qml/qml/qqmltypewrapper.cpp +++ b/src/qml/qml/qqmltypewrapper.cpp @@ -286,4 +286,15 @@ void QmlTypeWrapper::destroy(Managed *that) static_cast<QmlTypeWrapper *>(that)->~QmlTypeWrapper(); } +bool QmlTypeWrapper::isEqualTo(Managed *a, Managed *b) +{ + QV4::QmlTypeWrapper *qmlTypeWrapperA = a->asObject()->as<QV4::QmlTypeWrapper>(); + if (QV4::QmlTypeWrapper *qmlTypeWrapperB = b->asObject()->as<QV4::QmlTypeWrapper>()) + return qmlTypeWrapperA->toVariant() == qmlTypeWrapperB->toVariant(); + else if (QV4::QObjectWrapper *qobjectWrapper = b->as<QV4::QObjectWrapper>()) + return qmlTypeWrapperA->toVariant().value<QObject*>() == qobjectWrapper->object(); + + return false; +} + QT_END_NAMESPACE diff --git a/src/qml/qml/qqmltypewrapper_p.h b/src/qml/qml/qqmltypewrapper_p.h index 89f31d675a..ee462d6479 100644 --- a/src/qml/qml/qqmltypewrapper_p.h +++ b/src/qml/qml/qqmltypewrapper_p.h @@ -89,6 +89,9 @@ public: static PropertyAttributes query(const Managed *, StringRef name); static void destroy(Managed *that); +protected: + static bool isEqualTo(Managed *that, Managed *o); + private: QV8Engine *v8; TypeNameMode mode; |