summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-04-27 05:36:11 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-04-27 05:36:11 (GMT)
commit9f941fd65083ae6d3f2f5441bf60346821932218 (patch)
tree4ccd25dd9de4835a551534de37a931e2105fa4d3
parentf75b524b060682a896ac7a3951ac677d29e15727 (diff)
downloadQt-9f941fd65083ae6d3f2f5441bf60346821932218.zip
Qt-9f941fd65083ae6d3f2f5441bf60346821932218.tar.gz
Qt-9f941fd65083ae6d3f2f5441bf60346821932218.tar.bz2
Add a declarative data ptr to QObjectPrivate
This data ptr does not increase the size of the QObject, as we take advantage of space only used during destruction. Currently this data is only used to store an object's QmlContext, but it will be used for more later.
-rw-r--r--src/corelib/kernel/qobject.cpp8
-rw-r--r--src/corelib/kernel/qobject_p.h12
-rw-r--r--src/declarative/extra/qmlsqlconnection.cpp8
-rw-r--r--src/declarative/extra/qmlxmllistmodel.cpp6
-rw-r--r--src/declarative/fx/qfxhighlightfilter.cpp8
-rw-r--r--src/declarative/fx/qfxitem.cpp3
-rw-r--r--src/declarative/fx/qfxitem_p.h2
-rw-r--r--src/declarative/fx/qfxvisualitemmodel.cpp10
-rw-r--r--src/declarative/qml/qml.h5
-rw-r--r--src/declarative/qml/qmlcompiler.cpp9
-rw-r--r--src/declarative/qml/qmlcompiler_p.h3
-rw-r--r--src/declarative/qml/qmlcontext.cpp2
-rw-r--r--src/declarative/qml/qmlcontext_p.h7
-rw-r--r--src/declarative/qml/qmlengine.cpp33
-rw-r--r--src/declarative/qml/qmlengine.h2
-rw-r--r--src/declarative/qml/qmlvme.cpp3
-rw-r--r--src/declarative/util/qmlanimation.cpp2
-rw-r--r--src/declarative/util/qmlanimation_p.h3
-rw-r--r--src/declarative/util/qmlbehaviour.cpp9
-rw-r--r--src/declarative/util/qmlconnection.cpp9
-rw-r--r--src/declarative/util/qmllistmodel.cpp11
-rw-r--r--src/declarative/util/qmlscript.cpp20
-rw-r--r--src/declarative/util/qmlstateoperations.cpp7
23 files changed, 115 insertions, 67 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 638c7d1..220e132 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -842,6 +842,14 @@ QObject::~QObject()
d->eventFilters.clear();
+ // As declarativeData is in a union with currentChildBeingDeleted, this must
+ // be done (and declarativeData set back to 0) before deleting children.
+ if(d->declarativeData) {
+ QDeclarativeData *dd = d->declarativeData;
+ d->declarativeData = 0;
+ dd->destroyed(this);
+ }
+
if (!d->children.isEmpty())
d->deleteChildren();
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 31b1593..81d3aba 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -85,6 +85,13 @@ inline QObjectData::~QObjectData() {}
enum { QObjectPrivateVersion = QT_VERSION };
+class Q_CORE_EXPORT QDeclarativeData
+{
+public:
+ virtual ~QDeclarativeData() {}
+ virtual void destroyed(QObject *) {}
+};
+
class Q_CORE_EXPORT QObjectPrivate : public QObjectData
{
Q_DECLARE_PUBLIC(QObject)
@@ -118,7 +125,10 @@ public:
// object currently activating the object
Sender *currentSender;
- QObject *currentChildBeingDeleted;
+ union {
+ QObject *currentChildBeingDeleted;
+ QDeclarativeData *declarativeData;
+ };
bool isSender(const QObject *receiver, const char *signal) const;
QObjectList receiverList(const char *signal) const;
diff --git a/src/declarative/extra/qmlsqlconnection.cpp b/src/declarative/extra/qmlsqlconnection.cpp
index 3e2032c..7f1fec2 100644
--- a/src/declarative/extra/qmlsqlconnection.cpp
+++ b/src/declarative/extra/qmlsqlconnection.cpp
@@ -62,7 +62,6 @@ public:
int port;
QString name, databaseName, connectionOptions;
QString hostName, userName, password, driver;
- QmlContext *context;
};
/*!
@@ -177,8 +176,6 @@ public:
QmlSqlConnection::QmlSqlConnection(QObject *parent)
: QObject(*(new QmlSqlConnectionPrivate), parent)
{
- Q_D(QmlSqlConnection);
- d->context = QmlContext::activeContext();
}
/*!
@@ -416,10 +413,11 @@ QSqlDatabase QmlSqlConnection::database() const
}
if (db.isOpen())
return db;
- if ((d->driver.isEmpty() || d->driver == QLatin1String("QSQLITE")) && d->context) {
+ if ((d->driver.isEmpty() || d->driver == QLatin1String("QSQLITE")) &&
+ qmlContext(this)) {
// SQLITE uses files for databases, hence use relative pathing
// if possible.
- QUrl url = d->context->resolvedUrl(d->databaseName);
+ QUrl url = qmlContext(this)->resolvedUrl(d->databaseName);
if (url.isRelative() || url.scheme() == QLatin1String("file"))
db.setDatabaseName(url.toLocalFile());
else
diff --git a/src/declarative/extra/qmlxmllistmodel.cpp b/src/declarative/extra/qmlxmllistmodel.cpp
index 13faab2..44787b5 100644
--- a/src/declarative/extra/qmlxmllistmodel.cpp
+++ b/src/declarative/extra/qmlxmllistmodel.cpp
@@ -87,7 +87,7 @@ class QmlXmlListModelPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlXmlListModel)
public:
- QmlXmlListModelPrivate() : size(-1), highestRole(Qt::UserRole), reply(0), context(0), roleObjects(this) {}
+ QmlXmlListModelPrivate() : size(-1), highestRole(Qt::UserRole), reply(0), roleObjects(this) {}
QString src;
QString query;
@@ -100,7 +100,6 @@ public:
QNetworkReply *reply;
mutable QByteArray xml;
QString prefix;
- QmlContext *context;
struct RoleList : public QmlConcreteList<XmlListModelRole *>
{
@@ -144,7 +143,6 @@ QmlXmlListModel::QmlXmlListModel(QObject *parent)
: QListModelInterface(*(new QmlXmlListModelPrivate), parent)
{
Q_D(QmlXmlListModel);
- d->context = QmlContext::activeContext();
}
QmlXmlListModel::~QmlXmlListModel()
@@ -249,7 +247,7 @@ void QmlXmlListModel::fetch()
QNetworkRequest req((QUrl(d->src)));
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
- d->reply = d->context->engine()->networkAccessManager()->get(req);
+ d->reply = qmlContext(this)->engine()->networkAccessManager()->get(req);
QObject::connect(d->reply, SIGNAL(finished()),
this, SLOT(requestFinished()));
}
diff --git a/src/declarative/fx/qfxhighlightfilter.cpp b/src/declarative/fx/qfxhighlightfilter.cpp
index d1ff3d3..d99b9e5 100644
--- a/src/declarative/fx/qfxhighlightfilter.cpp
+++ b/src/declarative/fx/qfxhighlightfilter.cpp
@@ -56,10 +56,8 @@ class QFxHighlightFilterPrivate
{
public:
QFxHighlightFilterPrivate()
- : ctxt(QmlContext::activeContext()),
- xOffset(0), yOffset(0), tiled(false) {}
+ : xOffset(0), yOffset(0), tiled(false) {}
- QmlContext *ctxt;
QString source;
QUrl url;
int xOffset;
@@ -147,12 +145,12 @@ void QFxHighlightFilter::setSource(const QString &f)
if(!d->source.isEmpty())
QFxPixmap::cancelGet(d->url, this, SLOT(imageLoaded()));
d->source = f;
- d->url = QmlContext::activeContext()->resolvedUrl(f);
+ d->url = qmlContext(this)->resolvedUrl(f);
#if defined(QFX_RENDER_OPENGL2)
d->tex.clear();
#endif
if(!f.isEmpty())
- QFxPixmap::get(d->ctxt->engine(), d->url, this, SLOT(imageLoaded()));
+ QFxPixmap::get(qmlEngine(this), d->url, this, SLOT(imageLoaded()));
else
emit sourceChanged(d->source);
}
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 0ee734b..6e8a07d 100644
--- a/src/declarative/fx/qfxitem.cpp
+++ b/src/declarative/fx/qfxitem.cpp
@@ -1987,8 +1987,7 @@ void QFxItem::transformChanged(const QSimpleCanvas::Matrix &)
*/
QmlContext *QFxItem::itemContext() const
{
- Q_D(const QFxItem);
- return d->_ctxt;
+ return QmlEngine::contextForObject(this);
}
QmlStateGroup *QFxItemPrivate::states()
diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h
index 1266711..71fc912 100644
--- a/src/declarative/fx/qfxitem_p.h
+++ b/src/declarative/fx/qfxitem_p.h
@@ -84,7 +84,6 @@ public:
void init(QFxItem *parent)
{
Q_Q(QFxItem);
- _ctxt = QmlContext::activeContext();
if(parent)
q->setItemParent(parent);
@@ -92,7 +91,6 @@ public:
q->setAcceptedMouseButtons(Qt::NoButton);
}
- QmlContext *_ctxt;
QString _id;
// data property
diff --git a/src/declarative/fx/qfxvisualitemmodel.cpp b/src/declarative/fx/qfxvisualitemmodel.cpp
index 145e750..dc68026 100644
--- a/src/declarative/fx/qfxvisualitemmodel.cpp
+++ b/src/declarative/fx/qfxvisualitemmodel.cpp
@@ -285,7 +285,7 @@ QFxVisualItemModelData *QFxVisualItemModelPrivate::data(QObject *item)
}
QFxVisualItemModel::QFxVisualItemModel()
-: QObject(*(new QFxVisualItemModelPrivate(QmlContext::activeContext())))
+: QObject(*(new QFxVisualItemModelPrivate(0)))
{
}
@@ -489,7 +489,9 @@ QFxItem *QFxVisualItemModel::item(int index, const QByteArray &viewId, bool comp
if(d->m_cache.contains(index)) {
nobj = d->m_cache[index];
} else {
- QmlContext *ctxt = new QmlContext(d->m_context);
+ QmlContext *ccontext = d->m_context;
+ if(!ccontext) ccontext = qmlContext(this);
+ QmlContext *ctxt = new QmlContext(ccontext);
QFxVisualItemModelData *data = new QFxVisualItemModelData(index, d);
ctxt->setContextProperty(QLatin1String("model"), data);
ctxt->addDefaultObject(data);
@@ -545,7 +547,9 @@ QVariant QFxVisualItemModel::evaluate(int index, const QString &expression, QObj
value = e.value();
}
} else {
- QmlContext *ctxt = new QmlContext(d->m_context);
+ QmlContext *ccontext = d->m_context;
+ if(!ccontext) ccontext = qmlContext(this);
+ QmlContext *ctxt = new QmlContext(ccontext);
QFxVisualItemModelData *data = new QFxVisualItemModelData(index, d);
ctxt->addDefaultObject(data);
QmlExpression e(ctxt, expression, objectContext);
diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h
index bf7b6bc..fb288b7 100644
--- a/src/declarative/qml/qml.h
+++ b/src/declarative/qml/qml.h
@@ -88,6 +88,11 @@ QT_MODULE(Declarative)
#define QML_DEFINE_NOCREATE_TYPE(TYPE) \
template<> QmlPrivate::InstanceType QmlPrivate::Define<TYPE *>::instance(qmlRegisterType<TYPE>(#TYPE));
+class QmlContext;
+class QmlEngine;
+Q_DECLARATIVE_EXPORT QmlContext *qmlContext(const QObject *);
+Q_DECLARATIVE_EXPORT QmlEngine *qmlEngine(const QObject *);
+
QML_DECLARE_TYPE(QObject);
Q_DECLARE_METATYPE(QVariant);
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index f03ce20..5436227 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -1647,12 +1647,15 @@ QmlCompiledData &QmlCompiledData::operator=(const QmlCompiledData &other)
return *this;
}
-QObject *QmlCompiledData::TypeReference::createInstance() const
+QObject *QmlCompiledData::TypeReference::createInstance(QmlContext *ctxt) const
{
if(type) {
- return type->create();
+ QObject *rv = type->create();
+ if(rv)
+ QmlEngine::setContextForObject(rv, ctxt);
+ return rv;
} else if(component) {
- return component->create(QmlContext::activeContext());
+ return component->create(ctxt);
} else {
return 0;
}
diff --git a/src/declarative/qml/qmlcompiler_p.h b/src/declarative/qml/qmlcompiler_p.h
index 754e284..286cda8 100644
--- a/src/declarative/qml/qmlcompiler_p.h
+++ b/src/declarative/qml/qmlcompiler_p.h
@@ -54,6 +54,7 @@ class QmlXmlParser;
class QmlEngine;
class QmlComponent;
class QmlCompiledComponent;
+class QmlContext;
namespace QmlParser {
class Object;
@@ -83,7 +84,7 @@ public:
QmlCustomParser *parser;
QmlRefCount *ref;
- QObject *createInstance() const;
+ QObject *createInstance(QmlContext *) const;
};
QList<TypeReference> types;
struct CustomTypeData
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index 104f460..40e33c2 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -96,6 +96,8 @@ void QmlContextPrivate::init()
else
scopeChain = parent->d_func()->scopeChain;
scopeChain.prepend(scopeObj);
+
+ contextData.context = q;
}
void QmlContextPrivate::addDefaultObject(QObject *object, Priority priority)
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index 8c51a6b..aa0bf3e 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -81,6 +81,13 @@ public:
NormalPriority
};
void addDefaultObject(QObject *, Priority);
+
+ class ContextData : public QDeclarativeData
+ {
+ public:
+ QmlContext *context;
+ };
+ ContextData contextData;
};
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 5cbd02b..66c41f2 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -42,6 +42,7 @@
#include <QMetaProperty>
#include <private/qmlengine_p.h>
#include <private/qmlcontext_p.h>
+#include <private/qobject_p.h>
#ifdef QT_SCRIPTTOOLS_LIB
#include <QScriptEngineDebugger>
@@ -595,6 +596,38 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const
return d->networkAccessManager;
}
+QmlContext *QmlEngine::contextForObject(const QObject *object)
+{
+ QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
+ if(priv->declarativeData) {
+ return static_cast<QmlContextPrivate::ContextData *>(priv->declarativeData)->context;
+ } else {
+ return 0;
+ }
+}
+
+QmlContext *qmlContext(const QObject *obj)
+{
+ return QmlEngine::contextForObject(obj);
+}
+
+QmlEngine *qmlEngine(const QObject *obj)
+{
+ QmlContext *context = QmlEngine::contextForObject(obj);
+ return context?context->engine():0;
+}
+
+
+void QmlEngine::setContextForObject(QObject *object, QmlContext *context)
+{
+ QObjectPrivate *priv = QObjectPrivate::get(object);
+ if(priv->declarativeData) {
+ qWarning("QmlEngine::setContextForObject(): Object already has a QmlContext");
+ return;
+ }
+ priv->declarativeData = &context->d_func()->contextData;
+}
+
/*! \internal */
QScriptEngine *QmlEngine::scriptEngine()
{
diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h
index 086595a..fde84d4 100644
--- a/src/declarative/qml/qmlengine.h
+++ b/src/declarative/qml/qmlengine.h
@@ -81,6 +81,8 @@ public:
void setNetworkAccessManager(QNetworkAccessManager *);
QNetworkAccessManager *networkAccessManager() const;
+ static QmlContext *contextForObject(const QObject *);
+ static void setContextForObject(QObject *, QmlContext *);
private:
// LK: move to the private class
QScriptEngine *scriptEngine();
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index 966ef8a..b6d9173 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -253,7 +253,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in
#ifdef Q_ENABLE_PERFORMANCE_LOG
QFxCompilerTimer<QFxCompiler::InstrCreateObject> cc;
#endif
- QObject *o = types.at(instr.create.type).createInstance();
+ QObject *o = types.at(instr.create.type).createInstance(QmlContext::activeContext());
if(!o)
VME_EXCEPTION("Unable to create object of type" << types.at(instr.create.type).className);
@@ -276,6 +276,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledComponent *comp, int start, in
QObject *o = QmlMetaType::toQObject(v);
if(!o)
VME_EXCEPTION("Unable to create" << types.at(instr.create.type).className);
+ QmlEngine::setContextForObject(o, QmlContext::activeContext());
if(!stack.isEmpty()) {
QObject *parent = stack.top();
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index ede4008..3be714a 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -1004,7 +1004,7 @@ void QmlRunScriptActionPrivate::execute()
}
if(!scriptStr.isEmpty()) {
- QmlExpression expr(ctxt, scriptStr, q);
+ QmlExpression expr(qmlContext(q), scriptStr, q);
expr.setTrackChange(false);
expr.value();
}
diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h
index db7cb18..e07fa78 100644
--- a/src/declarative/util/qmlanimation_p.h
+++ b/src/declarative/util/qmlanimation_p.h
@@ -225,13 +225,12 @@ class QmlRunScriptActionPrivate : public QmlAbstractAnimationPrivate
Q_DECLARE_PUBLIC(QmlRunScriptAction);
public:
QmlRunScriptActionPrivate()
- : QmlAbstractAnimationPrivate(), ctxt(QmlContext::activeContext()), proxy(this), rsa(0) {}
+ : QmlAbstractAnimationPrivate(), proxy(this), rsa(0) {}
void init();
QString script;
QString file;
- QmlContext* ctxt;
void execute();
diff --git a/src/declarative/util/qmlbehaviour.cpp b/src/declarative/util/qmlbehaviour.cpp
index 3169f63..3fff06c 100644
--- a/src/declarative/util/qmlbehaviour.cpp
+++ b/src/declarative/util/qmlbehaviour.cpp
@@ -76,14 +76,13 @@ class QmlBehaviourPrivate : public QObjectPrivate
{
public:
QmlBehaviourPrivate()
- : context(0), oldContext(0), valueData(0), operations(this) {}
+ : context(0), valueData(0), operations(this) {}
QmlMetaProperty property;
QVariant currentValue;
QVariant fromValue;
QVariant toValue;
QmlContext *context;
- QmlContext *oldContext;
QmlBehaviourData *valueData;
class AnimationList : public QmlConcreteList<QmlAbstractAnimation *>
{
@@ -123,8 +122,6 @@ QmlBehaviour::QmlBehaviour(QObject *parent)
{
Q_D(QmlBehaviour);
d->valueData = new QmlBehaviourData(this);
- d->context = new QmlContext(QmlContext::activeContext(), this);
- d->context->addDefaultObject(d->valueData);
d->group = new QSequentialAnimationGroup(this);
}
@@ -234,6 +231,10 @@ void QmlBehaviour::setTarget(const QmlMetaProperty &property)
void QmlBehaviour::classBegin()
{
Q_D(QmlBehaviour);
+ if(!d->context) {
+ d->context = new QmlContext(qmlContext(this), this);
+ d->context->addDefaultObject(d->valueData);
+ }
d->context->activate();
}
diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp
index df45a31..b2fd450 100644
--- a/src/declarative/util/qmlconnection.cpp
+++ b/src/declarative/util/qmlconnection.cpp
@@ -51,9 +51,8 @@ QT_BEGIN_NAMESPACE
class QmlConnectionPrivate : public QObjectPrivate
{
public:
- QmlConnectionPrivate() : ctxt(0), boundsignal(0), signalSender(0), componentcomplete(false) {}
+ QmlConnectionPrivate() : boundsignal(0), signalSender(0), componentcomplete(false) {}
- QmlContext *ctxt;
QmlBoundSignal *boundsignal;
QObject *signalSender;
QString script;
@@ -112,8 +111,6 @@ public:
QmlConnection::QmlConnection(QObject *parent) :
QObject(*(new QmlConnectionPrivate), parent)
{
- Q_D(QmlConnection);
- d->ctxt = QmlContext::activeContext();
}
QmlConnection::~QmlConnection()
@@ -192,9 +189,9 @@ void QmlConnection::connectIfValid()
}
if (sigparams.isEmpty())
- d->boundsignal = new QmlBoundSignal(d->ctxt, d->script, sender, sigIdx, this);
+ d->boundsignal = new QmlBoundSignal(qmlContext(this), d->script, sender, sigIdx, this);
else
- d->boundsignal = new QmlBoundSignalProxy(new QmlContext(d->ctxt,this), d->script, sender, sigIdx, this);
+ d->boundsignal = new QmlBoundSignalProxy(new QmlContext(qmlContext(this),this), d->script, sender, sigIdx, this);
}
}
diff --git a/src/declarative/util/qmllistmodel.cpp b/src/declarative/util/qmllistmodel.cpp
index 992185a..24f2d5c 100644
--- a/src/declarative/util/qmllistmodel.cpp
+++ b/src/declarative/util/qmllistmodel.cpp
@@ -537,7 +537,6 @@ ModelNode::~ModelNode()
struct ListModelData
{
int dataOffset;
- int id;
int instrCount;
ListInstruction *instructions() const { return (ListInstruction *)((char *)this + sizeof(ListModelData)); }
};
@@ -546,7 +545,6 @@ QByteArray ListModelParser::compile(QXmlStreamReader& reader, bool *ok)
{
*ok = true;
- QByteArray id;
QByteArray data;
QList<ListInstruction> instr;
int depth=0;
@@ -649,10 +647,6 @@ QByteArray ListModelParser::compile(QXmlStreamReader& reader, bool *ok)
rv.resize(size);
ListModelData *lmd = (ListModelData *)rv.data();
- if(id.count())
- lmd->id = 0;
- else
- lmd->id = -1;
lmd->dataOffset = sizeof(ListModelData) +
instr.count() * sizeof(ListInstruction);
lmd->instrCount = instr.count();
@@ -709,11 +703,6 @@ QVariant ListModelParser::create(const QByteArray &d)
}
}
- if(lmd->id != -1) {
- QmlContext *ctxt = QmlContext::activeContext();
- ctxt->setContextProperty(QLatin1String(data + lmd->id), rv);
- }
-
return QVariant::fromValue(rv);
}
diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp
index 859e21e..73c8c07 100644
--- a/src/declarative/util/qmlscript.cpp
+++ b/src/declarative/util/qmlscript.cpp
@@ -65,7 +65,7 @@ class QmlScriptPrivate : public QObjectPrivate
Q_DECLARE_PUBLIC(QmlScript);
public:
- QmlScriptPrivate() : reply(0), ctxt(0) {}
+ QmlScriptPrivate() : reply(0) {}
void addScriptToEngine(const QString &, const QString &fileName=QString());
@@ -73,7 +73,6 @@ public:
QString source;
QNetworkReply *reply;
QUrl url;
- QmlContext *ctxt;
};
/*!
@@ -106,8 +105,6 @@ public:
QML_DEFINE_TYPE(QmlScript,Script);
QmlScript::QmlScript(QObject *parent) : QObject(*(new QmlScriptPrivate), parent)
{
- Q_D(QmlScript);
- d->ctxt = QmlContext::activeContext();
}
/*!
@@ -154,10 +151,10 @@ void QmlScript::setSource(const QString &source)
if (d->source == source)
return;
d->source = source;
- d->url = d->ctxt->resolvedUrl(source);
+ d->url = qmlContext(this)->resolvedUrl(source);
QNetworkRequest req(d->url);
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
- d->reply = d->ctxt->engine()->networkAccessManager()->get(req);
+ d->reply = qmlEngine(this)->networkAccessManager()->get(req);
QObject::connect(d->reply, SIGNAL(finished()),
this, SLOT(replyFinished()));
}
@@ -176,7 +173,8 @@ void QmlScript::replyFinished()
void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &fileName)
{
Q_Q(QmlScript);
- QmlEngine *engine = ctxt->engine();
+ QmlEngine *engine = qmlEngine(q);
+ QmlContext *context = qmlContext(q);
QScriptEngine *scriptEngine = engine->scriptEngine();
QScriptContext *currentContext = engine->scriptEngine()->currentContext();
@@ -186,11 +184,11 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &f
for (int i = 0; i < oldScopeChain.size(); ++i) {
currentContext->popScope();
}
- for (int i = ctxt->d_func()->scopeChain.size() - 1; i > -1; --i) {
- currentContext->pushScope(ctxt->d_func()->scopeChain.at(i));
+ for (int i = context->d_func()->scopeChain.size() - 1; i > -1; --i) {
+ currentContext->pushScope(context->d_func()->scopeChain.at(i));
}
- currentContext->setActivationObject(ctxt->d_func()->scopeChain.at(0));
+ currentContext->setActivationObject(context->d_func()->scopeChain.at(0));
QScriptValue val = scriptEngine->evaluate(script, fileName);
if (scriptEngine->hasUncaughtException()) {
@@ -209,7 +207,7 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &f
currentContext->setActivationObject(oldact);
- for (int i = 0; i < ctxt->d_func()->scopeChain.size(); ++i)
+ for (int i = 0; i < context->d_func()->scopeChain.size(); ++i)
currentContext->popScope();
for (int i = oldScopeChain.size() - 1; i > -1; --i)
diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp
index a8779f9..594e6fa 100644
--- a/src/declarative/util/qmlstateoperations.cpp
+++ b/src/declarative/util/qmlstateoperations.cpp
@@ -137,9 +137,8 @@ QmlStateOperation::ActionList QmlParentChange::actions()
class QmlRunScriptPrivate : public QObjectPrivate
{
public:
- QmlRunScriptPrivate() : ctxt(0) {}
+ QmlRunScriptPrivate() {}
- QmlContext *ctxt;
QString script;
QString name;
};
@@ -152,8 +151,6 @@ QML_DEFINE_TYPE(QmlRunScript,RunScript);
QmlRunScript::QmlRunScript(QObject *parent)
: QmlStateOperation(*(new QmlRunScriptPrivate), parent)
{
- Q_D(QmlRunScript);
- d->ctxt = QmlContext::activeContext();
}
QmlRunScript::~QmlRunScript()
@@ -192,7 +189,7 @@ void QmlRunScript::execute()
{
Q_D(QmlRunScript);
if(!d->script.isEmpty()) {
- QmlExpression expr(d->ctxt, d->script, this);
+ QmlExpression expr(qmlContext(this), d->script, this);
expr.setTrackChange(false);
expr.value();
}