Network: Fix operator<<(QDebug, ...) operations

Use the

  QDebugStateSaver saver(debug);
  debug.resetFormat().nospace();

idiom to unify the formatting and whitespace handling.

Change-Id: Id346d63b3f589b60ca19e4459271d587f1a0c003
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Kai Koehne 2015-02-11 10:22:01 +01:00
parent 7997e56a2e
commit cd83859bd6
10 changed files with 56 additions and 34 deletions

View File

@ -1034,8 +1034,10 @@ void QNetworkCookie::normalize(const QUrl &url)
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
{
s.nospace() << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')';
return s.space();
QDebugStateSaver saver(s);
s.resetFormat().nospace();
s << "QNetworkCookie(" << cookie.toRawForm(QNetworkCookie::Full) << ')';
return s;
}
#endif

View File

@ -1040,11 +1040,13 @@ bool QHostAddress::isLoopback() const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug d, const QHostAddress &address)
{
QDebugStateSaver saver(d);
d.resetFormat().nospace();
if (address == QHostAddress::Any)
d.maybeSpace() << "QHostAddress(QHostAddress::Any)";
d << "QHostAddress(QHostAddress::Any)";
else
d.maybeSpace() << "QHostAddress(" << address.toString() << ')';
return d.space();
d << "QHostAddress(" << address.toString() << ')';
return d;
}
#endif

View File

@ -580,40 +580,42 @@ QList<QHostAddress> QNetworkInterface::allAddresses()
static inline QDebug flagsDebug(QDebug debug, QNetworkInterface::InterfaceFlags flags)
{
if (flags & QNetworkInterface::IsUp)
debug.nospace() << "IsUp ";
debug << "IsUp ";
if (flags & QNetworkInterface::IsRunning)
debug.nospace() << "IsRunning ";
debug << "IsRunning ";
if (flags & QNetworkInterface::CanBroadcast)
debug.nospace() << "CanBroadcast ";
debug << "CanBroadcast ";
if (flags & QNetworkInterface::IsLoopBack)
debug.nospace() << "IsLoopBack ";
debug << "IsLoopBack ";
if (flags & QNetworkInterface::IsPointToPoint)
debug.nospace() << "IsPointToPoint ";
debug << "IsPointToPoint ";
if (flags & QNetworkInterface::CanMulticast)
debug.nospace() << "CanMulticast ";
return debug.nospace();
debug << "CanMulticast ";
return debug;
}
static inline QDebug operator<<(QDebug debug, const QNetworkAddressEntry &entry)
{
debug.nospace() << "(address = " << entry.ip();
debug << "(address = " << entry.ip();
if (!entry.netmask().isNull())
debug.nospace() << ", netmask = " << entry.netmask();
debug << ", netmask = " << entry.netmask();
if (!entry.broadcast().isNull())
debug.nospace() << ", broadcast = " << entry.broadcast();
debug.nospace() << ')';
return debug.space();
debug << ", broadcast = " << entry.broadcast();
debug << ')';
return debug;
}
QDebug operator<<(QDebug debug, const QNetworkInterface &networkInterface)
{
debug.nospace() << "QNetworkInterface(name = " << networkInterface.name()
<< ", hardware address = " << networkInterface.hardwareAddress()
<< ", flags = ";
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QNetworkInterface(name = " << networkInterface.name()
<< ", hardware address = " << networkInterface.hardwareAddress()
<< ", flags = ";
flagsDebug(debug, networkInterface.flags());
debug.nospace() << ", entries = " << networkInterface.addressEntries()
<< ")\n";
return debug.space();
debug << ", entries = " << networkInterface.addressEntries()
<< ")\n";
return debug;
}
#endif

View File

@ -1580,6 +1580,8 @@ QList<QNetworkProxy> QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuer
*/
QDebug operator<<(QDebug debug, const QNetworkProxy &proxy)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
QNetworkProxy::ProxyType type = proxy.type();
switch (type) {
case QNetworkProxy::NoProxy:

View File

@ -2915,6 +2915,8 @@ QNetworkProxy QAbstractSocket::proxy() const
#ifndef QT_NO_DEBUG_STREAM
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError error)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (error) {
case QAbstractSocket::ConnectionRefusedError:
debug << "QAbstractSocket::ConnectionRefusedError";
@ -2982,6 +2984,8 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketError er
Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QAbstractSocket::SocketState state)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (state) {
case QAbstractSocket::UnconnectedState:
debug << "QAbstractSocket::UnconnectedState";

View File

@ -487,6 +487,8 @@ bool QLocalSocket::isSequential() const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (error) {
case QLocalSocket::ConnectionRefusedError:
debug << "QLocalSocket::ConnectionRefusedError";
@ -527,6 +529,8 @@ QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketError error)
QDebug operator<<(QDebug debug, QLocalSocket::LocalSocketState state)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
switch (state) {
case QLocalSocket::UnconnectedState:
debug << "QLocalSocket::UnconnectedState";

View File

@ -682,16 +682,18 @@ QByteArray QSslCertificatePrivate::subjectInfoToString(QSslCertificate::SubjectI
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QSslCertificate &certificate)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QSslCertificate("
<< certificate.version()
<< ',' << certificate.serialNumber()
<< ',' << certificate.digest().toBase64()
<< ',' << certificate.issuerInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectInfo(QSslCertificate::Organization)
<< ',' << certificate.subjectAlternativeNames()
<< ", " << certificate.serialNumber()
<< ", " << certificate.digest().toBase64()
<< ", " << certificate.issuerInfo(QSslCertificate::Organization)
<< ", " << certificate.subjectInfo(QSslCertificate::Organization)
<< ", " << certificate.subjectAlternativeNames()
#ifndef QT_NO_DATESTRING
<< ',' << certificate.effectiveDate()
<< ',' << certificate.expiryDate()
<< ", " << certificate.effectiveDate()
<< ", " << certificate.expiryDate()
#endif
<< ')';
return debug;

View File

@ -248,9 +248,11 @@ QSsl::SslProtocol QSslCipher::protocol() const
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug debug, const QSslCipher &cipher)
{
debug << "QSslCipher(name=" << qPrintable(cipher.name())
QDebugStateSaver saver(debug);
debug.resetFormat().nospace().noquote();
debug << "QSslCipher(name=" << cipher.name()
<< ", bits=" << cipher.usedBits()
<< ", proto=" << qPrintable(cipher.protocolString())
<< ", proto=" << cipher.protocolString()
<< ')';
return debug;
}

View File

@ -170,7 +170,8 @@ QT_BEGIN_NAMESPACE
QDebug operator<<(QDebug debug, QSslEllipticCurve curve)
{
QDebugStateSaver saver(debug);
debug.nospace() << "QSslEllipticCurve(" << curve.shortName() << ")";
debug.resetFormat().nospace();
debug << "QSslEllipticCurve(" << curve.shortName() << ")";
return debug;
}
#endif

View File

@ -444,9 +444,10 @@ bool QSslKey::operator==(const QSslKey &other) const
*/
#ifndef QT_NO_DEBUG_STREAM
class QDebug;
QDebug operator<<(QDebug debug, const QSslKey &key)
{
QDebugStateSaver saver(debug);
debug.resetFormat().nospace();
debug << "QSslKey("
<< (key.type() == QSsl::PublicKey ? "PublicKey" : "PrivateKey")
<< ", " << (key.algorithm() == QSsl::Opaque ? "OPAQUE" :