summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-04-14 23:06:54 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-04-14 23:06:54 (GMT)
commitaad7bc4085980edf9fd6736efe909dc5a74a9d27 (patch)
treef44440a2633cb79b0e8e7c08315e0a8d8645a58b /src/declarative/qml
parentca52a35fa6bf4a86310d06c22aa256ab654712de (diff)
parent4174dd5dca647bfbe5ff5db1d495b7f887833323 (diff)
downloadQt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.zip
Qt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.tar.gz
Qt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (71 commits) Add QML documentation for validators Updates to the module documentation Fix minor typo in docs Revert "qdeclarativefocusscope works fine as a parallel test" qdeclarativefocusscope works fine as a parallel test Reduce warnings at shutdown Image with PreserveAspect enabled with either width or height defined should implicitly update the undefined axis to follow the aspect ratio Fix GridView.onRemove animation in photoviewer. Reduce warnings at shutdown Fix QT_NO_DESKTOPSERVICES Compiled bindings should not print warnings where normal bindings don't Update references links Move example code into separate files to make sure they compile Include qvariant.h as a convenience as context properties Merged 'orientation' into 'runtime' context property in qmlruntime Add 'runtime' property to the rootContext of DeclarativeViewer Temporarily disable tests that require compilation Fix qdeclarativedom test Further improve failure output Doc: more mention of using QUrl::fromLocalFile() for URLs on local filesystem ...
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qdeclarativebinding.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeboundsignal.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings.cpp7
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp11
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp21
-rw-r--r--src/declarative/qml/qdeclarativecontext.h3
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp62
-rw-r--r--src/declarative/qml/qdeclarativeengine.h2
-rw-r--r--src/declarative/qml/qdeclarativeexpression.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeextensionplugin.cpp12
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp5
13 files changed, 99 insertions, 38 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp
index e172a8b..664118d 100644
--- a/src/declarative/qml/qdeclarativebinding.cpp
+++ b/src/declarative/qml/qdeclarativebinding.cpp
@@ -126,7 +126,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags)
QDeclarativeBindingData *data = d->bindingData();
- if (!data->enabled || !data->context() || !data->context()->engine)
+ if (!data->enabled || !data->context() || !data->context()->isValid())
return;
data->addref();
diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp
index 762c6428..8c7a977 100644
--- a/src/declarative/qml/qdeclarativeboundsignal.cpp
+++ b/src/declarative/qml/qdeclarativeboundsignal.cpp
@@ -176,7 +176,7 @@ int QDeclarativeBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
}
if (m_params) m_params->setValues(a);
- if (m_expression) {
+ if (m_expression && m_expression->engine()) {
QDeclarativeExpressionPrivate::get(m_expression)->value(m_params);
if (m_expression && m_expression->hasError())
qWarning().nospace() << qPrintable(m_expression->error().toString());
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp
index 0c824fc..6fdf706 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings.cpp
+++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp
@@ -285,12 +285,7 @@ void QDeclarativeCompiledBindingsPrivate::run(Binding *binding, QDeclarativeProp
return;
QDeclarativeContextData *context = q->QDeclarativeAbstractExpression::context();
- if (!context) {
- qWarning("QDeclarativeCompiledBindings: Attempted to evaluate an expression in an invalid context");
- return;
- }
-
- if (!context->engine)
+ if (!context || !context->isValid())
return;
if (binding->updating) {
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index e180374..5f26ad5 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -320,6 +320,9 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, QObject
Create a QDeclarativeComponent from the given \a url and give it the
specified \a parent and \a engine.
+ Ensure that the URL provided is full and correct, in particular, use
+ \l QUrl::fromLocalFile() when loading a file from the local filesystem.
+
\sa loadUrl()
*/
QDeclarativeComponent::QDeclarativeComponent(QDeclarativeEngine *engine, const QUrl &url, QObject *parent)
@@ -409,6 +412,9 @@ QDeclarativeContext *QDeclarativeComponent::creationContext() const
/*!
Load the QDeclarativeComponent from the provided \a url.
+
+ Ensure that the URL provided is full and correct, in particular, use
+ \l QUrl::fromLocalFile() when loading a file from the local filesystem.
*/
void QDeclarativeComponent::loadUrl(const QUrl &url)
{
@@ -591,6 +597,11 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons
return 0;
}
+ if (!context->isValid()) {
+ qWarning("QDeclarativeComponent::beginCreate(): Cannot create a component in an invalid context");
+ return 0;
+ }
+
if (context->engine != engine) {
qWarning("QDeclarativeComponent::beginCreate(): Must create component in context from the same QDeclarativeEngine");
return 0;
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index 05e8d22..133b71f 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -723,6 +723,10 @@ void QDeclarativeCompositeTypeManager::compile(QDeclarativeCompositeTypeData *un
}
}
+ QUrl importUrl = unit->imports.baseUrl().resolved(QUrl(QLatin1String("qmldir")));
+ if (toLocalFileOrQrc(importUrl).isEmpty())
+ resourceList.prepend(importUrl);
+
for (int ii = 0; ii < resourceList.count(); ++ii) {
QUrl url = unit->imports.baseUrl().resolved(resourceList.at(ii));
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 9307bcc..ba4da95 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -202,6 +202,12 @@ QDeclarativeContext::~QDeclarativeContext()
d->data->destroy();
}
+bool QDeclarativeContext::isValid() const
+{
+ Q_D(const QDeclarativeContext);
+ return d->data && d->data->isValid();
+}
+
/*!
Return the context's QDeclarativeEngine, or 0 if the context has no QDeclarativeEngine or the
QDeclarativeEngine was destroyed.
@@ -245,6 +251,11 @@ void QDeclarativeContext::setContextObject(QObject *object)
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set context object on invalid context.");
+ return;
+ }
+
data->contextObject = object;
}
@@ -264,6 +275,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, const QVariant
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set property on invalid context.");
+ return;
+ }
+
if (data->engine) {
bool ok;
QObject *o = QDeclarativeEnginePrivate::get(data->engine)->toQObject(value, &ok);
@@ -305,6 +321,11 @@ void QDeclarativeContext::setContextProperty(const QString &name, QObject *value
return;
}
+ if (!isValid()) {
+ qWarning("QDeclarativeContext: Cannot set property on invalid context.");
+ return;
+ }
+
if (!data->propertyNames) data->propertyNames = new QDeclarativeIntegerCache(data->engine);
int idx = data->propertyNames->value(name);
diff --git a/src/declarative/qml/qdeclarativecontext.h b/src/declarative/qml/qdeclarativecontext.h
index a349628..94c9f4a 100644
--- a/src/declarative/qml/qdeclarativecontext.h
+++ b/src/declarative/qml/qdeclarativecontext.h
@@ -46,6 +46,7 @@
#include <QtCore/qobject.h>
#include <QtScript/qscriptvalue.h>
#include <QtCore/qmetatype.h>
+#include <QtCore/qvariant.h>
QT_BEGIN_HEADER
@@ -70,6 +71,8 @@ public:
QDeclarativeContext(QDeclarativeContext *parent, QObject *objParent=0);
virtual ~QDeclarativeContext();
+ bool isValid() const;
+
QDeclarativeEngine *engine() const;
QDeclarativeContext *parentContext() const;
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index eee72b6..7a16179 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -114,6 +114,10 @@ public:
QDeclarativeContextData(QDeclarativeContext *);
void destroy();
+ inline bool isValid() const {
+ return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted);
+ }
+
// My parent context and engine
QDeclarativeContextData *parent;
QDeclarativeEngine *engine;
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index f1adc16..c5afe92 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -212,10 +212,13 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr
newQMetaObject(StaticQtMetaObject::get());
globalObject().setProperty(QLatin1String("Qt"), qtObject);
+#ifndef QT_NO_DESKTOPSERVICES
offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation).replace(QLatin1Char('/'), QDir::separator())
+ QDir::separator() + QLatin1String("QML")
+ QDir::separator() + QLatin1String("OfflineStorage");
-
+#else
+ qWarning("offlineStoragePath is not set by default with QT_NO_DESKTOPSERVICES");
+#endif
qt_add_qmlxmlhttprequest(this);
qt_add_qmlsqldatabase(this);
@@ -848,6 +851,9 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object)
if (propertyCache)
propertyCache->release();
+ if (ownContext)
+ context->destroy();
+
QDeclarativeGuard<QObject> *guard = guards;
while (guard) {
QDeclarativeGuard<QObject> *g = guard;
@@ -858,9 +864,6 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object)
g->objectDestroyed(object);
}
- if (ownContext)
- context->destroy();
-
if (scriptValue)
delete scriptValue;
@@ -1214,7 +1217,10 @@ QScriptValue QDeclarativeEnginePrivate::desktopOpenUrl(QScriptContext *ctxt, QSc
{
if(ctxt->argumentCount() < 1)
return e->newVariant(QVariant(false));
- bool ret = QDesktopServices::openUrl(QUrl(ctxt->argument(0).toString()));
+ bool ret = false;
+#ifndef QT_NO_DESKTOPSERVICES
+ ret = QDesktopServices::openUrl(QUrl(ctxt->argument(0).toString()));
+#endif
return e->newVariant(QVariant(ret));
}
@@ -1486,13 +1492,17 @@ public:
QSet<QString> qmlDirFilesForWhichPluginsHaveBeenLoaded;
- QDeclarativeDirComponents importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine) {
+ bool importExtension(const QString &absoluteFilePath, const QString &uri, QDeclarativeEngine *engine, QDeclarativeDirComponents* components, QString *errorString) {
QFile file(absoluteFilePath);
QString filecontent;
if (file.open(QFile::ReadOnly)) {
filecontent = QString::fromUtf8(file.readAll());
if (qmlImportTrace())
qDebug() << "QDeclarativeEngine::add: loaded" << absoluteFilePath;
+ } else {
+ if (errorString)
+ *errorString = QDeclarativeEngine::tr("module \"%1\" definition \"%2\" not readable").arg(uri).arg(absoluteFilePath);
+ return false;
}
QDir dir = QFileInfo(file).dir();
@@ -1512,11 +1522,23 @@ public:
plugin.name);
if (!resolvedFilePath.isEmpty()) {
- engine->importPlugin(resolvedFilePath, uri);
+ if (!engine->importPlugin(resolvedFilePath, uri, errorString)) {
+ if (errorString)
+ *errorString = QDeclarativeEngine::tr("plugin cannot be loaded for module \"%1\": %2").arg(uri).arg(*errorString);
+ return false;
+ }
+ } else {
+ if (errorString)
+ *errorString = QDeclarativeEngine::tr("module \"%1\" plugin \"%2\" not found").arg(uri).arg(plugin.name);
+ return false;
}
}
}
- return qmldirParser.components();
+
+ if (components)
+ *components = qmldirParser.components();
+
+ return true;
}
QString resolvedUri(const QString &dir_arg, QDeclarativeEngine *engine)
@@ -1577,7 +1599,8 @@ public:
url = QUrl::fromLocalFile(fi.absolutePath()).toString();
uri = resolvedUri(dir, engine);
- qmldircomponents = importExtension(absoluteFilePath, uri, engine);
+ if (!importExtension(absoluteFilePath, uri, engine, &qmldircomponents, errorString))
+ return false;
break;
}
}
@@ -1608,12 +1631,12 @@ public:
return false; // local import dirs must exist
}
uri = resolvedUri(toLocalFileOrQrc(base.resolved(QUrl(uri))), engine);
- qmldircomponents = importExtension(localFileOrQrc,
- uri,
- engine);
-
if (uri.endsWith(QLatin1Char('/')))
uri.chop(1);
+ if (QFile::exists(localFileOrQrc)) {
+ if (!importExtension(localFileOrQrc,uri,engine,&qmldircomponents,errorString))
+ return false;
+ }
} else {
if (prefix.isEmpty()) {
// directory must at least exist for valid import
@@ -1926,8 +1949,10 @@ void QDeclarativeEngine::setPluginPathList(const QStringList &paths)
/*!
Imports the plugin named \a filePath with the \a uri provided.
Returns true if the plugin was successfully imported; otherwise returns false.
+
+ The plugin has to be a Qt plugin which implements the QDeclarativeExtensionPlugin interface.
*/
-bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri)
+bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &uri, QString *errorString)
{
if (qmlImportTrace())
qDebug() << "QDeclarativeEngine::importPlugin" << uri << "from" << filePath;
@@ -1948,9 +1973,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur
QPluginLoader loader(absoluteFilePath);
if (!loader.load()) {
- if (qmlImportTrace()) {
- qDebug() << "QDeclarativeEngine::importPlugin: " << loader.errorString();
- }
+ if (errorString)
+ *errorString = loader.errorString();
return false;
}
@@ -1972,8 +1996,8 @@ bool QDeclarativeEngine::importPlugin(const QString &filePath, const QString &ur
iface->initializeEngine(this, moduleId);
}
} else {
- if (qmlImportTrace())
- qDebug() << "QDeclarativeEngine::importPlugin: no DeclarativeExtensionInterface error";
+ if (errorString)
+ *errorString = loader.errorString();
return false;
}
}
diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h
index fcaddcf..7b058ea 100644
--- a/src/declarative/qml/qdeclarativeengine.h
+++ b/src/declarative/qml/qdeclarativeengine.h
@@ -85,7 +85,7 @@ public:
void setPluginPathList(const QStringList &paths);
void addPluginPath(const QString& dir);
- bool importPlugin(const QString &filePath, const QString &uri);
+ bool importPlugin(const QString &filePath, const QString &uri, QString *errorString);
void setNetworkAccessManagerFactory(QDeclarativeNetworkAccessManagerFactory *);
QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory() const;
diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp
index 2a3e557..05240a2 100644
--- a/src/declarative/qml/qdeclarativeexpression.cpp
+++ b/src/declarative/qml/qdeclarativeexpression.cpp
@@ -468,7 +468,7 @@ QVariant QDeclarativeExpressionPrivate::value(QObject *secondaryScope, bool *isU
{
Q_Q(QDeclarativeExpression);
- if (!q->engine()) {
+ if (!data || !data->context() || !data->context()->isValid()) {
qWarning("QDeclarativeExpression: Attempted to evaluate an expression in an invalid context");
return QVariant();
}
diff --git a/src/declarative/qml/qdeclarativeextensionplugin.cpp b/src/declarative/qml/qdeclarativeextensionplugin.cpp
index 5b7f1e8..762c642d 100644
--- a/src/declarative/qml/qdeclarativeextensionplugin.cpp
+++ b/src/declarative/qml/qdeclarativeextensionplugin.cpp
@@ -55,17 +55,21 @@ QT_BEGIN_NAMESPACE
applications using the QDeclarativeEngine class.
Writing a QML extension plugin is achieved by subclassing this
- base class, reimplementing the pure virtual initialize()
+ base class, reimplementing the pure virtual registerTypes()
function, and exporting the class using the Q_EXPORT_PLUGIN2()
- macro. See \l {How to Create Qt Plugins} for details.
+ macro.
- \sa QDeclarativeEngine::importExtension()
+ See \l {Extending QML in C++} for details how to write a QML extension plugin.
+ See \l {How to Create Qt Plugins} for general Qt plugin documentation.
+
+ \sa QDeclarativeEngine::importPlugin()
*/
/*!
\fn void QDeclarativeExtensionPlugin::registerTypes(const char *uri)
- Registers the QML types in the given \a uri.
+ Registers the QML types in the given \a uri. Here you call qmlRegisterType() for
+ all types which are provided by the extension plugin.
*/
/*!
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 0addfabd..3575c17 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -246,12 +246,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
{
QObject *o = (QObject *)operator new(instr.createSimple.typeSize +
sizeof(QDeclarativeDeclarativeData));
-#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
::memset(o, 0, instr.createSimple.typeSize + sizeof(QDeclarativeDeclarativeData));
-#else
- // faster than memset
- ::bzero(o, instr.createSimple.typeSize + sizeof(QDeclarativeDeclarativeData));
-#endif
instr.createSimple.create(o);
QDeclarativeDeclarativeData *ddata =