diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativeinfo.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativeinfo.cpp | 119 |
1 files changed, 81 insertions, 38 deletions
diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index 0a4352f..f6560a6 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -45,6 +45,7 @@ #include "qdeclarativecontext.h" #include "private/qdeclarativecontext_p.h" #include "private/qdeclarativemetatype_p.h" +#include "private/qdeclarativeengine_p.h" #include <QCoreApplication> @@ -77,52 +78,94 @@ QT_BEGIN_NAMESPACE \endcode */ +struct QDeclarativeInfoPrivate +{ + const QObject *object; + QString *buffer; + QList<QDeclarativeError> errors; +}; + QDeclarativeInfo::QDeclarativeInfo(const QObject *object) -: QDebug(QtWarningMsg) +: QDebug((*(QString **)&d) = new QString) { - QString pos = QLatin1String("QML"); - if (object) { - pos += QLatin1Char(' '); - - QString typeName; - QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); - if (type) { - typeName = QLatin1String(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); - } + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; - pos += typeName; - } - QDeclarativeData *ddata = object?QDeclarativeData::get(object):0; - pos += QLatin1String(" ("); - if (ddata) { - if (ddata->outerContext && !ddata->outerContext->url.isEmpty()) { - pos += ddata->outerContext->url.toString(); - pos += QLatin1Char(':'); - pos += QString::number(ddata->lineNumber); - pos += QLatin1Char(':'); - pos += QString::number(ddata->columnNumber); - } else { - pos += QCoreApplication::translate("QDeclarativeInfo","unknown location"); - } - } else { - pos += QCoreApplication::translate("QDeclarativeInfo","unknown location"); - } - pos += QLatin1Char(')'); - *this << pos; + d->object = object; nospace(); } -QDeclarativeInfo::~QDeclarativeInfo() +QDeclarativeInfo::QDeclarativeInfo(const QObject *object, const QList<QDeclarativeError> &errors) +: QDebug((*(QString **)&d) = new QString) { + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; + + d->object = object; + d->errors = errors; + nospace(); } +QDeclarativeInfo::QDeclarativeInfo(const QObject *object, const QDeclarativeError &error) +: QDebug((*(QString **)&d) = new QString) +{ + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; + + d->object = object; + d->errors << error; + nospace(); +} + +QDeclarativeInfo::~QDeclarativeInfo() +{ + QList<QDeclarativeError> errors = d->errors; + + QDeclarativeEngine *engine = 0; + + if (!d->buffer->isEmpty()) { + QDeclarativeError error; + + QObject *object = const_cast<QObject *>(d->object); + + if (object) { + engine = qmlEngine(d->object); + QString typeName; + QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); + if (type) { + typeName = QLatin1String(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); + } + + d->buffer->prepend(QLatin1String("QML ") + typeName + QLatin1String(": ")); + + QDeclarativeData *ddata = QDeclarativeData::get(object, false); + if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) { + error.setUrl(ddata->outerContext->url); + error.setLine(ddata->lineNumber); + error.setColumn(ddata->columnNumber); + } + } + + error.setDescription(*d->buffer); + + errors.prepend(error); + } + + QDeclarativeEnginePrivate::warning(engine, errors); + + delete d->buffer; + delete d; +} QT_END_NAMESPACE |