QByteArray convertToId(const QMetaObject *mo) { QByteArray className(mo->className()); if (!className.isEmpty()) return convertToId(className); // likely a metaobject generated for an extended qml object if (mo->superClass()) { className = convertToId(mo->superClass()); className.append("_extended"); return className; } static QHash<const QMetaObject *, QByteArray> generatedNames; className = generatedNames.value(mo); if (!className.isEmpty()) return className; qWarning() << "Found a QMetaObject without a className, generating a random name"; className = QByteArray("error-unknown-name-"); className.append(QByteArray::number(generatedNames.size())); generatedNames.insert(mo, className); return className; }
extensions[ty->typeName()].insert(ty->metaObject()->className()); } collectReachableMetaObjects(ty, &metas); } // Adjust ids of extended objects. // The chain ends up being: // __extended__.originalname - the base object // __extension_0_.originalname - first extension // .. // __extension_n-2_.originalname - second to last extension // originalname - last extension // ### does this actually work for multiple extensions? it seems like the prototypes might be wrong foreach (const QByteArray &extendedCpp, extensions.keys()) { cppToId.remove(extendedCpp); const QByteArray extendedId = convertToId(extendedCpp); cppToId.insert(extendedCpp, "__extended__." + extendedId); QSet<QByteArray> extensionCppNames = extensions.value(extendedCpp); int c = 0; foreach (const QByteArray &extensionCppName, extensionCppNames) { if (c != extensionCppNames.size() - 1) { QByteArray adjustedName = QString("__extension__%1.%2").arg(QString::number(c), QString(extendedId)).toAscii(); cppToId.insert(extensionCppName, adjustedName); } else { cppToId.insert(extensionCppName, extendedId); } ++c; } } // find even more QMetaObjects by instantiating QML types and running