diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-04-09 18:06:02 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-04-10 19:46:09 +0000 |
commit | 88c790b72e78d728dd9e2dc2fb27c630accb8afe (patch) | |
tree | fb7e787e0b3a6eabb8ae121fc753f6d11d899a15 /src/libs/qmldebug | |
parent | 741dc7bfead1058729afd096a918a720e5b13837 (diff) |
QmlDebug: Modernize QmlDebugConnection
Use nullptr, auto, and initialize members inline.
Change-Id: Ie031057e8f4a3a74c22a86b343d8b5c265454550
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Diffstat (limited to 'src/libs/qmldebug')
-rw-r--r-- | src/libs/qmldebug/qmldebugconnection.cpp | 46 | ||||
-rw-r--r-- | src/libs/qmldebug/qmldebugconnection.h | 9 |
2 files changed, 22 insertions, 33 deletions
diff --git a/src/libs/qmldebug/qmldebugconnection.cpp b/src/libs/qmldebug/qmldebugconnection.cpp index 008aca9191..143277b379 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 <QString, float> serverPlugins; QHash<QString, QmlDebugClient *> 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<QString, QmlDebugClient *>::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<QAbstractSocket *>(device)) + if (auto socket = qobject_cast<QAbstractSocket *>(device)) socket->flush(); - else if (QLocalSocket *socket = qobject_cast<QLocalSocket *>(device)) + else if (auto socket = qobject_cast<QLocalSocket *>(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<QAbstractSocket *>(d->device)) + if (auto socket = qobject_cast<QAbstractSocket *>(d->device)) return socket->state(); - else if (QLocalSocket *socket = qobject_cast<QLocalSocket *>(d->device)) + if (auto socket = qobject_cast<QLocalSocket *>(d->device)) return static_cast<QAbstractSocket::SocketState>(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 6fe2e35a16..6ca73a1f3c 100644 --- a/src/libs/qmldebug/qmldebugconnection.h +++ b/src/libs/qmldebug/qmldebugconnection.h @@ -30,6 +30,7 @@ #include <QObject> #include <QUrl> #include <QAbstractSocket> +#include <QDataStream> 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(); |