summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-09-28 08:50:18 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-09-28 08:50:18 (GMT)
commit746954581f06e0bca98f25eb95dca09c663d47bf (patch)
tree849d303446cd2771b3927a1066f7886c52bef7c7 /src/declarative
parent040b01732a37232aad7c6cd53c5d37b10bf5a6dc (diff)
downloadQt-746954581f06e0bca98f25eb95dca09c663d47bf.zip
Qt-746954581f06e0bca98f25eb95dca09c663d47bf.tar.gz
Qt-746954581f06e0bca98f25eb95dca09c663d47bf.tar.bz2
If a type is registered under several names, share the attached property object
Task-number: QTBUG-13799
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings.cpp10
-rw-r--r--src/declarative/qml/qdeclarativecompiler.cpp2
-rw-r--r--src/declarative/qml/qdeclarativemetatype.cpp25
-rw-r--r--src/declarative/qml/qdeclarativemetatype_p.h1
-rw-r--r--src/declarative/qml/qdeclarativeproperty.cpp4
-rw-r--r--src/declarative/qml/qdeclarativetypenamescriptclass.cpp2
6 files changed, 34 insertions, 10 deletions
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp
index 9402596..5f0fd56 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings.cpp
+++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp
@@ -438,7 +438,7 @@ struct Instr {
qint8 output;
qint8 reg;
quint8 exceptionId;
- quint32 index;
+ quint32 id;
} attached;
struct {
QML_INSTR_HEADER
@@ -988,7 +988,7 @@ static void dumpInstruction(const Instr *instr)
qWarning().nospace() << "\t" << "LoadRoot" << "\t\t" << instr->load.index << "\t" << instr->load.reg;
break;
case Instr::LoadAttached:
- qWarning().nospace() << "\t" << "LoadAttached" << "\t\t" << instr->attached.output << "\t" << instr->attached.reg << "\t" << instr->attached.index;
+ qWarning().nospace() << "\t" << "LoadAttached" << "\t\t" << instr->attached.output << "\t" << instr->attached.reg << "\t" << instr->attached.id;
break;
case Instr::ConvertIntToReal:
qWarning().nospace() << "\t" << "ConvertIntToReal" << "\t" << instr->unaryop.output << "\t" << instr->unaryop.src;
@@ -1225,7 +1225,7 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex,
output.setUndefined();
} else {
QObject *attached =
- qmlAttachedPropertiesObjectById(instr->attached.index,
+ qmlAttachedPropertiesObjectById(instr->attached.id,
registers[instr->attached.reg].getQObject(),
true);
Q_ASSERT(attached);
@@ -1895,7 +1895,7 @@ bool QDeclarativeBindingCompilerPrivate::parseName(AST::Node *node, Result &type
attach.common.type = Instr::LoadAttached;
attach.attached.output = reg;
attach.attached.reg = reg;
- attach.attached.index = attachType->index();
+ attach.attached.id = attachType->attachedPropertiesId();
attach.attached.exceptionId = exceptionId(nameNodes.at(ii));
bytecode << attach;
@@ -2011,7 +2011,7 @@ bool QDeclarativeBindingCompilerPrivate::parseName(AST::Node *node, Result &type
attach.common.type = Instr::LoadAttached;
attach.attached.output = reg;
attach.attached.reg = reg;
- attach.attached.index = attachType->index();
+ attach.attached.id = attachType->attachedPropertiesId();
bytecode << attach;
absType = 0;
diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp
index e55dc92..8c5fd3a 100644
--- a/src/declarative/qml/qdeclarativecompiler.cpp
+++ b/src/declarative/qml/qdeclarativecompiler.cpp
@@ -1407,7 +1407,7 @@ bool QDeclarativeCompiler::buildProperty(QDeclarativeParser::Property *prop,
COMPILE_EXCEPTION(prop, tr("Invalid attached object assignment"));
Q_ASSERT(type->attachedPropertiesFunction());
- prop->index = type->index();
+ prop->index = type->attachedPropertiesId();
prop->value->metatype = type->attachedPropertiesType();
} else {
// Setup regular property data
diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp
index a5c878f..7a78a1f 100644
--- a/src/declarative/qml/qdeclarativemetatype.cpp
+++ b/src/declarative/qml/qdeclarativemetatype.cpp
@@ -146,6 +146,7 @@ public:
const QMetaObject *m_baseMetaObject;
QDeclarativeAttachedPropertiesFunc m_attachedPropertiesFunc;
const QMetaObject *m_attachedPropertiesType;
+ int m_attachedPropertiesId;
int m_parserStatusCast;
int m_propertyValueSourceCast;
int m_propertyValueInterceptorCast;
@@ -155,8 +156,12 @@ public:
QDeclarativeCustomParser *m_customParser;
mutable volatile bool m_isSetup:1;
mutable QList<QDeclarativeProxyMetaObject::ProxyData> m_metaObjects;
+
+ static QHash<const QMetaObject *, int> m_attachedPropertyIds;
};
+QHash<const QMetaObject *, int> QDeclarativeTypePrivate::m_attachedPropertyIds;
+
QDeclarativeTypePrivate::QDeclarativeTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0),
m_allocationSize(0), m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
@@ -198,6 +203,14 @@ QDeclarativeType::QDeclarativeType(int index, const QDeclarativePrivate::Registe
d->m_baseMetaObject = type.metaObject;
d->m_attachedPropertiesFunc = type.attachedPropertiesFunction;
d->m_attachedPropertiesType = type.attachedPropertiesMetaObject;
+ if (d->m_attachedPropertiesType) {
+ QHash<const QMetaObject *, int>::Iterator iter = d->m_attachedPropertyIds.find(d->m_baseMetaObject);
+ if (iter == d->m_attachedPropertyIds.end())
+ iter = d->m_attachedPropertyIds.insert(d->m_baseMetaObject, index);
+ d->m_attachedPropertiesId = *iter;
+ } else {
+ d->m_attachedPropertiesId = -1;
+ }
d->m_parserStatusCast = type.parserStatusCast;
d->m_propertyValueSourceCast = type.valueSourceCast;
d->m_propertyValueInterceptorCast = type.valueInterceptorCast;
@@ -461,6 +474,16 @@ const QMetaObject *QDeclarativeType::attachedPropertiesType() const
return d->m_attachedPropertiesType;
}
+/*
+This is the id passed to qmlAttachedPropertiesById(). This is different from the index
+for the case that a single class is registered under two or more names (eg. Item in
+Qt 4.7 and QtQuick 1.0).
+*/
+int QDeclarativeType::attachedPropertiesId() const
+{
+ return d->m_attachedPropertiesId;
+}
+
int QDeclarativeType::parserStatusCast() const
{
return d->m_parserStatusCast;
@@ -662,7 +685,7 @@ int QDeclarativeMetaType::attachedPropertiesFuncId(const QMetaObject *mo)
QDeclarativeType *type = data->metaObjectToType.value(mo);
if (type && type->attachedPropertiesFunction())
- return type->index();
+ return type->attachedPropertiesId();
else
return -1;
}
diff --git a/src/declarative/qml/qdeclarativemetatype_p.h b/src/declarative/qml/qdeclarativemetatype_p.h
index f410547..382abd2 100644
--- a/src/declarative/qml/qdeclarativemetatype_p.h
+++ b/src/declarative/qml/qdeclarativemetatype_p.h
@@ -137,6 +137,7 @@ public:
QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction() const;
const QMetaObject *attachedPropertiesType() const;
+ int attachedPropertiesId() const;
int parserStatusCast() const;
QVariant fromObject(QObject *) const;
diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp
index d0dd2e8..bc20bff 100644
--- a/src/declarative/qml/qdeclarativeproperty.cpp
+++ b/src/declarative/qml/qdeclarativeproperty.cpp
@@ -220,7 +220,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction();
if (!func) return; // Not an attachable type
- currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject);
+ currentObject = qmlAttachedPropertiesObjectById(data->type->attachedPropertiesId(), currentObject);
if (!currentObject) return; // Something is broken with the attachable type
} else {
Q_ASSERT(data->typeNamespace);
@@ -232,7 +232,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name
QDeclarativeAttachedPropertiesFunc func = data->type->attachedPropertiesFunction();
if (!func) return; // Not an attachable type
- currentObject = qmlAttachedPropertiesObjectById(data->type->index(), currentObject);
+ currentObject = qmlAttachedPropertiesObjectById(data->type->attachedPropertiesId(), currentObject);
if (!currentObject) return; // Something is broken with the attachable type
}
} else {
diff --git a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
index 764a8db..cba7b4a 100644
--- a/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
+++ b/src/declarative/qml/qdeclarativetypenamescriptclass.cpp
@@ -129,7 +129,7 @@ QDeclarativeTypeNameScriptClass::queryProperty(Object *obj, const Identifier &na
return 0;
} else if (data->object) {
// Must be an attached property
- object = qmlAttachedPropertiesObjectById(data->type->index(), data->object);
+ object = qmlAttachedPropertiesObjectById(data->type->attachedPropertiesId(), data->object);
if (!object) return 0;
return ep->objectClass->queryProperty(object, name, flags, 0);
}