From b8fd4e1a48cab568da9fb2bd88eb2d3fabb964b6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 13 Jun 2017 09:09:25 +0200 Subject: [PATCH] Add debug operator for QStorageInfo Change-Id: Ia788a882a11443237ac362631d55b4dcd6d6b44f Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo.cpp | 35 +++++++++++++++++++++++++++++++++ src/corelib/io/qstorageinfo.h | 7 +++++++ 2 files changed, 42 insertions(+) diff --git a/src/corelib/io/qstorageinfo.cpp b/src/corelib/io/qstorageinfo.cpp index 27f0552a31..e2c1f0232f 100644 --- a/src/corelib/io/qstorageinfo.cpp +++ b/src/corelib/io/qstorageinfo.cpp @@ -40,6 +40,8 @@ #include "qstorageinfo.h" #include "qstorageinfo_p.h" +#include "qdebug.h" + QT_BEGIN_NAMESPACE /*! @@ -431,4 +433,37 @@ QStorageInfo QStorageInfo::root() volume than the \a second; otherwise returns false. */ +#ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug debug, const QStorageInfo &s) +{ + QDebugStateSaver saver(debug); + debug.nospace(); + debug.noquote(); + debug << "QStorageInfo("; + if (s.isValid()) { + const QStorageInfoPrivate *d = s.d.constData(); + debug << '"' << d->rootPath << '"'; + if (!d->fileSystemType.isEmpty()) + debug << ", type=" << d->fileSystemType; + if (!d->name.isEmpty()) + debug << ", name=\"" << d->name << '"'; + if (!d->device.isEmpty()) + debug << ", device=\"" << d->device << '"'; + if (!d->subvolume.isEmpty()) + debug << ", subvolume=\"" << d->subvolume << '"'; + if (d->readOnly) + debug << " [read only]"; + debug << (d->ready ? " [ready]" : " [not ready]"); + if (d->bytesTotal > 0) { + debug << ", bytesTotal=" << d->bytesTotal << ", bytesFree=" << d->bytesFree + << ", bytesAvailable=" << d->bytesAvailable; + } + } else { + debug << "invalid"; + } + debug<< ')'; + return debug; +} +#endif // !QT_NO_DEBUG_STREAM + QT_END_NAMESPACE diff --git a/src/corelib/io/qstorageinfo.h b/src/corelib/io/qstorageinfo.h index e2d9747ceb..4ab7a353ef 100644 --- a/src/corelib/io/qstorageinfo.h +++ b/src/corelib/io/qstorageinfo.h @@ -49,6 +49,8 @@ QT_BEGIN_NAMESPACE +class QDebug; + class QStorageInfoPrivate; class Q_CORE_EXPORT QStorageInfo { @@ -94,6 +96,7 @@ public: private: friend class QStorageInfoPrivate; friend bool operator==(const QStorageInfo &first, const QStorageInfo &second); + friend Q_CORE_EXPORT QDebug operator<<(QDebug, const QStorageInfo &); QExplicitlySharedDataPointer d; }; @@ -114,6 +117,10 @@ inline bool QStorageInfo::isRoot() const Q_DECLARE_SHARED(QStorageInfo) +#ifndef QT_NO_DEBUG_STREAM +Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QStorageInfo &); +#endif + QT_END_NAMESPACE Q_DECLARE_METATYPE(QStorageInfo)