summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:53:04 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-04-15 06:53:04 (GMT)
commiteaf1a714c2bcd087a538ba6c11bb656181923a8c (patch)
tree51eda11f672321c97017e4422759d681ba04754a /src/declarative
parent5783d51bcaed2a769c222ae7f6123f7638d6388a (diff)
parentd8a49ccfb8308aec11cd24e823c297ef157cc4c6 (diff)
downloadQt-eaf1a714c2bcd087a538ba6c11bb656181923a8c.zip
Qt-eaf1a714c2bcd087a538ba6c11bb656181923a8c.tar.gz
Qt-eaf1a714c2bcd087a538ba6c11bb656181923a8c.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp31
-rw-r--r--src/declarative/qml/qdeclarativecompiler_p.h2
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp47
-rw-r--r--src/declarative/qml/qdeclarativecomponent_p.h19
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp57
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h7
-rw-r--r--src/declarative/qml/qdeclarativedata_p.h4
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp13
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp34
-rw-r--r--src/declarative/qml/qdeclarativeproperty_p.h3
-rw-r--r--src/declarative/qml/qdeclarativepropertycache.cpp6
12 files changed, 126 insertions, 99 deletions
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index fad7779..5c5ad37 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -1364,35 +1364,6 @@ int QDeclarativeCompiler::componentTypeRef()
return output->types.count() - 1;
}
-QMetaMethod QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name)
-{
- Q_ASSERT(mo);
- int methods = mo->methodCount();
- for (int ii = methods - 1; ii >= 0; --ii) {
- QMetaMethod method = mo->method(ii);
- QByteArray methodName = method.signature();
- int idx = methodName.indexOf('(');
- methodName = methodName.left(idx);
-
- if (methodName == name)
- return method;
- }
-
- // If no signal is found, but the signal is of the form "onBlahChanged",
- // return the notify signal for the property "Blah"
- if (name.endsWith("Changed")) {
- QByteArray propName = name.mid(0, name.length() - 7);
- int propIdx = mo->indexOfProperty(propName.constData());
- if (propIdx >= 0) {
- QMetaProperty prop = mo->property(propIdx);
- if (prop.hasNotifySignal())
- return prop.notifySignal();
- }
- }
-
- return QMetaMethod();
-}
-
bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
const BindingContext &ctxt)
{
@@ -1404,7 +1375,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl
if(name[0] >= 'A' && name[0] <= 'Z')
name[0] = name[0] - 'A' + 'a';
- int sigIdx = findSignalByName(obj->metaObject(), name).methodIndex();
+ int sigIdx = QDeclarativePropertyPrivate::findSignalByName(obj->metaObject(), name).methodIndex();
if (sigIdx == -1) {
diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h
index 0e47774..002c6c9 100644
--- a/src/declarative/qml/qdeclarativecompiler_p.h
+++ b/src/declarative/qml/qdeclarativecompiler_p.h
@@ -159,8 +159,6 @@ public:
static bool isAttachedPropertyName(const QByteArray &);
static bool isSignalPropertyName(const QByteArray &);
- static QMetaMethod findSignalByName(const QMetaObject *, const QByteArray &name);
-
int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
private:
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index 1903006..5cc6639 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -657,11 +657,11 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe
state->bindValues = enginePriv->bindValues;
state->parserStatus = enginePriv->parserStatus;
- state->componentAttacheds = enginePriv->componentAttacheds;
- if (state->componentAttacheds)
- state->componentAttacheds->prev = &state->componentAttacheds;
+ state->componentAttached = enginePriv->componentAttached;
+ if (state->componentAttached)
+ state->componentAttached->prev = &state->componentAttached;
- enginePriv->componentAttacheds = 0;
+ enginePriv->componentAttached = 0;
enginePriv->bindValues.clear();
enginePriv->parserStatus.clear();
state->completePending = true;
@@ -671,7 +671,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe
return rv;
}
-void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContextData *, QDeclarativeEnginePrivate *enginePriv,
+void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeEnginePrivate *enginePriv,
QObject *object, ConstructionState *state)
{
bool isRoot = !enginePriv->inBeginCreate;
@@ -688,11 +688,11 @@ void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContextData *, QDec
state->bindValues = enginePriv->bindValues;
state->parserStatus = enginePriv->parserStatus;
- state->componentAttacheds = enginePriv->componentAttacheds;
- if (state->componentAttacheds)
- state->componentAttacheds->prev = &state->componentAttacheds;
+ state->componentAttached = enginePriv->componentAttached;
+ if (state->componentAttached)
+ state->componentAttached->prev = &state->componentAttached;
- enginePriv->componentAttacheds = 0;
+ enginePriv->componentAttached = 0;
enginePriv->bindValues.clear();
enginePriv->parserStatus.clear();
state->completePending = true;
@@ -729,11 +729,13 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri
QDeclarativeEnginePrivate::clear(ps);
}
- while (state->componentAttacheds) {
- QDeclarativeComponentAttached *a = state->componentAttacheds;
- if (a->next) a->next->prev = &state->componentAttacheds;
- state->componentAttacheds = a->next;
- a->prev = 0; a->next = 0;
+ while (state->componentAttached) {
+ QDeclarativeComponentAttached *a = state->componentAttached;
+ a->rem();
+ QDeclarativeData *d = QDeclarativeData::get(a->parent());
+ Q_ASSERT(d);
+ Q_ASSERT(d->context);
+ a->add(&d->context->componentAttached);
emit a->completed();
}
@@ -793,15 +795,18 @@ QDeclarativeComponentAttached *QDeclarativeComponent::qmlAttachedProperties(QObj
QDeclarativeComponentAttached *a = new QDeclarativeComponentAttached(obj);
QDeclarativeEngine *engine = qmlEngine(obj);
- if (!engine || !QDeclarativeEnginePrivate::get(engine)->inBeginCreate)
+ if (!engine)
return a;
- QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
-
- a->next = p->componentAttacheds;
- a->prev = &p->componentAttacheds;
- if (a->next) a->next->prev = &a->next;
- p->componentAttacheds = a;
+ if (QDeclarativeEnginePrivate::get(engine)->inBeginCreate) {
+ QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine);
+ a->add(&p->componentAttached);
+ } else {
+ QDeclarativeData *d = QDeclarativeData::get(obj);
+ Q_ASSERT(d);
+ Q_ASSERT(d->context);
+ a->add(&d->context->componentAttached);
+ }
return a;
}
diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h
index dfe327b..24e5386 100644
--- a/src/declarative/qml/qdeclarativecomponent_p.h
+++ b/src/declarative/qml/qdeclarativecomponent_p.h
@@ -99,10 +99,10 @@ public:
QDeclarativeCompiledData *cc;
struct ConstructionState {
- ConstructionState() : componentAttacheds(0), completePending(false) {}
+ ConstructionState() : componentAttached(0), completePending(false) {}
QList<QDeclarativeEnginePrivate::SimpleList<QDeclarativeAbstractBinding> > bindValues;
QList<QDeclarativeEnginePrivate::SimpleList<QDeclarativeParserStatus> > parserStatus;
- QDeclarativeComponentAttached *componentAttacheds;
+ QDeclarativeComponentAttached *componentAttached;
QList<QDeclarativeError> errors;
bool completePending;
};
@@ -111,8 +111,8 @@ public:
static QObject *begin(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv,
QDeclarativeCompiledData *component, int start, int count,
ConstructionState *state, const QBitField &bindings = QBitField());
- static void beginDeferred(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv,
- QObject *object, ConstructionState *state);
+ static void beginDeferred(QDeclarativeEnginePrivate *enginePriv, QObject *object,
+ ConstructionState *state);
static void complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state);
QDeclarativeEngine *engine;
@@ -132,13 +132,24 @@ public:
QDeclarativeComponentAttached(QObject *parent = 0);
~QDeclarativeComponentAttached();
+ void add(QDeclarativeComponentAttached **a) {
+ prev = a; next = *a; *a = this;
+ if (next) next->prev = &next;
+ }
+ void rem() {
+ if (next) next->prev = prev;
+ *prev = next;
+ next = 0; prev = 0;
+ }
QDeclarativeComponentAttached **prev;
QDeclarativeComponentAttached *next;
Q_SIGNALS:
void completed();
+ void destruction();
private:
+ friend class QDeclarativeContextData;;
friend class QDeclarativeComponentPrivate;
};
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 42e7386..6657fea 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -42,6 +42,7 @@
#include "qdeclarativecontext.h"
#include "private/qdeclarativecontext_p.h"
+#include "private/qdeclarativecomponent_p.h"
#include "private/qdeclarativeexpression_p.h"
#include "private/qdeclarativeengine_p.h"
#include "qdeclarativeengine.h"
@@ -476,21 +477,34 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject
QDeclarativeContextData::QDeclarativeContextData()
: parent(0), engine(0), isInternal(false), publicContext(0), propertyNames(0), contextObject(0),
imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0),
- contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0)
+ contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0),
+ componentAttached(0)
{
}
QDeclarativeContextData::QDeclarativeContextData(QDeclarativeContext *ctxt)
: parent(0), engine(0), isInternal(false), publicContext(ctxt), propertyNames(0), contextObject(0),
imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0),
- contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0)
+ contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0),
+ componentAttached(0)
{
}
-void QDeclarativeContextData::destroy()
+void QDeclarativeContextData::invalidate()
{
- if (linkedContext)
- linkedContext->destroy();
+ while (childContexts)
+ childContexts->invalidate();
+
+ while (componentAttached) {
+ QDeclarativeComponentAttached *a = componentAttached;
+ componentAttached = a->next;
+ if (componentAttached) componentAttached->prev = &componentAttached;
+
+ a->next = 0;
+ a->prev = 0;
+
+ emit a->destruction();
+ }
if (prevChild) {
*prevChild = nextChild;
@@ -498,19 +512,17 @@ void QDeclarativeContextData::destroy()
nextChild = 0;
prevChild = 0;
}
-
- QDeclarativeContextData *child = childContexts;
- while (child) {
- QDeclarativeContextData *next = child->nextChild;
- child->invalidateEngines();
- child->parent = 0;
- child->nextChild = 0;
- child->prevChild = 0;
+ engine = 0;
+ parent = 0;
+}
- child = next;
- }
- childContexts = 0;
+void QDeclarativeContextData::destroy()
+{
+ if (linkedContext)
+ linkedContext->destroy();
+
+ if (engine) invalidate();
QDeclarativeAbstractExpression *expression = expressions;
while (expression) {
@@ -573,19 +585,6 @@ void QDeclarativeContextData::setParent(QDeclarativeContextData *p)
}
}
-void QDeclarativeContextData::invalidateEngines()
-{
- if (!engine)
- return;
- engine = 0;
-
- QDeclarativeContextData *child = childContexts;
- while (child) {
- child->invalidateEngines();
- child = child->nextChild;
- }
-}
-
/*
Refreshes all expressions that could possibly depend on this context. Refreshing flushes all
context-tree dependent caches in the expressions, and should occur every time the context tree
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index 5d26e7e..77a6d94 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -106,6 +106,7 @@ public:
static QObject *context_at(QDeclarativeListProperty<QObject> *, int);
};
+class QDeclarativeComponentAttached;
class QDeclarativeGuardedContextData;
class QDeclarativeContextData
{
@@ -113,6 +114,7 @@ public:
QDeclarativeContextData();
QDeclarativeContextData(QDeclarativeContext *);
void destroy();
+ void invalidate();
inline bool isValid() const {
return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted);
@@ -123,7 +125,6 @@ public:
QDeclarativeEngine *engine;
void setParent(QDeclarativeContextData *);
- void invalidateEngines();
void refreshExpressions();
void addObject(QObject *);
@@ -194,6 +195,10 @@ public:
// Linked contexts. this owns linkedContext.
QDeclarativeContextData *linkedContext;
+ // Linked list of uses of the Component attached property in this
+ // context
+ QDeclarativeComponentAttached *componentAttached;
+
QString findObjectId(const QObject *obj) const;
static QDeclarativeContextData *get(QDeclarativeContext *context) {
diff --git a/src/declarative/qml/qdeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h
index 3676d8d..2ddd7e5 100644
--- a/src/declarative/qml/qdeclarativedata_p.h
+++ b/src/declarative/qml/qdeclarativedata_p.h
@@ -100,7 +100,9 @@ public:
quint32 explicitIndestructibleSet:1;
quint32 dummy:28;
- QDeclarativeContextData *context;
+ // The context that created the C++ object
+ QDeclarativeContextData *context;
+ // The outermost context in which this object lives
QDeclarativeContextData *outerContext;
QDeclarativeAbstractBinding *bindings;
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index ae0929b..1deadb2 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -155,7 +155,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e)
: captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false),
contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0),
globalClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0),
- scriptEngine(this), workerScriptEngine(0), componentAttacheds(0), inBeginCreate(false),
+ scriptEngine(this), workerScriptEngine(0), componentAttached(0), inBeginCreate(false),
networkAccessManager(0), networkAccessManagerFactory(0),
typeManager(e), uniqueId(1)
{
@@ -350,8 +350,13 @@ typedef QMap<QString, QString> StringStringMap;
Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri
-void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *)
+void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o)
{
+ QObjectPrivate *p = QObjectPrivate::get(o);
+ Q_ASSERT(p->declarativeData);
+ QDeclarativeData *d = static_cast<QDeclarativeData*>(p->declarativeData);
+ if (d->ownContext)
+ d->context->destroy();
}
void QDeclarativeData::destroyed(QAbstractDeclarativeData *d, QObject *o)
@@ -767,7 +772,7 @@ void qmlExecuteDeferred(QObject *object)
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(data->context->engine);
QDeclarativeComponentPrivate::ConstructionState state;
- QDeclarativeComponentPrivate::beginDeferred(data->context, ep, object, &state);
+ QDeclarativeComponentPrivate::beginDeferred(ep, object, &state);
data->deferredComponent->release();
data->deferredComponent = 0;
@@ -855,7 +860,7 @@ void QDeclarativeData::destroyed(QObject *object)
if (propertyCache)
propertyCache->release();
- if (ownContext)
+ if (ownContext && context)
context->destroy();
QDeclarativeGuard<QObject> *guard = guards;
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 7766ad6..b3bba43 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -215,7 +215,7 @@ public:
QList<SimpleList<QDeclarativeAbstractBinding> > bindValues;
QList<SimpleList<QDeclarativeParserStatus> > parserStatus;
- QDeclarativeComponentAttached *componentAttacheds;
+ QDeclarativeComponentAttached *componentAttached;
bool inBeginCreate;
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index 9cb2416..afd0d84 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -286,7 +286,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QString signalName = terminal.mid(2);
signalName[0] = signalName.at(0).toLower();
- QMetaMethod method = QDeclarativeCompiler::findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData());
+ QMetaMethod method = findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData());
if (method.signature()) {
object = currentObject;
core.load(method);
@@ -1353,4 +1353,36 @@ bool QDeclarativePropertyPrivate::canConvert(const QMetaObject *from, const QMet
return false;
}
+/*!
+ Return the signal corresponding to \a name
+*/
+QMetaMethod QDeclarativePropertyPrivate::findSignalByName(const QMetaObject *mo, const QByteArray &name)
+{
+ Q_ASSERT(mo);
+ int methods = mo->methodCount();
+ for (int ii = methods - 1; ii >= 2; --ii) { // >= 2 to block the destroyed signal
+ QMetaMethod method = mo->method(ii);
+ QByteArray methodName = method.signature();
+ int idx = methodName.indexOf('(');
+ methodName = methodName.left(idx);
+
+ if (methodName == name)
+ return method;
+ }
+
+ // If no signal is found, but the signal is of the form "onBlahChanged",
+ // return the notify signal for the property "Blah"
+ if (name.endsWith("Changed")) {
+ QByteArray propName = name.mid(0, name.length() - 7);
+ int propIdx = mo->indexOfProperty(propName.constData());
+ if (propIdx >= 0) {
+ QMetaProperty prop = mo->property(propIdx);
+ if (prop.hasNotifySignal())
+ return prop.notifySignal();
+ }
+ }
+
+ return QMetaMethod();
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h
index 420a1ba..8522561 100644
--- a/src/declarative/qml/qdeclarativeproperty_p.h
+++ b/src/declarative/qml/qdeclarativeproperty_p.h
@@ -96,8 +96,6 @@ public:
void initProperty(QObject *obj, const QString &name);
void initDefault(QObject *obj);
- QMetaMethod findSignal(QObject *, const QString &);
-
bool isValueType() const;
int propertyType() const;
QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const;
@@ -134,6 +132,7 @@ public:
static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags);
static int valueTypeCoreIndex(const QDeclarativeProperty &that);
static int bindingIndex(const QDeclarativeProperty &that);
+ static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags)
diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp
index 4b4b142..888945b 100644
--- a/src/declarative/qml/qdeclarativepropertycache.cpp
+++ b/src/declarative/qml/qdeclarativepropertycache.cpp
@@ -147,7 +147,7 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj
}
int methodCount = metaObject->methodCount();
- for (int ii = methodCount - 1; ii >= 0; --ii) {
+ for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;
@@ -216,7 +216,7 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb
}
int methodCount = metaObject->methodCount();
- int methodOffset = metaObject->methodOffset();
+ int methodOffset = qMax(2, metaObject->methodOffset()); // 2 to block the destroyed signal
for (int ii = methodOffset; ii < methodCount; ++ii) {
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
@@ -289,7 +289,7 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb
}
int methodCount = metaObject->methodCount();
- for (int ii = methodCount - 1; ii >= 0; --ii) {
+ for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal
QMetaMethod m = metaObject->method(ii);
if (m.access() == QMetaMethod::Private)
continue;