| 
									
										
										
										
											2011-01-24 12:30:21 +01:00
										 |  |  | #include <QtDeclarative/QtDeclarative>
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | #include <QtDeclarative/private/qdeclarativemetatype_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-06-09 14:24:23 +02:00
										 |  |  | #include <QtDeclarative/private/qdeclarativeopenmetaobject_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | #include <QtDeclarative/QDeclarativeView>
 | 
					
						
							| 
									
										
										
										
											2011-01-24 12:30:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QtGui/QApplication>
 | 
					
						
							|  |  |  | #include <QtGui/QPushButton>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QtCore/QSet>
 | 
					
						
							|  |  |  | #include <QtCore/QXmlStreamWriter>
 | 
					
						
							|  |  |  | #include <QtCore/QXmlStreamReader>
 | 
					
						
							|  |  |  | #include <QtCore/QMetaObject>
 | 
					
						
							|  |  |  | #include <QtCore/QMetaProperty>
 | 
					
						
							|  |  |  | #include <QtCore/QDebug>
 | 
					
						
							|  |  |  | #include <QtCore/private/qobject_p.h>
 | 
					
						
							|  |  |  | #include <QtCore/private/qmetaobject_p.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-26 10:32:27 +01:00
										 |  |  | #ifdef QT_SIMULATOR
 | 
					
						
							|  |  |  | #include <QtGui/private/qsimulatorconnection_p.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  | #ifdef Q_OS_UNIX
 | 
					
						
							|  |  |  | #include <signal.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  | static QHash<QByteArray, QList<const QDeclarativeType *> > qmlTypesByCppName; | 
					
						
							|  |  |  | static QHash<QByteArray, QByteArray> cppToId; | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  | QString currentProperty; | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  | QByteArray convertToId(const QByteArray &cppName) | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     QByteArray idName = cppToId.value(cppName, cppName); | 
					
						
							|  |  |  |     idName.replace("::", "."); | 
					
						
							|  |  |  |     idName.replace("/", "."); | 
					
						
							|  |  |  |     return idName; | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void erasure(QByteArray *typeName, bool *isList, bool *isPointer) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static QByteArray declListPrefix = "QDeclarativeListProperty<"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (typeName->endsWith('*')) { | 
					
						
							|  |  |  |         *isPointer = true; | 
					
						
							|  |  |  |         typeName->truncate(typeName->length() - 1); | 
					
						
							|  |  |  |         erasure(typeName, isList, isPointer); | 
					
						
							|  |  |  |     } else if (typeName->startsWith(declListPrefix)) { | 
					
						
							|  |  |  |         *isList = true; | 
					
						
							|  |  |  |         typeName->truncate(typeName->length() - 1); // get rid of the suffix '>'
 | 
					
						
							|  |  |  |         *typeName = typeName->mid(declListPrefix.size()); | 
					
						
							|  |  |  |         erasure(typeName, isList, isPointer); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     *typeName = convertToId(*typeName); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void processMetaObject(const QMetaObject *meta, QSet<const QMetaObject *> *metas) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (! meta || metas->contains(meta)) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-09 14:24:23 +02:00
										 |  |  |     // dynamic meta objects break things badly
 | 
					
						
							|  |  |  |     const QMetaObjectPrivate *mop = reinterpret_cast<const QMetaObjectPrivate *>(meta->d.data); | 
					
						
							|  |  |  |     if (!(mop->flags & DynamicMetaObject)) | 
					
						
							|  |  |  |         metas->insert(meta); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     processMetaObject(meta->superClass(), metas); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void processObject(QObject *object, QSet<const QMetaObject *> *metas) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (! object) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QMetaObject *meta = object->metaObject(); | 
					
						
							| 
									
										
										
										
											2010-09-15 14:13:33 +02:00
										 |  |  |     qDebug() << "Processing object" << meta->className(); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     processMetaObject(meta, metas); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int index = 0; index < meta->propertyCount(); ++index) { | 
					
						
							|  |  |  |         QMetaProperty prop = meta->property(index); | 
					
						
							|  |  |  |         if (QDeclarativeMetaType::isQObject(prop.userType())) { | 
					
						
							| 
									
										
										
										
											2010-09-15 14:13:33 +02:00
										 |  |  |             qDebug() << "  Processing property" << prop.name(); | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  |             currentProperty = QString("%1::%2").arg(meta->className(), prop.name()); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |             QObject *oo = QDeclarativeMetaType::toQObject(prop.read(object)); | 
					
						
							| 
									
										
										
										
											2010-03-31 14:09:49 +02:00
										 |  |  |             if (oo && !metas->contains(oo->metaObject())) | 
					
						
							|  |  |  |                 processObject(oo, metas); | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  |             currentProperty.clear(); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void processDeclarativeType(const QDeclarativeType *ty, QSet<const QMetaObject *> *metas) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     processMetaObject(ty->metaObject(), metas); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 10:29:32 +01:00
										 |  |  | void writeType(QXmlStreamAttributes *attrs, QByteArray typeName, bool isWritable = false) | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     bool isList = false, isPointer = false; | 
					
						
							|  |  |  |     erasure(&typeName, &isList, &isPointer); | 
					
						
							|  |  |  |     attrs->append(QXmlStreamAttribute("type", typeName)); | 
					
						
							|  |  |  |     if (isList) | 
					
						
							|  |  |  |         attrs->append(QXmlStreamAttribute("isList", "true")); | 
					
						
							| 
									
										
										
										
											2010-11-11 10:29:32 +01:00
										 |  |  |     if (isWritable) | 
					
						
							|  |  |  |         attrs->append(QXmlStreamAttribute("isWritable", "true")); | 
					
						
							|  |  |  |     if (isPointer) | 
					
						
							|  |  |  |         attrs->append(QXmlStreamAttribute("isPointer", "true")); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump(const QMetaProperty &prop, QXmlStreamWriter *xml) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     xml->writeStartElement("property"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QXmlStreamAttributes attributes; | 
					
						
							|  |  |  |     attributes.append(QXmlStreamAttribute("name", QString::fromUtf8(prop.name()))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-11 10:29:32 +01:00
										 |  |  |     writeType(&attributes, prop.typeName(), prop.isWritable()); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     xml->writeAttributes(attributes); | 
					
						
							|  |  |  |     xml->writeEndElement(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump(const QMetaMethod &meth, QXmlStreamWriter *xml) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (meth.methodType() == QMetaMethod::Signal) { | 
					
						
							|  |  |  |         if (meth.access() != QMetaMethod::Protected) | 
					
						
							|  |  |  |             return; // nothing to do.
 | 
					
						
							|  |  |  |     } else if (meth.access() != QMetaMethod::Public) { | 
					
						
							|  |  |  |         return; // nothing to do.
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray name = meth.signature(); | 
					
						
							|  |  |  |     int lparenIndex = name.indexOf('('); | 
					
						
							|  |  |  |     if (lparenIndex == -1) { | 
					
						
							|  |  |  |         return; // invalid signature
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     name = name.left(lparenIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString elementName = QLatin1String("method"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QXmlStreamAttributes attributes; | 
					
						
							|  |  |  |     if (meth.methodType() == QMetaMethod::Signal) | 
					
						
							|  |  |  |         elementName = QLatin1String("signal"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeStartElement(elementName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     attributes.append(QXmlStreamAttribute("name", name)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     const QString typeName = convertToId(meth.typeName()); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     if (! typeName.isEmpty()) | 
					
						
							|  |  |  |         attributes.append(QXmlStreamAttribute("type", typeName)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeAttributes(attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int i = 0; i < meth.parameterTypes().size(); ++i) { | 
					
						
							|  |  |  |         QByteArray argName = meth.parameterNames().at(i); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xml->writeStartElement("param"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QXmlStreamAttributes attrs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (! argName.isEmpty()) | 
					
						
							|  |  |  |             attrs.append(QXmlStreamAttribute("name", argName)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         writeType(&attrs, meth.parameterTypes().at(i)); | 
					
						
							|  |  |  |         xml->writeAttributes(attrs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xml->writeEndElement(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeEndElement(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump(const QMetaEnum &e, QXmlStreamWriter *xml) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     xml->writeStartElement("enum"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QXmlStreamAttributes attributes; | 
					
						
							|  |  |  |     attributes.append(QXmlStreamAttribute("name", QString::fromUtf8(e.name()))); // ### FIXME
 | 
					
						
							|  |  |  |     xml->writeAttributes(attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int index = 0; index < e.keyCount(); ++index) { | 
					
						
							|  |  |  |         xml->writeStartElement("enumerator"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QXmlStreamAttributes attributes; | 
					
						
							|  |  |  |         attributes.append(QXmlStreamAttribute("name", QString::fromUtf8(e.key(index)))); | 
					
						
							|  |  |  |         attributes.append(QXmlStreamAttribute("value", QString::number(e.value(index)))); | 
					
						
							|  |  |  |         xml->writeAttributes(attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         xml->writeEndElement(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeEndElement(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FriendlyQObject: public QObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     static const QMetaObject *qtMeta() { return &staticQtMetaObject; } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void dump(const QMetaObject *meta, QXmlStreamWriter *xml) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     QByteArray id = convertToId(meta->className()); | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     xml->writeStartElement("type"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QXmlStreamAttributes attributes; | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     attributes.append(QXmlStreamAttribute("name", id)); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-31 14:09:49 +02:00
										 |  |  |     for (int index = meta->classInfoCount() - 1 ; index >= 0 ; --index) { | 
					
						
							|  |  |  |         QMetaClassInfo classInfo = meta->classInfo(index); | 
					
						
							|  |  |  |         if (QLatin1String(classInfo.name()) == QLatin1String("DefaultProperty")) { | 
					
						
							|  |  |  |             attributes.append(QXmlStreamAttribute("defaultProperty", QLatin1String(classInfo.value()))); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     if (meta->superClass()) | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         attributes.append(QXmlStreamAttribute("extends", convertToId(meta->superClass()->className()))); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     xml->writeAttributes(attributes); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 13:27:19 +01:00
										 |  |  |     QList<const QDeclarativeType *> qmlTypes = qmlTypesByCppName.value(meta->className()); | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     if (!qmlTypes.isEmpty()) { | 
					
						
							|  |  |  |         xml->writeStartElement("exports"); | 
					
						
							|  |  |  |         foreach (const QDeclarativeType *qmlTy, qmlTypes) { | 
					
						
							|  |  |  |             QXmlStreamAttributes moduleAttributes; | 
					
						
							|  |  |  |             const QString qmlTyName = qmlTy->qmlTypeName(); | 
					
						
							|  |  |  |             int slashIdx = qmlTyName.lastIndexOf(QLatin1Char('/')); | 
					
						
							|  |  |  |             if (slashIdx == -1) | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             const QString moduleName = qmlTyName.left(slashIdx); | 
					
						
							|  |  |  |             const QString typeName = qmlTyName.mid(slashIdx + 1); | 
					
						
							|  |  |  |             moduleAttributes.append(QXmlStreamAttribute("module", moduleName)); | 
					
						
							|  |  |  |             moduleAttributes.append(QXmlStreamAttribute("version", QString("%1.%2").arg(qmlTy->majorVersion()).arg(qmlTy->minorVersion()))); | 
					
						
							|  |  |  |             moduleAttributes.append(QXmlStreamAttribute("type", typeName)); | 
					
						
							|  |  |  |             xml->writeEmptyElement("export"); | 
					
						
							|  |  |  |             xml->writeAttributes(moduleAttributes); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         xml->writeEndElement(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     for (int index = meta->enumeratorOffset(); index < meta->enumeratorCount(); ++index) | 
					
						
							|  |  |  |         dump(meta->enumerator(index), xml); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int index = meta->propertyOffset(); index < meta->propertyCount(); ++index) | 
					
						
							|  |  |  |         dump(meta->property(index), xml); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int index = meta->methodOffset(); index < meta->methodCount(); ++index) | 
					
						
							|  |  |  |         dump(meta->method(index), xml); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeEndElement(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-07 17:33:44 +02:00
										 |  |  | void writeEasingCurve(QXmlStreamWriter *xml) | 
					
						
							| 
									
										
										
										
											2010-03-03 11:36:42 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  |     xml->writeStartElement("type"); | 
					
						
							| 
									
										
										
										
											2010-03-03 11:36:42 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |         QXmlStreamAttributes attributes; | 
					
						
							| 
									
										
										
										
											2010-06-07 17:33:44 +02:00
										 |  |  |         attributes.append(QXmlStreamAttribute("name", "QEasingCurve")); | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         attributes.append(QXmlStreamAttribute("extends", "QDeclarativeEasingValueType")); | 
					
						
							| 
									
										
										
										
											2010-03-03 11:36:42 +01:00
										 |  |  |         xml->writeAttributes(attributes); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml->writeEndElement(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  | enum ExitCode { | 
					
						
							|  |  |  |     EXIT_INVALIDARGUMENTS = 1, | 
					
						
							|  |  |  |     EXIT_SEGV = 2, | 
					
						
							|  |  |  |     EXIT_IMPORTERROR = 3 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  | #ifdef Q_OS_UNIX
 | 
					
						
							|  |  |  | void sigSegvHandler(int) { | 
					
						
							|  |  |  |     fprintf(stderr, "Error: qmldump SEGV\n"); | 
					
						
							|  |  |  |     if (!currentProperty.isEmpty()) | 
					
						
							|  |  |  |         fprintf(stderr, "While processing the property '%s', which probably has uninitialized data.\n", currentProperty.toLatin1().constData()); | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |     exit(EXIT_SEGV); | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | int main(int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-01-12 13:15:09 +01:00
										 |  |  | #ifdef Q_OS_UNIX
 | 
					
						
							|  |  |  |     // qmldump may crash, but we don't want any crash handlers to pop up
 | 
					
						
							|  |  |  |     // therefore we intercept the segfault and just exit() ourselves
 | 
					
						
							|  |  |  |     struct sigaction action; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sigemptyset(&action.sa_mask); | 
					
						
							|  |  |  |     action.sa_handler = &sigSegvHandler; | 
					
						
							|  |  |  |     action.sa_flags   = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     sigaction(SIGSEGV, &action, 0); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-26 10:32:27 +01:00
										 |  |  | #ifdef QT_SIMULATOR
 | 
					
						
							|  |  |  |     QtSimulatorPrivate::SimulatorConnection::createStubInstance(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     QApplication app(argc, argv); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-25 14:15:57 +02:00
										 |  |  |     if (argc != 1 && argc != 3) { | 
					
						
							|  |  |  |         qWarning() << "Usage: qmldump [plugin/import/path plugin.uri]"; | 
					
						
							| 
									
										
										
										
											2011-01-12 13:45:38 +01:00
										 |  |  |         qWarning() << "Example: ./qmldump /home/user/dev/qt-install/imports Qt.labs.particles"; | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |         return EXIT_INVALIDARGUMENTS; | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString pluginImportName; | 
					
						
							|  |  |  |     QString pluginImportPath; | 
					
						
							| 
									
										
										
										
											2010-08-25 14:15:57 +02:00
										 |  |  |     if (argc == 3) { | 
					
						
							|  |  |  |         pluginImportPath = QString(argv[1]); | 
					
						
							|  |  |  |         pluginImportName = QString(argv[2]); | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     QDeclarativeView view; | 
					
						
							|  |  |  |     QDeclarativeEngine *engine = view.engine(); | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |     if (!pluginImportPath.isEmpty()) | 
					
						
							|  |  |  |         engine->addImportPath(pluginImportPath); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     bool hasQtQuickModule = false; | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         QByteArray code = "import QtQuick 1.0; Item {}"; | 
					
						
							|  |  |  |         QDeclarativeComponent c(engine); | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |         c.setData(code, QUrl("qtquickcheck")); | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         c.create(); | 
					
						
							|  |  |  |         if (c.errors().isEmpty()) { | 
					
						
							|  |  |  |             hasQtQuickModule = true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |     QByteArray importCode; | 
					
						
							|  |  |  |     importCode += "import Qt 4.7;\n"; | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     if (hasQtQuickModule) { | 
					
						
							|  |  |  |         importCode += "import QtQuick 1.0;\n"; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-25 14:15:57 +02:00
										 |  |  |     if (pluginImportName.isEmpty()) { | 
					
						
							|  |  |  |         importCode += "import Qt.labs.particles 4.7;\n"; | 
					
						
							|  |  |  |         importCode += "import Qt.labs.gestures 4.7;\n"; | 
					
						
							|  |  |  |         importCode += "import Qt.labs.folderlistmodel 4.7;\n"; | 
					
						
							|  |  |  |         importCode += "import QtWebKit 1.0;\n"; | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-06-01 15:10:20 +02:00
										 |  |  |         importCode += QString("import %0 1.0;\n").arg(pluginImportName).toAscii(); | 
					
						
							| 
									
										
										
										
											2010-08-25 14:15:57 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |         QByteArray code = importCode; | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  |         code += "Item {}"; | 
					
						
							|  |  |  |         QDeclarativeComponent c(engine); | 
					
						
							| 
									
										
										
										
											2010-06-09 14:27:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |         c.setData(code, QUrl("typelist")); | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  |         c.create(); | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |         if (!c.errors().isEmpty()) { | 
					
						
							|  |  |  |             foreach (const QDeclarativeError &error, c.errors()) | 
					
						
							|  |  |  |                 qWarning() << error.toString(); | 
					
						
							|  |  |  |             return EXIT_IMPORTERROR; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     cppToId.insert("QString", "string"); | 
					
						
							|  |  |  |     cppToId.insert("QDeclarativeEasingValueType::Type", "Type"); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QSet<const QMetaObject *> metas; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     metas.insert(FriendlyQObject::qtMeta()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     QHash<QByteArray, QSet<QByteArray> > extensions; | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         qmlTypesByCppName[ty->metaObject()->className()].append(ty); | 
					
						
							| 
									
										
										
										
											2010-06-01 12:03:17 +02:00
										 |  |  |         if (ty->isExtendedType()) { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |             extensions[ty->typeName()].insert(ty->metaObject()->className()); | 
					
						
							| 
									
										
										
										
											2010-06-01 12:03:17 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |             cppToId.insert(ty->metaObject()->className(), ty->metaObject()->className()); | 
					
						
							| 
									
										
										
										
											2010-06-01 12:03:17 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |         processDeclarativeType(ty, &metas); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     // Adjust ids of extended objects.
 | 
					
						
							| 
									
										
										
										
											2010-06-01 12:03:17 +02:00
										 |  |  |     // 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
 | 
					
						
							|  |  |  |     foreach (const QByteArray &extendedCpp, extensions.keys()) { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         const QByteArray extendedId = cppToId.value(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; | 
					
						
							| 
									
										
										
										
											2010-06-01 12:03:17 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     foreach (const QDeclarativeType *ty, QDeclarativeMetaType::qmlTypes()) { | 
					
						
							| 
									
										
										
										
											2010-04-29 13:52:12 +02:00
										 |  |  |         if (ty->isExtendedType()) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |         QByteArray tyName = ty->qmlTypeName(); | 
					
						
							|  |  |  |         tyName = tyName.mid(tyName.lastIndexOf('/') + 1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-20 12:02:46 +02:00
										 |  |  |         QByteArray code = importCode; | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |         code += tyName; | 
					
						
							|  |  |  |         code += " {}\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         QDeclarativeComponent c(engine); | 
					
						
							| 
									
										
										
										
											2011-01-20 16:02:28 +01:00
										 |  |  |         c.setData(code, QUrl("typeinstance")); | 
					
						
							| 
									
										
										
										
											2010-06-09 14:27:30 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         QObject *object = c.create(); | 
					
						
							|  |  |  |         if (object) | 
					
						
							|  |  |  |             processObject(object, &metas); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             qDebug() << "Could not create" << tyName << ":" << c.errorString(); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray bytes; | 
					
						
							|  |  |  |     QXmlStreamWriter xml(&bytes); | 
					
						
							|  |  |  |     xml.setAutoFormatting(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     xml.writeStartDocument("1.0"); | 
					
						
							|  |  |  |     xml.writeStartElement("module"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-05 10:17:18 +01:00
										 |  |  |     QMap<QString, const QMetaObject *> nameToMeta; | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |     foreach (const QMetaObject *meta, metas) { | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |         nameToMeta.insert(convertToId(meta->className()), meta); | 
					
						
							| 
									
										
										
										
											2010-03-05 10:17:18 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     foreach (const QMetaObject *meta, nameToMeta) { | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  |         dump(meta, &xml); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-03-15 17:41:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-30 11:21:23 +02:00
										 |  |  |     // define QEasingCurve as an extension of QDeclarativeEasingValueType
 | 
					
						
							| 
									
										
										
										
											2010-06-07 17:33:44 +02:00
										 |  |  |     writeEasingCurve(&xml); | 
					
						
							| 
									
										
										
										
											2010-02-25 13:53:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     xml.writeEndElement(); | 
					
						
							|  |  |  |     xml.writeEndDocument(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::cout << bytes.constData(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QTimer timer; | 
					
						
							|  |  |  |     timer.setSingleShot(true); | 
					
						
							|  |  |  |     timer.setInterval(0); | 
					
						
							|  |  |  |     QObject::connect(&timer, SIGNAL(timeout()), &app, SLOT(quit())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     timer.start(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return app.exec(); | 
					
						
							|  |  |  | } |