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