diff --git a/src/libs/qmldebug/qmldebugconnection.cpp b/src/libs/qmldebug/qmldebugconnection.cpp index 008aca91917..143277b379b 100644 --- a/src/libs/qmldebug/qmldebugconnection.cpp +++ b/src/libs/qmldebug/qmldebugconnection.cpp @@ -45,17 +45,16 @@ const QString clientId = QLatin1String("QDeclarativeDebugClient"); class QmlDebugConnectionPrivate { public: - QmlDebugConnectionPrivate(); - QPacketProtocol *protocol; - QLocalServer *server; - QIODevice *device; // Currently a QTcpSocket or a QLocalSocket + QPacketProtocol *protocol = nullptr; + QLocalServer *server = nullptr; + QIODevice *device = nullptr; // Currently a QTcpSocket or a QLocalSocket - bool gotHello; + bool gotHello = false; QHash serverPlugins; QHash plugins; - int currentDataStreamVersion; - int maximumDataStreamVersion; + int currentDataStreamVersion = QmlDebugConnection::minimumDataStreamVersion(); + int maximumDataStreamVersion = QDataStream::Qt_DefaultCompiledVersion; void advertisePlugins(); void flush(); @@ -75,13 +74,6 @@ static QString socketErrorToString(QAbstractSocket::SocketError error) return QmlDebugConnection::tr("Error: %1").arg(errorString); } -QmlDebugConnectionPrivate::QmlDebugConnectionPrivate() : - protocol(0), server(0), device(0), gotHello(false), - currentDataStreamVersion(QmlDebugConnection::minimumDataStreamVersion()), - maximumDataStreamVersion(QDataStream::Qt_DefaultCompiledVersion) -{ -} - void QmlDebugConnectionPrivate::advertisePlugins() { if (!gotHello) @@ -118,7 +110,7 @@ void QmlDebugConnection::socketDisconnected() if (d->protocol) { d->protocol->disconnect(); d->protocol->deleteLater(); - d->protocol = 0; + d->protocol = nullptr; } if (d->device) { // Don't allow any "connected()" or "disconnected()" signals to be triggered anymore. @@ -126,7 +118,7 @@ void QmlDebugConnection::socketDisconnected() d->device->disconnect(); // Don't immediately delete it as it may do some cleanup on returning from a signal. d->device->deleteLater(); - d->device = 0; + d->device = nullptr; } } @@ -220,7 +212,7 @@ void QmlDebugConnection::protocolReadyRead() QHash::Iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) { - const QString pluginName = iter.key(); + const QString &pluginName = iter.key(); QmlDebugClient::State newState = QmlDebugClient::Unavailable; if (d->serverPlugins.contains(pluginName)) newState = QmlDebugClient::Enabled; @@ -282,7 +274,7 @@ void QmlDebugConnection::close() QmlDebugClient *QmlDebugConnection::client(const QString &name) const { Q_D(const QmlDebugConnection); - return d->plugins.value(name, 0); + return d->plugins.value(name, nullptr); } bool QmlDebugConnection::addClient(const QString &name, QmlDebugClient *client) @@ -324,16 +316,11 @@ bool QmlDebugConnection::sendMessage(const QString &name, const QByteArray &mess return true; } -int QmlDebugConnection::minimumDataStreamVersion() -{ - return QDataStream::Qt_4_7; -} - void QmlDebugConnectionPrivate::flush() { - if (QAbstractSocket *socket = qobject_cast(device)) + if (auto socket = qobject_cast(device)) socket->flush(); - else if (QLocalSocket *socket = qobject_cast(device)) + else if (auto socket = qobject_cast(device)) socket->flush(); } @@ -341,7 +328,7 @@ void QmlDebugConnection::connectToHost(const QString &hostName, quint16 port) { Q_D(QmlDebugConnection); socketDisconnected(); - QTcpSocket *socket = new QTcpSocket(this); + auto socket = new QTcpSocket(this); socket->setProxy(QNetworkProxy::NoProxy); d->device = socket; d->protocol = new QPacketProtocol(socket, this); @@ -420,12 +407,11 @@ void QmlDebugConnection::setMaximumDataStreamVersion(int maximumVersion) QAbstractSocket::SocketState QmlDebugConnection::socketState() const { Q_D(const QmlDebugConnection); - if (QAbstractSocket *socket = qobject_cast(d->device)) + if (auto socket = qobject_cast(d->device)) return socket->state(); - else if (QLocalSocket *socket = qobject_cast(d->device)) + if (auto socket = qobject_cast(d->device)) return static_cast(socket->state()); - else - return QAbstractSocket::UnconnectedState; + return QAbstractSocket::UnconnectedState; } } // namespace QmlDebug diff --git a/src/libs/qmldebug/qmldebugconnection.h b/src/libs/qmldebug/qmldebugconnection.h index 6fe2e35a162..6ca73a1f3c8 100644 --- a/src/libs/qmldebug/qmldebugconnection.h +++ b/src/libs/qmldebug/qmldebugconnection.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace QmlDebug { @@ -38,10 +39,9 @@ class QmlDebugConnectionPrivate; class QMLDEBUG_EXPORT QmlDebugConnection : public QObject { Q_OBJECT - Q_DISABLE_COPY(QmlDebugConnection) Q_DECLARE_PRIVATE(QmlDebugConnection) public: - QmlDebugConnection(QObject * = 0); + QmlDebugConnection(QObject *parent = nullptr); ~QmlDebugConnection() override; void connectToHost(const QString &hostName, quint16 port); @@ -62,7 +62,10 @@ public: float serviceVersion(const QString &serviceName) const; bool sendMessage(const QString &name, const QByteArray &message); - static int minimumDataStreamVersion(); + static constexpr int minimumDataStreamVersion() + { + return QDataStream::Qt_4_7; + } signals: void connected();