Add debug operator for QStorageInfo

Change-Id: Ia788a882a11443237ac362631d55b4dcd6d6b44f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Friedemann Kleint 2017-06-13 09:09:25 +02:00
parent 6634c424f8
commit b8fd4e1a48
2 changed files with 42 additions and 0 deletions

View File

@ -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

View File

@ -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<QStorageInfoPrivate> 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)