diff options
author | Tobias Koenig <tobias.koenig@kdab.com> | 2015-09-24 12:45:22 +0200 |
---|---|---|
committer | Tobias Koenig <tobias.koenig@kdab.com> | 2015-09-24 11:11:32 +0000 |
commit | fe7d35e3cbc7b6db42fbc66e26a63d321260cea0 (patch) | |
tree | b055a92ff980fa9f57bd5f6b12355aa1045f93a1 /src/qml/qml | |
parent | 0e90fac4afeda889c38a8c1998fdba92e9138559 (diff) |
Factor out method to get pretty QML type name
Factor out the code to get the pretty QML type name
for an QObject from ~QQmlInfo and put it into
QQmlMetaType::prettyTypeName() method.
Change-Id: I54ab0c49ba4a52074877447ef67708104f954f2d
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmlinfo.cpp | 28 | ||||
-rw-r--r-- | src/qml/qml/qqmlmetatype.cpp | 39 | ||||
-rw-r--r-- | src/qml/qml/qqmlmetatype_p.h | 2 |
3 files changed, 42 insertions, 27 deletions
diff --git a/src/qml/qml/qqmlinfo.cpp b/src/qml/qml/qqmlinfo.cpp index b9f96a724c..7a801032d3 100644 --- a/src/qml/qml/qqmlinfo.cpp +++ b/src/qml/qml/qqmlinfo.cpp @@ -109,34 +109,8 @@ QQmlInfo::~QQmlInfo() if (object) { engine = qmlEngine(d->object); - QString typeName; - QQmlType *type = QQmlMetaType::qmlType(object->metaObject()); - if (type) { - typeName = type->qmlTypeName(); - int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); - if (lastSlash != -1) - typeName = typeName.mid(lastSlash+1); - } else { - typeName = QString::fromUtf8(object->metaObject()->className()); - int marker = typeName.indexOf(QLatin1String("_QMLTYPE_")); - if (marker != -1) - typeName = typeName.left(marker); - - marker = typeName.indexOf(QLatin1String("_QML_")); - if (marker != -1) { - typeName = typeName.left(marker); - typeName += QLatin1Char('*'); - type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1())); - if (type) { - typeName = type->qmlTypeName(); - int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); - if (lastSlash != -1) - typeName = typeName.mid(lastSlash+1); - } - } - } - d->buffer.prepend(QLatin1String("QML ") + typeName + QLatin1String(": ")); + d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(object) + QLatin1String(": ")); QQmlData *ddata = QQmlData::get(object, false); if (ddata && ddata->outerContext) { diff --git a/src/qml/qml/qqmlmetatype.cpp b/src/qml/qml/qqmlmetatype.cpp index b173bc8bec..04c001d305 100644 --- a/src/qml/qml/qqmlmetatype.cpp +++ b/src/qml/qml/qqmlmetatype.cpp @@ -1908,4 +1908,43 @@ const QQmlPrivate::CachedQmlUnit *QQmlMetaType::findCachedCompilationUnit(const return 0; } +/*! + Returns the pretty QML type name (e.g. 'Item' instead of 'QtQuickItem') for the given object. + */ +QString QQmlMetaType::prettyTypeName(const QObject *object) +{ + QString typeName; + + if (!object) + return typeName; + + const QQmlType *type = QQmlMetaType::qmlType(object->metaObject()); + if (type) { + typeName = type->qmlTypeName(); + const int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); + if (lastSlash != -1) + typeName = typeName.mid(lastSlash + 1); + } else { + typeName = QString::fromUtf8(object->metaObject()->className()); + int marker = typeName.indexOf(QLatin1String("_QMLTYPE_")); + if (marker != -1) + typeName = typeName.left(marker); + + marker = typeName.indexOf(QLatin1String("_QML_")); + if (marker != -1) { + typeName = typeName.left(marker); + typeName += QLatin1Char('*'); + type = QQmlMetaType::qmlType(QMetaType::type(typeName.toLatin1())); + if (type) { + typeName = type->qmlTypeName(); + const int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); + if (lastSlash != -1) + typeName = typeName.mid(lastSlash + 1); + } + } + } + + return typeName; +} + QT_END_NAMESPACE diff --git a/src/qml/qml/qqmlmetatype_p.h b/src/qml/qml/qqmlmetatype_p.h index 08f19bcf09..40765d461a 100644 --- a/src/qml/qml/qqmlmetatype_p.h +++ b/src/qml/qml/qqmlmetatype_p.h @@ -123,6 +123,8 @@ public: static QStringList typeRegistrationFailures(); static QMutex *typeRegistrationLock(); + + static QString prettyTypeName(const QObject *object); }; struct QQmlMetaTypeData; |