summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-08-24 23:44:27 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-08-24 23:44:27 (GMT)
commitf7a3ece15715bea8c8588aa0682e6f798a533cab (patch)
tree55bdf64589dead4c9f6bd5c1fa0608e17ef7a01a /src/declarative
parent00736dec26d7db60f8cbf8606ecf6d011c7182df (diff)
downloadQt-f7a3ece15715bea8c8588aa0682e6f798a533cab.zip
Qt-f7a3ece15715bea8c8588aa0682e6f798a533cab.tar.gz
Qt-f7a3ece15715bea8c8588aa0682e6f798a533cab.tar.bz2
Largely revert 40c12237b506bd and implement simpler more efficient way.
Still doubtful that ACTUAL version import is needed.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qmlcompiler.cpp2
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp26
-rw-r--r--src/declarative/qml/qmlengine.cpp128
-rw-r--r--src/declarative/qml/qmlengine_p.h20
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp2
5 files changed, 43 insertions, 135 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 1771cb4..ad63b5b 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -1176,7 +1176,7 @@ bool QmlCompiler::buildProperty(QmlParser::Property *prop,
}
QmlType *type = 0;
- QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, &type, 0);
+ QmlEnginePrivate::get(engine)->resolveType(unit->imports, prop->name, &type, 0, 0, 0);
// 0: attached properties not supported in QML component files
if (!type || !type->attachedPropertiesType())
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index 5bf2dc0..46ce857 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -327,26 +327,18 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
}
QUrl url;
- QmlEnginePrivate::ImportedNamespace *s;
- QByteArray localTypeName;
-
- QmlEnginePrivate::get(engine)->resolveNamespace(unit->imports, typeName, &s, &localTypeName);
- if (QmlEnginePrivate::get(engine)->resolveTypeInNamespace(s, localTypeName, &ref.type, &url)) {
- int majorVersion;
- int minorVersion;
- if (s->getTypeInfo(localTypeName, 0, &majorVersion, &minorVersion)) {
- foreach (QmlParser::Object *obj, parserRef->refObjects) {
- // store namespace for DOM
- obj->majorVersion = majorVersion;
- obj->minorVersion = minorVersion;
- }
- }
- } else {
- // try base url
- url = unit->imports.baseUrl().resolved(QUrl(QLatin1String(typeName + ".qml")));
+ int majorVersion;
+ int minorVersion;
+ if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion)) {
+ // XXX could produce error message here.
}
if (ref.type) {
+ foreach (QmlParser::Object *obj, parserRef->refObjects) {
+ // store namespace for DOM
+ obj->majorVersion = majorVersion;
+ obj->minorVersion = minorVersion;
+ }
unit->types << ref;
continue;
}
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index fd18b26..b3e08ea 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -1072,7 +1072,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object,
}
-struct QmlImportedNamespacePrivate {
+struct QmlEnginePrivate::ImportedNamespace {
QStringList urls;
QList<int> majversions;
QList<int> minversions;
@@ -1122,7 +1122,7 @@ struct QmlImportedNamespacePrivate {
return QUrl();
}
- QmlType *findBuiltin(const QByteArray& type, QByteArray* found=0) const
+ QmlType *findBuiltin(const QByteArray& type, int *vmajor, int *vminor) const
{
for (int i=0; i<urls.count(); ++i) {
int vmaj = majversions.at(i);
@@ -1131,7 +1131,8 @@ struct QmlImportedNamespacePrivate {
qt += "/";
qt += type;
QmlType *t = QmlMetaType::qmlType(qt,vmaj,vmin);
- if (found) *found = qt;
+ if (vmajor) *vmajor = vmaj;
+ if (vminor) *vminor = vmin;
if (t) return t;
}
return 0;
@@ -1177,10 +1178,10 @@ public:
} else {
url = base.resolved(QUrl(url)).toString();
}
- s->d->urls.append(url);
- s->d->majversions.append(vmaj);
- s->d->minversions.append(vmin);
- s->d->isLibrary.append(importType == QmlScriptParser::Import::Library);
+ s->urls.append(url);
+ s->majversions.append(vmaj);
+ s->minversions.append(vmin);
+ s->isLibrary.append(importType == QmlScriptParser::Import::Library);
return true;
}
@@ -1202,13 +1203,13 @@ public:
}
QString unqualifiedtype = type.mid(slash+1);
if (s)
- return s->d->find(unqualifiedtype);
+ return s->find(unqualifiedtype);
else
return QUrl();
}
- QmlType *findBuiltin(const QByteArray& type, QByteArray* found=0)
+ QmlType *findBuiltin(const QByteArray& type, int *vmajor, int *vminor)
{
QmlEnginePrivate::ImportedNamespace *s = 0;
int slash = type.indexOf('/');
@@ -1226,37 +1227,16 @@ public:
}
QByteArray unqualifiedtype = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower)
if (s)
- return s->d->findBuiltin(unqualifiedtype,found);
+ return s->findBuiltin(unqualifiedtype,vmajor,vminor);
else
return 0;
- }
+ }
QmlEnginePrivate::ImportedNamespace *findNamespace(const QString& type)
{
return set.value(type);
}
- void resolveNamespace(const QByteArray &type, QmlEnginePrivate::ImportedNamespace **ns, QByteArray *unqualifiedType)
- {
- QmlEnginePrivate::ImportedNamespace *s = 0;
- int slash = type.indexOf('/');
- if (slash >= 0) {
- while (!s) {
- s = set.value(QString::fromLatin1(type.left(slash)));
- int nslash = type.indexOf('/',slash+1);
- if (nslash > 0)
- slash = nslash;
- else
- break;
- }
- } else {
- s = &unqualifiedset;
- }
-
- *ns = s;
- *unqualifiedType = slash < 0 ? type : type.mid(slash+1); // common-case opt (QString::mid works fine, but slower)
- }
-
private:
QmlEnginePrivate::ImportedNamespace unqualifiedset;
QHash<QString,QmlEnginePrivate::ImportedNamespace* > set;
@@ -1279,37 +1259,6 @@ void QmlEnginePrivate::Imports::setBaseUrl(const QUrl& url)
base = url;
}
-QmlEnginePrivate::ImportedNamespace::ImportedNamespace()
- : d(new QmlImportedNamespacePrivate)
-{
-}
-
-QmlEnginePrivate::ImportedNamespace::~ImportedNamespace()
-{
- delete d;
-}
-
-bool QmlEnginePrivate::ImportedNamespace::getTypeInfo(const QByteArray &typeName, QString *uri, int *majorVersion, int *minorVersion)
-{
- for (int i=0; i<d->urls.count(); ++i) {
- int vmaj = d->majversions.at(i);
- int vmin = d->minversions.at(i);
- QByteArray qt = d->urls.at(i).toLatin1();
- qt += "/";
- qt += typeName;
- if (QmlMetaType::qmlType(qt,vmaj,vmin)) {
- if (uri)
- *uri = d->urls.at(i);
- if (majorVersion)
- *majorVersion = d->majversions.at(i);
- if (minorVersion)
- *minorVersion = d->minversions.at(i);
- return true;
- }
- }
- return false;
-}
-
/*!
Adds \a path as a directory where installed QML components are
defined in a URL-based directory structure.
@@ -1362,11 +1311,21 @@ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const Q
\sa addToImport()
*/
-bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return) const
+bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *vmaj, int *vmin, ImportedNamespace** ns_return) const
{
+ if (ns_return) {
+ *ns_return = imports.d->findNamespace(QLatin1String(type));
+ if (*ns_return)
+ return true;
+ }
if (type_return) {
- QmlType* t = imports.d->findBuiltin(type);
- if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace
+ QmlType* t = imports.d->findBuiltin(type,vmaj,vmin);
+ if (!t) {
+ // XXX do we really still need this?
+ t = QmlMetaType::qmlType(type,0,0); // Try global namespace
+ if (vmin) *vmin = 0;
+ if (vmaj) *vmaj = 0;
+ }
if (t) {
if (type_return) *type_return = t;
if (qmlImportTrace())
@@ -1386,11 +1345,6 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ
return true;
}
}
- if (ns_return) {
- *ns_return = imports.d->findNamespace(QLatin1String(type));
- if (*ns_return)
- return true;
- }
if (qmlImportTrace())
qDebug() << "QmlEngine::resolveType" << type << " not found";
return false;
@@ -1399,16 +1353,6 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ
/*!
\internal
- Splits a fully qualified type name into the namespace and the unqualified type name.
-*/
-void QmlEnginePrivate::resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **ns, QByteArray *unqualifiedType) const
-{
- imports.d->resolveNamespace(type, ns, unqualifiedType);
-}
-
-/*!
- \internal
-
Searching \e only in the namespace \a ns (previously returned in a call to
resolveType(), \a type is found and returned to either
a QmlType stored at \a type_return, or
@@ -1416,31 +1360,17 @@ void QmlEnginePrivate::resolveNamespace(const Imports& imports, const QByteArray
If either return pointer is 0, the corresponding search is not done.
*/
-bool QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const
+void QmlEnginePrivate::resolveTypeInNamespace(ImportedNamespace* ns, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *vmaj, int *vmin ) const
{
if (!ns)
- return false;
+ return;
if (type_return) {
- QmlType* t = ns->d->findBuiltin(type);
- if (!t) t = QmlMetaType::qmlType(type,0,0); // Try global namespace
- if (t) {
- *type_return = t;
- if (qmlImportTrace())
- qDebug() << "QmlEngine::resolveTypeInNamespace" << type << "= (builtin)";
- return true;
- }
+ *type_return = ns->findBuiltin(type,vmaj,vmin);
}
if (url_return) {
- QUrl url = ns->d->find(QLatin1String(type));
- if (url.isValid()) {
- if (url_return) *url_return = url;
- if (qmlImportTrace())
- qDebug() << "QmlEngine::resolveType" << type << "=" << url;
- return true;
- }
+ *url_return = ns->find(QLatin1String(type));
}
- return false;
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index c84b3b5..4be5a98 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -195,24 +195,10 @@ public:
QUrl base;
QmlImportsPrivate *d;
};
-
- struct ImportedNamespace {
- ImportedNamespace();
- ~ImportedNamespace();
-
- bool getTypeInfo(const QByteArray &typeName, QString *uri, int *vmaj, int *vmin);
- private:
- friend class QmlImportsPrivate;
- friend class QmlEnginePrivate;
- class QmlImportedNamespacePrivate *d;
- };
-
+ struct ImportedNamespace;
bool addToImport(Imports*, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const;
-
- bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const;
-
- void resolveNamespace(const Imports& imports, const QByteArray &type, ImportedNamespace **s, QByteArray *unqualifiedType) const;
- bool resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const;
+ bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor, ImportedNamespace** ns_return=0) const;
+ void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return, int *version_major, int *version_minor ) const;
static QScriptValue qmlScriptObject(QObject*, QmlEngine*);
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 99f9f0c..63415da 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -224,7 +224,7 @@ void QmlMetaPropertyPrivate::initProperty(QObject *obj, const QString &name)
if (typeData) {
QmlType *t = 0;
- enginePrivate->resolveType(typeData->imports, name.toLatin1(), &t, 0);
+ enginePrivate->resolveType(typeData->imports, name.toLatin1(), &t, 0, 0, 0);
if (t && t->attachedPropertiesFunction()) {
attachedFunc = t->index();
if (attachedFunc != -1)