Add QDebug operator for QMimeType.

Task-number: QTBUG-35686
Change-Id: I72be7cf9374f86e8cb3e6946129bbfec8fec9616
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2014-02-15 10:48:40 +01:00 committed by The Qt Project
parent 91c9cae720
commit 14bd7a5881
3 changed files with 20 additions and 0 deletions

View File

@ -443,4 +443,17 @@ bool QMimeType::inherits(const QString &mimeTypeName) const
return QMimeDatabasePrivate::instance()->inherits(d->name, mimeTypeName);
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QMimeType &mime)
{
QDebugStateSaver saver(debug);
if (!mime.isValid()) {
debug.nospace() << "QMimeType(invalid)";
} else {
debug.nospace() << "QMimeType(" << mime.name() << ")";
}
return debug;
}
#endif
QT_END_NAMESPACE

View File

@ -110,5 +110,10 @@ protected:
Q_DECLARE_SHARED(QMimeType)
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime);
#endif
QT_END_NAMESPACE
#endif // QMIMETYPE_H

View File

@ -211,6 +211,8 @@ void tst_QDebug::debugSpaceHandling() const
QCOMPARE(s_msg, QString::fromLatin1("QPoint(21,22) QRect(23,24 25x26) QLine(QPoint(27,28),QPoint(29,30))"));
qDebug() << QPointF(21, 22) << QRectF(23, 24, 25, 26) << QLineF(27, 28, 29, 30);
QCOMPARE(s_msg, QString::fromLatin1("QPointF(21,22) QRectF(23,24 25x26) QLineF(QPointF(27,28),QPointF(29,30))"));
qDebug() << QMimeType() << QMimeDatabase().mimeTypeForName("application/pdf") << "foo";
QCOMPARE(s_msg, QString::fromLatin1("QMimeType(invalid) QMimeType(\"application/pdf\") foo"));
}
void tst_QDebug::stateSaver() const