forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user