if (componentName.isEmpty())
return false;
- // get a list of all the names that may refer to this component
- // this can only happen for file imports with an 'as' clause
- // if there aren't any, possibleNames will be left empty
- QSet<QString> possibleNames;
- foreach (const ImportInfo &import, imports()) {
- if (import.type() == ImportInfo::FileImport
- && !import.id().isEmpty()
- && import.name().contains(componentName)) {
- possibleNames.insert(import.id());
- }
- }
- if (!possibleNames.isEmpty())
- possibleNames.insert(componentName);
-
- // if there are no renamed imports and the document does not use
- // the className string anywhere, it's out
- if (possibleNames.isEmpty()) {
- // ### FIXME!
-// NameId nameId(componentName.data(), componentName.size());
-// if (!_doc->engine()->literals().contains(nameId))
-// return false;
- }
-
- QHashIterator<Node *, ObjectValue *> it(_qmlObjects);
- while (it.hasNext()) {
- it.next();
-
- // if the type id does not contain one of the possible names, skip
- Node *node = it.key();
- UiQualifiedId *id = 0;
- if (UiObjectDefinition *n = cast<UiObjectDefinition *>(node)) {
- id = n->qualifiedTypeNameId;
- } else if (UiObjectBinding *n = cast<UiObjectBinding *>(node)) {
- id = n->qualifiedTypeNameId;
- }
- if (!id)
- continue;
-
- bool skip = false;
- // optimize the common case of no renamed imports
- if (possibleNames.isEmpty()) {
- for (UiQualifiedId *idIt = id; idIt; idIt = idIt->next) {
- if (!idIt->next && idIt->name != componentName)
- skip = true;
- }
- } else {
- for (UiQualifiedId *idIt = id; idIt; idIt = idIt->next) {
- if (!idIt->next && !possibleNames.contains(idIt->name.toString()))
- skip = true;
- }
- }
- if (skip)
- continue;
-
+ foreach (const ObjectValue *object, _qmlObjectsByPrototypeName.values(componentName)) {
// resolve and check the prototype
- const ObjectValue *object = it.value();
const ObjectValue *resolvedPrototype = object->prototype(context);
if (resolvedPrototype == prototype)
return true;
new QmlPrototypeReference(qualifiedTypeNameId, _doc, &_valueOwner);
objectValue->setPrototype(prototypeReference);
+ // add the prototype name to the prototypes hash
+ for (UiQualifiedId *it = qualifiedTypeNameId; it; it = it->next) {
+ if (!it->next && !it->name.isEmpty())
+ _qmlObjectsByPrototypeName.insert(it->name.toString(), objectValue);
+ }
+
parentObjectValue = switchObjectValue(objectValue);
if (parentObjectValue)