diff options
Diffstat (limited to 'src/declarative/qml/qmlcompiler.cpp')
-rw-r--r-- | src/declarative/qml/qmlcompiler.cpp | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bb7abf3..cbd7d70 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -677,6 +677,13 @@ void QmlCompiler::compileTree(Object *tree) QmlEnginePrivate::get(engine)->registerCompositeType(output); } +static bool ValuePtrLessThan(const Value *t1, const Value *t2) +{ + return t1->location.start.line < t2->location.start.line || + (t1->location.start.line == t2->location.start.line && + t1->location.start.column < t2->location.start.column); +} + bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) { componentStat.objects++; @@ -736,9 +743,46 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) } } + // Merge + Property *defaultProperty = 0; + Property *skipProperty = 0; + if (obj->defaultProperty) { + const QMetaObject *metaObject = obj->metaObject(); + Q_ASSERT(metaObject); + QMetaProperty p = QmlMetaType::defaultProperty(metaObject); + if (p.name()) { + Property *explicitProperty = obj->getProperty(p.name(), false); + if (explicitProperty && !explicitProperty->value) { + skipProperty = explicitProperty; + + defaultProperty = new Property; + defaultProperty->parent = obj; + defaultProperty->isDefault = true; + defaultProperty->location = obj->defaultProperty->location; + defaultProperty->listValueRange = obj->defaultProperty->listValueRange; + defaultProperty->listCommaPositions = obj->defaultProperty->listCommaPositions; + + defaultProperty->values = obj->defaultProperty->values; + defaultProperty->values += explicitProperty->values; + foreach(Value *value, defaultProperty->values) + value->addref(); + qSort(defaultProperty->values.begin(), defaultProperty->values.end(), ValuePtrLessThan); + + } else { + defaultProperty = obj->defaultProperty; + defaultProperty->addref(); + } + } else { + defaultProperty = obj->defaultProperty; + defaultProperty->addref(); + } + } + // Build all explicit properties specified foreach(Property *prop, obj->properties) { + if (prop == skipProperty) + continue; if (prop->name == "id") continue; @@ -768,8 +812,8 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) } // Build the default property - if (obj->defaultProperty) { - Property *prop = obj->defaultProperty; + if (defaultProperty) { + Property *prop = defaultProperty; bool canDefer = false; if (isCustomParser) { @@ -791,6 +835,9 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) prop->isDeferred = true; } + if (defaultProperty) + defaultProperty->release(); + // Compile custom parser parts if (isCustomParser && !customProps.isEmpty()) { QmlCustomParser *cp = output->types.at(obj->type).type->customParser(); |