summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/script/api/qscriptengine.cpp14
-rw-r--r--src/script/bridge/qscriptqobject.cpp5
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp3
-rw-r--r--tests/auto/qscriptqwidgets/qscriptqwidgets.pro12
-rw-r--r--tests/auto/qscriptqwidgets/tst_qscriptqwidgets.cpp144
6 files changed, 165 insertions, 14 deletions
diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp
index 9965b3a..d96d11c 100644
--- a/src/script/api/qscriptengine.cpp
+++ b/src/script/api/qscriptengine.cpp
@@ -3130,7 +3130,6 @@ JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const
#endif
#ifndef QT_NO_QOBJECT
case QMetaType::QObjectStar:
- case QMetaType::QWidgetStar:
result = eng->newQObject(*reinterpret_cast<QObject* const *>(ptr));
break;
#endif
@@ -3138,6 +3137,11 @@ JSC::JSValue QScriptEnginePrivate::create(JSC::ExecState *exec, int type, const
result = eng->newVariant(*reinterpret_cast<const QVariant*>(ptr));
break;
default:
+ if (QMetaType::typeFlags(type) & QMetaType::PointerToQObject) {
+ result = eng->newQObject(*reinterpret_cast<QObject* const *>(ptr));
+ break;
+ }
+
if (type == qMetaTypeId<QScriptValue>()) {
result = eng->scriptValueToJSCValue(*reinterpret_cast<const QScriptValue*>(ptr));
if (!result)
@@ -3262,14 +3266,6 @@ bool QScriptEnginePrivate::convertValue(JSC::ExecState *exec, JSC::JSValue value
*reinterpret_cast<QObject* *>(ptr) = toQObject(exec, value);
return true;
} break;
- case QMetaType::QWidgetStar:
- if (isQObject(value) || value.isNull()) {
- QObject *qo = toQObject(exec, value);
- if (!qo || qo->isWidgetType()) {
- *reinterpret_cast<QWidget* *>(ptr) = reinterpret_cast<QWidget*>(qo);
- return true;
- }
- } break;
#endif
case QMetaType::QStringList:
if (isArray(value)) {
diff --git a/src/script/bridge/qscriptqobject.cpp b/src/script/bridge/qscriptqobject.cpp
index da1e0d6..e4da978 100644
--- a/src/script/bridge/qscriptqobject.cpp
+++ b/src/script/bridge/qscriptqobject.cpp
@@ -713,18 +713,17 @@ static JSC::JSValue delegateQtMethod(JSC::ExecState *exec, QMetaMethod::MethodTy
} else if (QScriptEnginePrivate::isQObject(actual)) {
switch (tid) {
case QMetaType::QObjectStar:
- case QMetaType::QWidgetStar:
// perfect
break;
default:
- matchDistance += 10;
+ if (!(QMetaType::typeFlags(tid) & QMetaType::PointerToQObject))
+ matchDistance += 10;
break;
}
} else if (actual.isNull()) {
switch (tid) {
case QMetaType::VoidStar:
case QMetaType::QObjectStar:
- case QMetaType::QWidgetStar:
// perfect
break;
default:
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 4175dca..b5936c0 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -14,6 +14,7 @@ SUBDIRS=\
qscriptvalue \
qscriptvaluegenerated \
qscriptvalueiterator \
+ qscriptqwidgets \
cmake \
# qtipc \
diff --git a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
index 9706901..c6fab3d 100644
--- a/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
+++ b/tests/auto/qscriptextqobject/tst_qscriptextqobject.cpp
@@ -1533,7 +1533,6 @@ void tst_QScriptExtQObject::callQtInvokable4()
QCOMPARE(m_myObject->qtFunctionInvoked(), 63);
QCOMPARE(m_myObject->qtFunctionActuals().size(), 1);
QVariant v = m_myObject->qtFunctionActuals().at(0);
- QCOMPARE(v.userType(), int(QMetaType::QWidgetStar));
QCOMPARE(qvariant_cast<QWidget*>(v), (QObject *)0);
}
@@ -1702,7 +1701,7 @@ void tst_QScriptExtQObject::callQtInvokable5()
{
QScriptValue ret = m_engine->evaluate("myObject.myInvokableReturningMyQObject()");
QCOMPARE(m_myObject->qtFunctionInvoked(), 53);
- QVERIFY(ret.isVariant());
+ QVERIFY(ret.isQObject());
QCOMPARE(*reinterpret_cast<MyQObject* const *>(ret.toVariant().constData()), m_myObject);
}
diff --git a/tests/auto/qscriptqwidgets/qscriptqwidgets.pro b/tests/auto/qscriptqwidgets/qscriptqwidgets.pro
new file mode 100644
index 0000000..4a2f763
--- /dev/null
+++ b/tests/auto/qscriptqwidgets/qscriptqwidgets.pro
@@ -0,0 +1,12 @@
+
+CONFIG += testcase
+
+TEMPLATE = app
+TARGET = tst_qscriptqwidgets
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT += widgets script testlib
+
+# Input
+SOURCES += tst_qscriptqwidgets.cpp
diff --git a/tests/auto/qscriptqwidgets/tst_qscriptqwidgets.cpp b/tests/auto/qscriptqwidgets/tst_qscriptqwidgets.cpp
new file mode 100644
index 0000000..f847d75
--- /dev/null
+++ b/tests/auto/qscriptqwidgets/tst_qscriptqwidgets.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Stephen Kelly <stephen.kelly@kdab.com>
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+#include <QWidget>
+#include <QScriptEngine>
+
+class CustomQObject : public QObject
+{
+ Q_OBJECT
+public:
+ CustomQObject(QObject *parent = 0)
+ : QObject(parent)
+ {
+
+ }
+};
+
+class tst_QScriptQWidgets : public QObject
+{
+ Q_OBJECT
+public:
+ explicit tst_QScriptQWidgets(QObject *parent = 0);
+ virtual ~tst_QScriptQWidgets();
+
+private slots:
+ void testProperty();
+ void testSlot();
+};
+
+tst_QScriptQWidgets::tst_QScriptQWidgets(QObject *parent)
+ : QObject(parent)
+{
+ qRegisterMetaType<QWidget*>();
+ qRegisterMetaType<CustomQObject*>();
+}
+
+tst_QScriptQWidgets::~tst_QScriptQWidgets()
+{
+
+}
+
+class ObjectUnderTest : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QWidget* widget READ widget CONSTANT)
+ Q_PROPERTY(CustomQObject* customObject READ customObject CONSTANT)
+public:
+ ObjectUnderTest(QObject *parent = 0)
+ : QObject(parent), m_widget(new QWidget), m_customObject(new CustomQObject)
+ {
+
+ }
+
+ QWidget* widget() const
+ {
+ return m_widget.data();
+ }
+
+ CustomQObject* customObject() const
+ {
+ return m_customObject.data();
+ }
+
+public slots:
+ QWidget* widgetAccessor() const
+ {
+ return m_widget.data();
+ }
+
+ QWidget* widgetReturner(QWidget* widget)
+ {
+ return widget;
+ }
+
+private:
+ QScopedPointer<QWidget> m_widget;
+ QScopedPointer<CustomQObject> m_customObject;
+};
+
+void tst_QScriptQWidgets::testProperty()
+{
+ QScriptEngine engine;
+ ObjectUnderTest *testObject = new ObjectUnderTest(this);
+ QCOMPARE(engine.newQObject(testObject).property("widget").toQObject(), testObject->widget());
+
+ QCOMPARE(engine.newQObject(testObject).property("customObject").toQObject(), testObject->customObject());
+}
+
+void tst_QScriptQWidgets::testSlot()
+{
+ {
+ QScriptEngine engine;
+ ObjectUnderTest *testObject = new ObjectUnderTest(this);
+ QCOMPARE(engine.newQObject(testObject).property("widgetAccessor").call(QScriptValue()).toQObject(), testObject->widget());
+ }
+ {
+ QScriptEngine engine;
+ ObjectUnderTest *testObject = new ObjectUnderTest(this);
+ QCOMPARE(engine.newQObject(testObject).property("widgetReturner").call(QScriptValue(), QScriptValueList() << engine.toScriptValue(testObject->widget())).toQObject(), testObject->widget());
+ }
+}
+
+QTEST_MAIN(tst_QScriptQWidgets)
+
+#include "tst_qscriptqwidgets.moc"