aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpropertycache
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-11-02 15:53:02 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-11-19 08:25:32 +0000
commit3e9b752bf4114b2b06e2f8f65aad67606dfc0215 (patch)
treec5ab9351ad3bce5e66ce9429948dd00a1986dd01 /tests/auto/qml/qqmlpropertycache
parent75937c9da7910ce41b4b3207d66d844ed9624df8 (diff)
QML: Use all available type information to find enum types
Using the metatype system we can identify most enumeration types statically, without lookup by name. Only if we get UnknownType we have to do a name based lookup. As the name based lookup only checks enums that either belong to the global Qt namespace or the surrounding class, the type based lookup gives better results. Task-number: QTBUG-58454 Change-Id: Id6bd748f37838249defb4c5b2a7628eadc1a8341 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
-rw-r--r--tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml11
-rw-r--r--tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro4
-rw-r--r--tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp69
3 files changed, 83 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml
new file mode 100644
index 0000000000..7ceb231c8d
--- /dev/null
+++ b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml
@@ -0,0 +1,11 @@
+import QtQml 2.2
+import example 1.0
+
+QtObject {
+ Component.onCompleted: {
+ var opt1 = MyEnum.Option1A | MyEnum.Option1D // 0x09
+ mydata.opt1 = opt1;
+ mydata.setOpt1(opt1);
+ mydata.setOption1(opt1);
+ }
+}
diff --git a/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro b/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
index 9a04c899fe..26d41bbdbf 100644
--- a/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
+++ b/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
@@ -4,4 +4,8 @@ macx:CONFIG -= app_bundle
SOURCES += tst_qqmlpropertycache.cpp
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
QT += core-private gui-private qml-private testlib
diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
index 29f70c4e46..1c8e3c50ab 100644
--- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
+++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
@@ -29,12 +29,14 @@
#include <qtest.h>
#include <private/qqmlpropertycache_p.h>
#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlcomponent.h>
#include <private/qv8engine_p.h>
#include <private/qmetaobjectbuilder_p.h>
#include <QCryptographicHash>
#include "../../shared/util.h"
-class tst_qqmlpropertycache : public QObject
+class tst_qqmlpropertycache : public QQmlDataTest
{
Q_OBJECT
public:
@@ -47,6 +49,7 @@ private slots:
void methodsDerived();
void signalHandlers();
void signalHandlersDerived();
+ void passForeignEnums();
void metaObjectSize_data();
void metaObjectSize();
void metaObjectChecksum();
@@ -271,6 +274,70 @@ void tst_qqmlpropertycache::signalHandlersDerived()
QCOMPARE(data->coreIndex(), metaObject->indexOfMethod("propertyDChanged()"));
}
+class MyEnum : public QObject
+ {
+ Q_OBJECT
+ public:
+ enum Option1Flag {
+ Option10 = 0,
+ Option1A = 1,
+ Option1B = 2,
+ Option1C = 4,
+ Option1D = 8,
+ Option1E = 16,
+ Option1F = 32,
+ Option1AD = Option1A | Option1D,
+ };
+ Q_DECLARE_FLAGS(Option1, Option1Flag)
+ Q_FLAG(Option1)
+};
+
+class MyData : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(MyEnum::Option1 opt1 READ opt1 WRITE setOpt1 NOTIFY opt1Changed)
+public:
+ MyEnum::Option1 opt1() const { return m_opt1; }
+
+signals:
+ void opt1Changed(MyEnum::Option1 opt1);
+
+public slots:
+ void setOpt1(MyEnum::Option1 opt1)
+ {
+ QCOMPARE(opt1, MyEnum::Option1AD);
+ if (opt1 != m_opt1) {
+ m_opt1 = opt1;
+ emit opt1Changed(opt1);
+ }
+ }
+
+ void setOption1(MyEnum::Option1 opt1) { setOpt1(opt1); }
+
+private:
+ MyEnum::Option1 m_opt1 = MyEnum::Option10;
+};
+
+void tst_qqmlpropertycache::passForeignEnums()
+{
+ qmlRegisterType<MyEnum>("example", 1, 0, "MyEnum");
+ qmlRegisterType<MyData>("example", 1, 0, "MyData");
+
+ MyEnum myenum;
+ MyData data;
+
+ engine.rootContext()->setContextProperty("myenum", &myenum);
+ engine.rootContext()->setContextProperty("mydata", &data);
+
+ QQmlComponent component(&engine, testFile("foreignEnums.qml"));
+ QVERIFY(component.isReady());
+
+ QObject *obj = component.create(engine.rootContext());
+ QCOMPARE(data.opt1(), MyEnum::Option1AD);
+}
+
+Q_DECLARE_METATYPE(MyEnum::Option1)
+
class TestClass : public QObject
{
Q_OBJECT