diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-08-25 07:13:52 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-08-25 07:13:52 (GMT) |
commit | 7c1eaa4ec5d78ccf7770c09e12afb497daa4b90e (patch) | |
tree | cbfc17fbd68ad17792516ecd0493ab5f14cac99e /src | |
parent | de9bcc414c230fa7af1828d938c59fe2d139b968 (diff) | |
download | Qt-7c1eaa4ec5d78ccf7770c09e12afb497daa4b90e.zip Qt-7c1eaa4ec5d78ccf7770c09e12afb497daa4b90e.tar.gz Qt-7c1eaa4ec5d78ccf7770c09e12afb497daa4b90e.tar.bz2 |
Make QmlEnginePrivate::Imports a stack type.
Also fixes memleak.
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 44 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine_p.h | 9 |
2 files changed, 48 insertions, 5 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index faac8cd..7923eda 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1141,6 +1141,16 @@ struct QmlEnginePrivate::ImportedNamespace { class QmlImportsPrivate { public: + QmlImportsPrivate() : ref(1) + { + } + + ~QmlImportsPrivate() + { + foreach (QmlEnginePrivate::ImportedNamespace* s, set.values()) + delete s; + } + bool add(const QUrl& base, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType, const QStringList& importPath) { QmlEnginePrivate::ImportedNamespace *s; @@ -1237,11 +1247,29 @@ public: return set.value(type); } + QUrl base; + int ref; + private: QmlEnginePrivate::ImportedNamespace unqualifiedset; QHash<QString,QmlEnginePrivate::ImportedNamespace* > set; }; +QmlEnginePrivate::Imports::Imports(const Imports ©) : + d(copy.d) +{ + ++d->ref; +} + +QmlEnginePrivate::Imports &QmlEnginePrivate::Imports::operator =(const Imports ©) +{ + ++copy.d->ref; + if (--d->ref == 0) + delete d; + d = copy.d; + return *this; +} + QmlEnginePrivate::Imports::Imports() : d(new QmlImportsPrivate) { @@ -1249,6 +1277,8 @@ QmlEnginePrivate::Imports::Imports() : QmlEnginePrivate::Imports::~Imports() { + if (--d->ref == 0) + delete d; } /*! @@ -1256,7 +1286,15 @@ QmlEnginePrivate::Imports::~Imports() */ void QmlEnginePrivate::Imports::setBaseUrl(const QUrl& url) { - base = url; + d->base = url; +} + +/*! + Returns the base URL to be used for all relative file imports added. +*/ +QUrl QmlEnginePrivate::Imports::baseUrl() const +{ + return d->base; } /*! @@ -1293,7 +1331,7 @@ void QmlEngine::addImportPath(const QString& path) */ bool QmlEnginePrivate::addToImport(Imports* imports, const QString& uri, const QString& prefix, int vmaj, int vmin, QmlScriptParser::Import::Type importType) const { - bool ok = imports->d->add(imports->base,uri,prefix,vmaj,vmin,importType,fileImportPath); + bool ok = imports->d->add(imports->d->base,uri,prefix,vmaj,vmin,importType,fileImportPath); if (qmlImportTrace()) qDebug() << "QmlEngine::addToImport(" << imports << uri << prefix << vmaj << "." << vmin << (importType==QmlScriptParser::Import::Library? "Library" : "File") << ": " << ok; return ok; @@ -1336,7 +1374,7 @@ bool QmlEnginePrivate::resolveType(const Imports& imports, const QByteArray& typ if (url_return) { QUrl url = imports.d->find(QLatin1String(type)); if (!url.isValid()) - url = imports.base.resolved(QUrl(QLatin1String(type + ".qml"))); + url = imports.d->base.resolved(QUrl(QLatin1String(type + ".qml"))); if (url.isValid()) { if (url_return) *url_return = url; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 4be5a98..3f0c03c 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -188,13 +188,17 @@ public: struct Imports { Imports(); ~Imports(); + Imports(const Imports ©); + Imports &operator =(const Imports ©); + void setBaseUrl(const QUrl& url); - QUrl baseUrl() const { return base; } + QUrl baseUrl() const; + private: friend class QmlEnginePrivate; - QUrl base; QmlImportsPrivate *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, int *version_major, int *version_minor, ImportedNamespace** ns_return=0) const; @@ -210,6 +214,7 @@ public: static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } }; + class QmlScriptClass : public QScriptClass { public: |