From 31cc1b382fbcd77def12cd0ad4fe9fc0fabdf60b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 11 Jan 2010 11:01:18 +1000 Subject: Correctly determine QScriptValue::isQObject() for QObjects using the QScriptDeclarativeClass. Task-number: QTBUG-6178 Reviewed-by: Kent Hansen Reviewed-by: Aaron Kennedy --- src/script/api/qscriptvalue.cpp | 12 ++++++++---- src/script/bridge/qscriptdeclarativeclass.cpp | 5 +++++ src/script/bridge/qscriptdeclarativeclass_p.h | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 286230f..b9be285 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -54,6 +54,7 @@ #include "bridge/qscriptvariant_p.h" #include "bridge/qscriptqobject_p.h" #include "bridge/qscriptdeclarativeclass_p.h" +#include "bridge/qscriptdeclarativeobject_p.h" /*! \since 4.3 @@ -1570,9 +1571,10 @@ QObject *QScriptValue::toQObject() const Q_D(const QScriptValue); if (isQObject()) { QScriptObject *object = static_cast(JSC::asObject(d->jscValue)); - return static_cast(object->delegate())->value(); - } else if (QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(*this)) { - return dc->toQObject(QScriptDeclarativeClass::object(*this)); + QScriptObjectDelegate *delegate = object->delegate(); + if (delegate->type() == QScriptObjectDelegate::DeclarativeClassObject) + return static_cast(delegate)->scriptClass()->toQObject(QScriptDeclarativeClass::object(*this)); + return static_cast(delegate)->value(); } else if (isVariant()) { QVariant var = toVariant(); int type = var.userType(); @@ -2245,7 +2247,9 @@ bool QScriptValue::isQObject() const return false; QScriptObject *object = static_cast(JSC::asObject(d->jscValue)); QScriptObjectDelegate *delegate = object->delegate(); - return (delegate && (delegate->type() == QScriptObjectDelegate::QtObject)); + return (delegate && (delegate->type() == QScriptObjectDelegate::QtObject || + (delegate->type() == QScriptObjectDelegate::DeclarativeClassObject && + static_cast(delegate)->scriptClass()->isQObject()))); } /*! diff --git a/src/script/bridge/qscriptdeclarativeclass.cpp b/src/script/bridge/qscriptdeclarativeclass.cpp index df00ce9..5e363d2 100644 --- a/src/script/bridge/qscriptdeclarativeclass.cpp +++ b/src/script/bridge/qscriptdeclarativeclass.cpp @@ -319,6 +319,11 @@ QStringList QScriptDeclarativeClass::propertyNames(Object *object) return QStringList(); } +bool QScriptDeclarativeClass::isQObject() const +{ + return false; +} + QObject *QScriptDeclarativeClass::toQObject(Object *, bool *ok) { if (ok) *ok = false; diff --git a/src/script/bridge/qscriptdeclarativeclass_p.h b/src/script/bridge/qscriptdeclarativeclass_p.h index 40e5051..f2557bd 100644 --- a/src/script/bridge/qscriptdeclarativeclass_p.h +++ b/src/script/bridge/qscriptdeclarativeclass_p.h @@ -97,6 +97,7 @@ public: virtual QStringList propertyNames(Object *); + virtual bool isQObject() const; virtual QObject *toQObject(Object *, bool *ok = 0); virtual QVariant toVariant(Object *, bool *ok = 0); -- cgit v0.12