diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-08-27 04:32:25 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-08-27 04:32:25 (GMT) |
commit | 34a107454426db2f40b3be31923b8a5ce1d84f6e (patch) | |
tree | 06c08608be336beaf5f072a405202e6cb2247a9c /src | |
parent | 06f2a6982680beb5d72321b690af1ac9df5afd95 (diff) | |
download | Qt-34a107454426db2f40b3be31923b8a5ce1d84f6e.zip Qt-34a107454426db2f40b3be31923b8a5ce1d84f6e.tar.gz Qt-34a107454426db2f40b3be31923b8a5ce1d84f6e.tar.bz2 |
Internal QML API cleanup
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativecompiledbindings.cpp | 2 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecompiler.cpp | 18 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativecompositetypemanager.cpp | 18 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeimport.cpp | 157 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeimport_p.h | 37 |
5 files changed, 124 insertions, 108 deletions
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 723da94..9402596 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -1874,7 +1874,7 @@ bool QDeclarativeBindingCompilerPrivate::parseName(AST::Node *node, Result &type return false; QDeclarativeImportedNamespace *ns = 0; - if (!engine->importDatabase.resolveType(imports, name.toUtf8(), &attachType, 0, 0, 0, &ns)) + if (!imports.resolveType(name.toUtf8(), &attachType, 0, 0, 0, &ns)) return false; if (ns || !attachType || !attachType->attachedPropertiesType()) return false; diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 2b4a4a5..34d33bb 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -703,7 +703,7 @@ void QDeclarativeCompiler::compileTree(Object *tree) for (int ii = 0; ii < importedScriptIndexes.count(); ++ii) output->importCache->add(importedScriptIndexes.at(ii), ii); - unit->imports.cache(output->importCache, engine); + unit->imports.populateCache(output->importCache, engine); Q_ASSERT(tree->metatype); @@ -1403,8 +1403,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop, QDeclarativeType *type = 0; QDeclarativeImportedNamespace *typeNamespace = 0; - enginePrivate->importDatabase.resolveType(unit->imports, prop->name, - &type, 0, 0, 0, &typeNamespace); + unit->imports.resolveType(prop->name, &type, 0, 0, 0, &typeNamespace); if (typeNamespace) { // ### We might need to indicate that this property is a namespace @@ -1512,7 +1511,7 @@ bool QDeclarativeCompiler::buildPropertyInNamespace(QDeclarativeImportedNamespac // Setup attached property data QDeclarativeType *type = 0; - enginePrivate->importDatabase.resolveTypeInNamespace(ns, prop->name, &type, 0, 0, 0); + unit->imports.resolveType(ns, prop->name, &type, 0, 0, 0); if (!type || !type->attachedPropertiesType()) COMPILE_EXCEPTION(prop, tr("Non-existent attached object")); @@ -2139,8 +2138,7 @@ bool QDeclarativeCompiler::testQualifiedEnumAssignment(const QMetaProperty &prop QString typeName = parts.at(0); QDeclarativeType *type = 0; - enginePrivate->importDatabase.resolveType(unit->imports, typeName.toUtf8(), - &type, 0, 0, 0, 0); + unit->imports.resolveType(typeName.toUtf8(), &type, 0, 0, 0, 0); if (!type || obj->typeName != type->qmlTypeName()) return true; @@ -2167,7 +2165,7 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const int dot = script.indexOf('.'); if (dot > 0) { QDeclarativeType *type = 0; - enginePrivate->importDatabase.resolveType(unit->imports, script.left(dot), &type, 0, 0, 0, 0); + unit->imports.resolveType(script.left(dot), &type, 0, 0, 0, 0); if (!type) return -1; const QMetaObject *mo = type->metaObject(); @@ -2185,8 +2183,7 @@ int QDeclarativeCompiler::evaluateEnum(const QByteArray& script) const const QMetaObject *QDeclarativeCompiler::resolveType(const QByteArray& name) const { QDeclarativeType *qmltype = 0; - if (!enginePrivate->importDatabase.resolveType(unit->imports, name, &qmltype, - 0, 0, 0, 0)) + if (!unit->imports.resolveType(name, &qmltype, 0, 0, 0, 0)) return 0; if (!qmltype) return 0; @@ -2344,8 +2341,7 @@ bool QDeclarativeCompiler::buildDynamicMeta(QDeclarativeParser::Object *obj, Dyn QByteArray customTypeName; QDeclarativeType *qmltype = 0; QUrl url; - if (!enginePrivate->importDatabase.resolveType(unit->imports, p.customType, &qmltype, - &url, 0, 0, 0)) + if (!unit->imports.resolveType(p.customType, &qmltype, &url, 0, 0, 0)) COMPILE_EXCEPTION(&p, tr("Invalid property type")); if (!qmltype) { diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 2e77534..cc8f887 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -523,7 +523,7 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData int waiting = 0; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - QDeclarativeImportDatabase &importDatabase = ep->importDatabase; + QDeclarativeImportDatabase *importDatabase = &ep->importDatabase; // For local urls, add an implicit import "." as first (most overridden) lookup. // This will also trigger the loading of the qmldir and the import of any native @@ -538,9 +538,10 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData qmldircomponentsnetwork = parser.components(); } - importDatabase.addToImport(&unit->imports, qmldircomponentsnetwork, QLatin1String("."), - QString(), -1, -1, QDeclarativeScriptParser::Import::File, - 0); // error ignored (just means no fallback) + unit->imports.addImport(importDatabase, + QLatin1String("."), QString(), -1, -1, QDeclarativeScriptParser::Import::File, + qmldircomponentsnetwork, + 0); // error ignored (just means no fallback) } @@ -577,8 +578,9 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData } QString errorString; - if (!importDatabase.addToImport(&unit->imports, qmldircomponentsnetwork, imp.uri, imp.qualifier, - vmaj, vmin, imp.type, &errorString)) { + if (!unit->imports.addImport(importDatabase, + imp.uri, imp.qualifier, vmaj, vmin, imp.type, + qmldircomponentsnetwork, &errorString)) { QDeclarativeError error; error.setUrl(unit->imports.baseUrl()); error.setDescription(errorString); @@ -606,8 +608,8 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData int minorVersion; QDeclarativeImportedNamespace *typeNamespace = 0; QString errorString; - if (!importDatabase.resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, - &typeNamespace, &errorString) || typeNamespace) { + if (!unit->imports.resolveType(typeName, &ref.type, &url, &majorVersion, &minorVersion, + &typeNamespace, &errorString) || typeNamespace) { // Known to not be a type: // - known to be a namespace (Namespace {}) // - type with unknown namespace (UnknownNamespace.SomeType {}) diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp index 5c21ebc..8f95e26 100644 --- a/src/declarative/qml/qdeclarativeimport.cpp +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -109,6 +109,11 @@ public: QHash<QString,QDeclarativeImportedNamespace* > set; }; +/*! +\class QDeclarativeImports +\brief The QDeclarativeImports class encapsulates one QML document's import statements. +\internal +*/ QDeclarativeImports::QDeclarativeImports(const QDeclarativeImports ©) : d(copy.d) { @@ -181,7 +186,7 @@ cacheForNamespace(QDeclarativeEngine *engine, const QDeclarativeImportedNamespac return cache; } -void QDeclarativeImports::cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *engine) const +void QDeclarativeImports::populateCache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *engine) const { const QDeclarativeImportedNamespace &set = d->unqualifiedset; @@ -201,6 +206,67 @@ void QDeclarativeImports::cache(QDeclarativeTypeNameCache *cache, QDeclarativeEn cacheForNamespace(engine, set, cache); } + +/*! + \internal + + The given (namespace qualified) \a type is resolved to either + \list + \o a QDeclarativeImportedNamespace stored at \a ns_return, + \o a QDeclarativeType stored at \a type_return, or + \o a component located at \a url_return. + \endlist + + If any return pointer is 0, the corresponding search is not done. + + \sa addImport() +*/ +bool QDeclarativeImports::resolveType(const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, int *vmaj, int *vmin, + QDeclarativeImportedNamespace** ns_return, QString *errorString) const +{ + QDeclarativeImportedNamespace* ns = d->findNamespace(QString::fromUtf8(type)); + if (ns) { + if (ns_return) + *ns_return = ns; + return true; + } + if (type_return || url_return) { + if (d->find(type,vmaj,vmin,type_return,url_return, errorString)) { + if (qmlImportTrace()) { + if (type_return && *type_return && url_return && !url_return->isEmpty()) + qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: " + << type << " => " << (*type_return)->typeName() << " " << *url_return; + if (type_return && *type_return) + qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: " + << type << " => " << (*type_return)->typeName(); + if (url_return && !url_return->isEmpty()) + qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::resolveType: " + << type << " => " << *url_return; + } + return true; + } + } + return false; +} + +/*! + \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 QDeclarativeType stored at \a type_return, or + a component located at \a url_return. + + If either return pointer is 0, the corresponding search is not done. +*/ +bool QDeclarativeImports::resolveType(QDeclarativeImportedNamespace* ns, const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *vmaj, int *vmin) const +{ + return ns->find(type,vmaj,vmin,type_return,url_return); +} + bool QDeclarativeImportedNamespace::find_helper(int i, const QByteArray& type, int *vmajor, int *vminor, QDeclarativeType** type_return, QUrl* url_return, QUrl *base, bool *typeRecursionDetected) @@ -280,15 +346,16 @@ QDeclarativeImportsPrivate::~QDeclarativeImportsPrivate() } bool QDeclarativeImportsPrivate::importExtension(const QString &absoluteFilePath, const QString &uri, - QDeclarativeImportDatabase *database, - QDeclarativeDirComponents* components, QString *errorString) + QDeclarativeImportDatabase *database, + QDeclarativeDirComponents* components, QString *errorString) { QFile file(absoluteFilePath); QString filecontent; if (file.open(QFile::ReadOnly)) { filecontent = QString::fromUtf8(file.readAll()); if (qmlImportTrace()) - qDebug() << "QDeclarativeImportDatabase::add: loaded" << absoluteFilePath; + qDebug().nospace() << "QDeclarativeImports(" << qPrintable(base.toString()) << "::importExtension: " + << "loaded " << absoluteFilePath; } else { if (errorString) *errorString = QDeclarativeImportDatabase::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath); @@ -576,6 +643,10 @@ bool QDeclarativeImportedNamespace::find(const QByteArray& type, int *vmajor, in return false; } +/*! +\class QDeclarativeImportDatabase +\brief The QDeclarativeImportDatabase class manages the QML imports for a QDeclarativeEngine. +*/ QDeclarativeImportDatabase::QDeclarativeImportDatabase(QDeclarativeEngine *e) : engine(e) { @@ -619,75 +690,19 @@ QDeclarativeImportDatabase::~QDeclarativeImportDatabase() The base URL must already have been set with Import::setBaseUrl(). */ -bool QDeclarativeImportDatabase::addToImport(QDeclarativeImports* imports, - const QDeclarativeDirComponents &qmldircomponentsnetwork, - const QString& uri, const QString& prefix, int vmaj, int vmin, - QDeclarativeScriptParser::Import::Type importType, - QString *errorString) +bool QDeclarativeImports::addImport(QDeclarativeImportDatabase *importDb, + const QString& uri, const QString& prefix, int vmaj, int vmin, + QDeclarativeScriptParser::Import::Type importType, + const QDeclarativeDirComponents &qmldircomponentsnetwork, + QString *errorString) { if (qmlImportTrace()) - qDebug().nospace() << "QDeclarativeImportDatabase::addToImport " << imports << " " << uri << " " - << vmaj << '.' << vmin << " " + qDebug().nospace() << "QDeclarativeImports(" << qPrintable(baseUrl().toString()) << ")" << "::addImport: " + << uri << " " << vmaj << '.' << vmin << " " << (importType==QDeclarativeScriptParser::Import::Library? "Library" : "File") << " as " << prefix; - bool ok = imports->d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, this, errorString); - return ok; -} - -/*! - \internal - - Using the given \a imports, the given (namespace qualified) \a type is resolved to either - a QDeclarativeImportedNamespace stored at \a ns_return, - a QDeclarativeType stored at \a type_return, or - a component located at \a url_return. - - If any return pointer is 0, the corresponding search is not done. - - \sa addToImport() -*/ -bool QDeclarativeImportDatabase::resolveType(const QDeclarativeImports& imports, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, int *vmaj, int *vmin, - QDeclarativeImportedNamespace** ns_return, QString *errorString) const -{ - QDeclarativeImportedNamespace* ns = imports.d->findNamespace(QString::fromUtf8(type)); - if (ns) { - if (ns_return) - *ns_return = ns; - return true; - } - if (type_return || url_return) { - if (imports.d->find(type,vmaj,vmin,type_return,url_return, errorString)) { - if (qmlImportTrace()) { - if (type_return && *type_return && url_return && !url_return->isEmpty()) - qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << (*type_return)->typeName() << *url_return; - if (type_return && *type_return) - qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << (*type_return)->typeName(); - if (url_return && !url_return->isEmpty()) - qDebug() << "QDeclarativeImportDatabase::resolveType" << type << '=' << *url_return; - } - return true; - } - } - return false; -} - -/*! - \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 QDeclarativeType stored at \a type_return, or - a component located at \a url_return. - - If either return pointer is 0, the corresponding search is not done. -*/ -bool QDeclarativeImportDatabase::resolveTypeInNamespace(QDeclarativeImportedNamespace* ns, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, - int *vmaj, int *vmin) const -{ - return ns->find(type,vmaj,vmin,type_return,url_return); + return d->add(qmldircomponentsnetwork, uri, prefix, vmaj, vmin, importType, importDb, errorString); } /*! @@ -834,7 +849,7 @@ void QDeclarativeImportDatabase::setPluginPathList(const QStringList &paths) void QDeclarativeImportDatabase::addPluginPath(const QString& path) { if (qmlImportTrace()) - qDebug() << "QDeclarativeImportDatabase::addPluginPath" << path; + qDebug().nospace() << "QDeclarativeImportDatabase::addPluginPath: " << path; QUrl url = QUrl(path); if (url.isRelative() || url.scheme() == QLatin1String("file")) { @@ -848,7 +863,7 @@ void QDeclarativeImportDatabase::addPluginPath(const QString& path) void QDeclarativeImportDatabase::addImportPath(const QString& path) { if (qmlImportTrace()) - qDebug() << "QDeclarativeImportDatabase::addImportPath" << path; + qDebug().nospace() << "QDeclarativeImportDatabase::addImportPath: " << path; if (path.isEmpty()) return; @@ -882,7 +897,7 @@ void QDeclarativeImportDatabase::setImportPathList(const QStringList &paths) bool QDeclarativeImportDatabase::importPlugin(const QString &filePath, const QString &uri, QString *errorString) { if (qmlImportTrace()) - qDebug() << "QDeclarativeImportDatabase::importPlugin" << uri << "from" << filePath; + qDebug().nospace() << "QDeclarativeImportDatabase::importPlugin: " << uri << " from " << filePath; QFileInfo fileInfo(filePath); const QString absoluteFilePath = fileInfo.absoluteFilePath(); diff --git a/src/declarative/qml/qdeclarativeimport_p.h b/src/declarative/qml/qdeclarativeimport_p.h index 88246d4..84802de 100644 --- a/src/declarative/qml/qdeclarativeimport_p.h +++ b/src/declarative/qml/qdeclarativeimport_p.h @@ -65,9 +65,10 @@ QT_BEGIN_NAMESPACE class QDeclarativeTypeNameCache; class QDeclarativeEngine; class QDir; - class QDeclarativeImportedNamespace; class QDeclarativeImportsPrivate; +class QDeclarativeImportDatabase; + class QDeclarativeImports { public: @@ -79,7 +80,24 @@ public: void setBaseUrl(const QUrl &url); QUrl baseUrl() const; - void cache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const; + bool resolveType(const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *version_major, int *version_minor, + QDeclarativeImportedNamespace** ns_return, + QString *errorString = 0) const; + bool resolveType(QDeclarativeImportedNamespace*, + const QByteArray& type, + QDeclarativeType** type_return, QUrl* url_return, + int *version_major, int *version_minor) const; + + bool addImport(QDeclarativeImportDatabase *, + const QString& uri, const QString& prefix, int vmaj, int vmin, + QDeclarativeScriptParser::Import::Type importType, + const QDeclarativeDirComponents &qmldircomponentsnetwork, + QString *errorString); + + void populateCache(QDeclarativeTypeNameCache *cache, QDeclarativeEngine *) const; + private: friend class QDeclarativeImportDatabase; QDeclarativeImportsPrivate *d; @@ -102,21 +120,6 @@ public: void setPluginPathList(const QStringList &paths); void addPluginPath(const QString& path); - - bool addToImport(QDeclarativeImports*, const QDeclarativeDirComponents &qmldircomponentsnetwork, - const QString& uri, const QString& prefix, int vmaj, int vmin, - QDeclarativeScriptParser::Import::Type importType, - QString *errorString); - bool resolveType(const QDeclarativeImports&, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, - int *version_major, int *version_minor, - QDeclarativeImportedNamespace** ns_return, - QString *errorString = 0) const; - bool resolveTypeInNamespace(QDeclarativeImportedNamespace*, const QByteArray& type, - QDeclarativeType** type_return, QUrl* url_return, - int *version_major, int *version_minor ) const; - - private: friend class QDeclarativeImportsPrivate; QString resolvePlugin(const QDir &qmldirPath, const QString &qmldirPluginPath, |