aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Benelli <marco.benelli@theqtcompany.com>2015-12-04 15:56:07 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-17 14:06:47 +0000
commit4b018848f7a7055976895de8a4b8208b58a36fac (patch)
tree0a7f67cd91437e5ef806446d802b96476c9e3e86
parentf89d8294f930914a8f7b933719596e2e3ebf1773 (diff)
qml: preserve composite singleton types.
Composite singleton types used to always have version -1,-1; regardless of what is written in qmldir. Change-Id: Ia193e73695e57095f6a09b97768805f2f23cd56a Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
-rw-r--r--src/qml/qml/qqmlimport.cpp19
-rw-r--r--src/qml/qml/qqmlimport_p.h2
-rw-r--r--src/qml/qml/qqmltypeloader.cpp4
-rw-r--r--tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/Singleton.qml6
-rw-r--r--tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/qmldir3
-rw-r--r--tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp14
6 files changed, 40 insertions, 8 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index f6f8c6e51e..d538199520 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -125,7 +125,9 @@ bool isPathAbsolute(const QString &path)
}
// If the type does not already exist as a file import, add the type and return the new type
-QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeName, bool isCompositeSingleton, QList<QQmlError> *errors)
+QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeName,
+ bool isCompositeSingleton, QList<QQmlError> *errors,
+ int majorVersion=-1, int minorVersion=-1)
{
QUrl url(urlString);
QQmlType *ret = QQmlMetaType::qmlType(url);
@@ -140,8 +142,8 @@ QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeNa
QQmlPrivate::RegisterCompositeSingletonType reg = {
url,
"", //Empty URI indicates loaded via file imports
- -1,
- -1,
+ majorVersion,
+ minorVersion,
buf.constData()
};
ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeSingletonRegistration, &reg));
@@ -149,8 +151,8 @@ QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeNa
QQmlPrivate::RegisterCompositeType reg = {
url,
"", //Empty URI indicates loaded via file imports
- -1,
- -1,
+ majorVersion,
+ minorVersion,
buf.constData()
};
ret = QQmlMetaType::qmlTypeFromIndex(QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, &reg));
@@ -416,6 +418,8 @@ void findCompositeSingletons(const QQmlImportNamespace &set, QList<QQmlImports::
QQmlImports::CompositeSingletonReference ref;
ref.typeName = cit->typeName;
ref.prefix = set.prefix;
+ ref.majorVersion = cit->majorVersion;
+ ref.minorVersion = cit->minorVersion;
resultList.append(ref);
}
}
@@ -656,7 +660,10 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader,
}
if (candidate != end) {
- QQmlType *returnType = getTypeForUrl(componentUrl, type, isCompositeSingleton, 0);
+ int major = vmajor ? *vmajor : -1;
+ int minor = vminor ? *vminor : -1;
+ QQmlType *returnType = getTypeForUrl(componentUrl, type, isCompositeSingleton, 0,
+ major, minor);
if (type_return)
*type_return = returnType;
return returnType != 0;
diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h
index bda87f29b1..951b9752f3 100644
--- a/src/qml/qml/qqmlimport_p.h
+++ b/src/qml/qml/qqmlimport_p.h
@@ -118,6 +118,8 @@ public:
{
QString typeName;
QString prefix;
+ int majorVersion;
+ int minorVersion;
};
QList<CompositeSingletonReference> resolvedCompositeSingletons() const;
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 29f1ca7959..1e671542be 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -2320,8 +2320,8 @@ void QQmlTypeData::resolveTypes()
m_namespaces.insert(csRef.prefix);
}
- int majorVersion = -1;
- int minorVersion = -1;
+ int majorVersion = csRef.majorVersion > -1 ? csRef.majorVersion : -1;
+ int minorVersion = csRef.minorVersion > -1 ? csRef.minorVersion : -1;
if (!resolveType(typeName, majorVersion, minorVersion, ref))
return;
diff --git a/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/Singleton.qml b/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/Singleton.qml
new file mode 100644
index 0000000000..b47d2e98f4
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/Singleton.qml
@@ -0,0 +1,6 @@
+pragma Singleton
+import QtQuick 2.0
+
+QtObject {
+ property int test: 0
+}
diff --git a/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/qmldir b/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/qmldir
new file mode 100644
index 0000000000..8df57f6d47
--- /dev/null
+++ b/tests/auto/qml/qmlplugindump/tests/dumper/CompositeSingleton/qmldir
@@ -0,0 +1,3 @@
+module tests.dumper.CompositeSingleton
+singleton Singleton 1.0 Singleton.qml
+depends QtQuick 2.0
diff --git a/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp b/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
index 28d687bd1c..eb05e8cde7 100644
--- a/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
+++ b/tests/auto/qml/qmlplugindump/tst_qmlplugindump.cpp
@@ -47,6 +47,7 @@ public:
private slots:
void initTestCase();
void builtins();
+ void singleton();
private:
QString qmlplugindumpPath;
@@ -102,6 +103,19 @@ void tst_qmlplugindump::builtins()
QVERIFY(result.contains(QLatin1String("Module {")));
}
+void tst_qmlplugindump::singleton()
+{
+ QProcess dumper;
+ QStringList args;
+ args << QLatin1String("tests.dumper.CompositeSingleton") << QLatin1String("1.0")
+ << QLatin1String(".");
+ dumper.start(qmlplugindumpPath, args);
+ dumper.waitForFinished();
+
+ const QString &result = dumper.readAllStandardOutput();
+ QVERIFY(result.contains(QLatin1String("exports: [\"Singleton 1.0\"]")));
+}
+
QTEST_MAIN(tst_qmlplugindump)
#include "tst_qmlplugindump.moc"