diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2017-01-05 20:19:18 +0100 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-01-11 13:49:04 +0000 |
commit | 5a5f140e60a65ae9a976444c1e47e5a8c606ff21 (patch) | |
tree | 1f9c5674b61b1ba6d20357826bf0a39cac029050 /src/qml/qml/qqmlinfo.cpp | |
parent | 971314dbb56c3761bb38abda8e257fd5f8502d00 (diff) |
QQmlInfo: Add qmlDebug & qmlWarning functions alongside qmlInfo
This way, we can correctly write to multiple levels of QDebug with QML context
information. A followup change will port all existing callers, and
subsequently change qmlInfo's message level to QtInfoMsg.
[ChangeLog][QtQml] Introduced qmlDebug & qmlWarning functions to qqmlinfo.h, in
addition to the pre-existing qmlInfo function. As a side effect, QQmlError has
also gained messageType() and setMessageType().
Change-Id: I04ced5952c5c3c58293a89a6767c7b545c03cc0a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlinfo.cpp')
-rw-r--r-- | src/qml/qml/qqmlinfo.cpp | 127 |
1 files changed, 104 insertions, 23 deletions
diff --git a/src/qml/qml/qqmlinfo.cpp b/src/qml/qml/qqmlinfo.cpp index 5b6e02d5b1..e87f29753a 100644 --- a/src/qml/qml/qqmlinfo.cpp +++ b/src/qml/qml/qqmlinfo.cpp @@ -50,13 +50,45 @@ QT_BEGIN_NAMESPACE /*! + \fn QQmlInfo QtQml::qmlDebug(const QObject *object) + \relates QQmlEngine + \since 5.9 + + Prints debug messages that include the file and line number for the + specified QML \a object. + + When QML types produce logging messages, it improves traceability + if they include the QML file and line number on which the + particular instance was instantiated. + + To include the file and line number, an object must be passed. If + the file and line number is not available for that instance + (either it was not instantiated by the QML engine or location + information is disabled), "unknown location" will be used instead. + + For example, + + \code + qmlDebug(object) << "Internal state: 42"; + \endcode + + prints + + \code + QML MyCustomType (unknown location): Internal state: 42 + \endcode + + \sa QtQml::qmlInfo, QtQml::qmlWarning +*/ + +/*! \fn QQmlInfo QtQml::qmlInfo(const QObject *object) \relates QQmlEngine - Prints warning messages that include the file and line number for the + Prints informational messages that include the file and line number for the specified QML \a object. - When QML types display warning messages, it improves traceability + When QML types produce logging messages, it improves traceability if they include the QML file and line number on which the particular instance was instantiated. @@ -76,14 +108,58 @@ QT_BEGIN_NAMESPACE \code QML MyCustomType (unknown location): component property is a write-once property \endcode + + \note In versions prior to Qt 5.9, qmlInfo reported messages using a warning + QtMsgType. For Qt 5.9 and above, qmlInfo uses an info QtMsgType. To send + warnings, use qmlWarning. + + \sa QtQml::qmlDebug, QtQml::qmlWarning +*/ + + +/*! + \fn QQmlInfo QtQml::qmlWarning(const QObject *object) + \relates QQmlEngine + \since 5.9 + + Prints warning messages that include the file and line number for the + specified QML \a object. + + When QML types produce logging messages, it improves traceability + if they include the QML file and line number on which the + particular instance was instantiated. + + To include the file and line number, an object must be passed. If + the file and line number is not available for that instance + (either it was not instantiated by the QML engine or location + information is disabled), "unknown location" will be used instead. + + For example, + + \code + qmlInfo(object) << tr("property cannot be set to 0"); + \endcode + + prints + + \code + QML MyCustomType (unknown location): property cannot be set to 0 + \endcode + + \sa QtQml::qmlDebug, QtQml::qmlInfo */ class QQmlInfoPrivate { public: - QQmlInfoPrivate() : ref (1), object(0) {} + QQmlInfoPrivate(QtMsgType type) + : ref (1) + , msgType(type) + , object(nullptr) + {} int ref; + QtMsgType msgType; const QObject *object; QString buffer; QList<QQmlError> errors; @@ -110,6 +186,7 @@ QQmlInfo::~QQmlInfo() if (!d->buffer.isEmpty()) { QQmlError error; + error.setMessageType(d->msgType); QObject *object = const_cast<QObject *>(d->object); @@ -139,28 +216,32 @@ QQmlInfo::~QQmlInfo() namespace QtQml { -QQmlInfo qmlInfo(const QObject *me) -{ - QQmlInfoPrivate *d = new QQmlInfoPrivate; - d->object = me; - return QQmlInfo(d); -} +#define MESSAGE_FUNCS(FuncName, MessageLevel) \ + QQmlInfo FuncName(const QObject *me) \ + { \ + QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ + d->object = me; \ + return QQmlInfo(d); \ + } \ + QQmlInfo FuncName(const QObject *me, const QQmlError &error) \ + { \ + QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ + d->object = me; \ + d->errors << error; \ + return QQmlInfo(d); \ + } \ + QQmlInfo FuncName(const QObject *me, const QList<QQmlError> &errors) \ + { \ + QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \ + d->object = me; \ + d->errors = errors; \ + return QQmlInfo(d); \ + } -QQmlInfo qmlInfo(const QObject *me, const QQmlError &error) -{ - QQmlInfoPrivate *d = new QQmlInfoPrivate; - d->object = me; - d->errors << error; - return QQmlInfo(d); -} +MESSAGE_FUNCS(qmlDebug, QtMsgType::QtDebugMsg) +MESSAGE_FUNCS(qmlInfo, QtMsgType::QtWarningMsg) // XXX: temporary, switch to QtInfoMsg when callers are ported +MESSAGE_FUNCS(qmlWarning, QtMsgType::QtWarningMsg) -QQmlInfo qmlInfo(const QObject *me, const QList<QQmlError> &errors) -{ - QQmlInfoPrivate *d = new QQmlInfoPrivate; - d->object = me; - d->errors = errors; - return QQmlInfo(d); -} } // namespace QtQml |