summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativecontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/qdeclarativecontext.cpp')
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp50
1 files changed, 14 insertions, 36 deletions
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 6657fea..ae4223e 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -114,7 +114,7 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
\endcode
All properties added explicitly by QDeclarativeContext::setContextProperty() take
- precedence over context object's properties.
+ precedence over the context object's properties.
Contexts form a hierarchy. The root of this heirarchy is the QDeclarativeEngine's
\l {QDeclarativeEngine::rootContext()}{root context}. A component instance can
@@ -140,6 +140,11 @@ QDeclarativeContextPrivate::QDeclarativeContextPrivate()
While QML objects instantiated in a context are not strictly owned by that
context, their bindings are. If a context is destroyed, the property bindings of
outstanding QML objects will stop evaluating.
+
+ \note Setting the context object or adding new context properties after an object
+ has been created in that context is an expensive operation (essentially forcing all bindings
+ to reevaluate). Thus whenever possible you should complete "setup" of the context
+ before using it to create any objects.
*/
/*! \internal */
@@ -203,6 +208,12 @@ QDeclarativeContext::~QDeclarativeContext()
d->data->destroy();
}
+/*!
+ Returns whether the context is valid.
+
+ To be valid, a context must have a engine, and it's contextObject(), if any,
+ must not have been deleted.
+*/
bool QDeclarativeContext::isValid() const
{
Q_D(const QDeclarativeContext);
@@ -655,7 +666,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
if (scriptEngine->hasUncaughtException()) {
QDeclarativeError error;
QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
- qWarning().nospace() << qPrintable(error.toString());
+ enginePriv->warning(error);
}
scriptEngine->popContext();
@@ -681,7 +692,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
if (scriptEngine->hasUncaughtException()) {
QDeclarativeError error;
QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
- qWarning().nospace() << qPrintable(error.toString());
+ enginePriv->warning(error);
}
scriptEngine->popContext();
@@ -691,39 +702,6 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object
}
}
-void QDeclarativeContextData::addScript(const QDeclarativeParser::Object::ScriptBlock &script,
- QObject *scopeObject)
-{
- if (!engine)
- return;
-
- QDeclarativeEnginePrivate *enginePriv = QDeclarativeEnginePrivate::get(engine);
- QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine);
-
- QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
-
- scriptContext->pushScope(enginePriv->contextClass->newContext(this, scopeObject));
- scriptContext->pushScope(enginePriv->globalClass->globalObject());
-
- QScriptValue scope = scriptEngine->newObject();
- scriptContext->setActivationObject(scope);
- scriptContext->pushScope(scope);
-
- for (int ii = 0; ii < script.codes.count(); ++ii) {
- scriptEngine->evaluate(script.codes.at(ii), script.files.at(ii), script.lineNumbers.at(ii));
-
- if (scriptEngine->hasUncaughtException()) {
- QDeclarativeError error;
- QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
- qWarning().nospace() << qPrintable(error.toString());
- }
- }
-
- scriptEngine->popContext();
-
- scripts.append(scope);
-}
-
void QDeclarativeContextData::setIdProperty(int idx, QObject *obj)
{
idValues[idx] = obj;