From 895a511245ae3750ac41b352cdc6915c8f8dd110 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 5 Feb 2018 14:15:47 +0100 Subject: QQmlDebugClient: Make stateChanged a signal This way we can observe it from the outside and drop all the code that genrated extra signals from the virtual method. Also drop the unused QQmlDebugTestService::stateHasChanged signal to reduce the confusion. Change-Id: Ia37c1eaf8b392e594b0931694f43f84fe09b000c Reviewed-by: Simon Hausmann --- src/qmldebug/qqmldebugclient.cpp | 5 ----- src/qmldebug/qqmldebugclient_p.h | 5 +++-- src/qmldebug/qqmldebugconnection.cpp | 4 ++-- src/qmldebug/qqmldebugmessageclient.cpp | 5 ----- src/qmldebug/qqmldebugmessageclient_p.h | 5 ----- src/qmldebug/qqmlprofilerclient.cpp | 3 ++- src/qmldebug/qqmlprofilerclient_p.h | 2 +- .../debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp | 9 --------- .../qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp | 6 ++++-- tests/auto/qml/debugger/shared/debugutil.cpp | 9 +++------ tests/auto/qml/debugger/shared/debugutil_p.h | 2 -- tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp | 1 - tests/auto/qml/debugger/shared/qqmldebugtestservice.h | 3 --- tools/qmlprofiler/qmlprofilerclient.cpp | 4 +++- tools/qmlprofiler/qmlprofilerclient.h | 2 +- 15 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/qmldebug/qqmldebugclient.cpp b/src/qmldebug/qqmldebugclient.cpp index d412b7b267..03123cc6e0 100644 --- a/src/qmldebug/qqmldebugclient.cpp +++ b/src/qmldebug/qqmldebugclient.cpp @@ -117,11 +117,6 @@ QQmlDebugConnection *QQmlDebugClient::connection() const return d->connection; } -void QQmlDebugClient::stateChanged(QQmlDebugClient::State state) -{ - Q_UNUSED(state); -} - void QQmlDebugClient::messageReceived(const QByteArray &message) { Q_UNUSED(message); diff --git a/src/qmldebug/qqmldebugclient_p.h b/src/qmldebug/qqmldebugclient_p.h index 723de5ee43..469b65d4a9 100644 --- a/src/qmldebug/qqmldebugclient_p.h +++ b/src/qmldebug/qqmldebugclient_p.h @@ -76,13 +76,14 @@ public: QQmlDebugConnection *connection() const; +signals: + void stateChanged(State state); + protected: QQmlDebugClient(QQmlDebugClientPrivate &dd); private: friend class QQmlDebugConnection; - - virtual void stateChanged(State state); virtual void messageReceived(const QByteArray &message); }; diff --git a/src/qmldebug/qqmldebugconnection.cpp b/src/qmldebug/qqmldebugconnection.cpp index 67bad8d812..4e087ee6db 100644 --- a/src/qmldebug/qqmldebugconnection.cpp +++ b/src/qmldebug/qqmldebugconnection.cpp @@ -259,7 +259,7 @@ QQmlDebugConnection::~QQmlDebugConnection() Q_D(QQmlDebugConnection); QHash::iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) - iter.value()->stateChanged(QQmlDebugClient::NotConnected); + emit iter.value()->stateChanged(QQmlDebugClient::NotConnected); } int QQmlDebugConnection::currentDataStreamVersion() const @@ -295,7 +295,7 @@ void QQmlDebugConnection::close() QHash::iterator iter = d->plugins.begin(); for (; iter != d->plugins.end(); ++iter) - iter.value()->stateChanged(QQmlDebugClient::NotConnected); + emit iter.value()->stateChanged(QQmlDebugClient::NotConnected); } if (d->device) { diff --git a/src/qmldebug/qqmldebugmessageclient.cpp b/src/qmldebug/qqmldebugmessageclient.cpp index a03c1f8af2..0892404194 100644 --- a/src/qmldebug/qqmldebugmessageclient.cpp +++ b/src/qmldebug/qqmldebugmessageclient.cpp @@ -58,11 +58,6 @@ QQmlDebugMessageClient::QQmlDebugMessageClient(QQmlDebugConnection *client) { } -void QQmlDebugMessageClient::stateChanged(State state) -{ - emit newState(state); -} - void QQmlDebugMessageClient::messageReceived(const QByteArray &data) { QDataStream ds(data); diff --git a/src/qmldebug/qqmldebugmessageclient_p.h b/src/qmldebug/qqmldebugmessageclient_p.h index 75c70044e4..a2a7f28f81 100644 --- a/src/qmldebug/qqmldebugmessageclient_p.h +++ b/src/qmldebug/qqmldebugmessageclient_p.h @@ -71,15 +71,10 @@ class QQmlDebugMessageClient : public QQmlDebugClient public: explicit QQmlDebugMessageClient(QQmlDebugConnection *client); - virtual void stateChanged(State state) override; virtual void messageReceived(const QByteArray &) override; signals: - void newState(QQmlDebugClient::State); void message(QtMsgType, const QString &, const QQmlDebugContextInfo &); - -private: - Q_DISABLE_COPY(QQmlDebugMessageClient) }; QT_END_NAMESPACE diff --git a/src/qmldebug/qqmlprofilerclient.cpp b/src/qmldebug/qqmlprofilerclient.cpp index 356190f2b0..0f3cbb49ee 100644 --- a/src/qmldebug/qqmlprofilerclient.cpp +++ b/src/qmldebug/qqmlprofilerclient.cpp @@ -170,6 +170,7 @@ QQmlProfilerClient::QQmlProfilerClient(QQmlDebugConnection *connection, { Q_D(QQmlProfilerClient); setRequestedFeatures(features); + connect(this, &QQmlDebugClient::stateChanged, this, &QQmlProfilerClient::onStateChanged); connect(d->engineControl.data(), &QQmlEngineControlClient::engineAboutToBeAdded, this, &QQmlProfilerClient::sendRecordingStatus); connect(d->engineControl.data(), &QQmlEngineControlClient::engineAboutToBeRemoved, @@ -319,7 +320,7 @@ bool QQmlProfilerClientPrivate::updateFeatures(ProfileFeature feature) return true; } -void QQmlProfilerClient::stateChanged(State status) +void QQmlProfilerClient::onStateChanged(State status) { if (status == Enabled) { sendRecordingStatus(-1); diff --git a/src/qmldebug/qqmlprofilerclient_p.h b/src/qmldebug/qqmlprofilerclient_p.h index 68a32a1a5a..0c867525d2 100644 --- a/src/qmldebug/qqmlprofilerclient_p.h +++ b/src/qmldebug/qqmlprofilerclient_p.h @@ -76,7 +76,6 @@ public: void setRecording(bool); quint64 recordedFeatures() const; virtual void messageReceived(const QByteArray &) override; - virtual void stateChanged(State status) override; void clearEvents(); void clearAll(); @@ -87,6 +86,7 @@ public: protected: QQmlProfilerClient(QQmlProfilerClientPrivate &dd); + void onStateChanged(State status); signals: void complete(qint64 maximumTime); diff --git a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp index f851688b5e..d2cfd3897a 100644 --- a/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp +++ b/tests/auto/qml/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp @@ -89,21 +89,12 @@ public: protected: //inherited from QQmlDebugClient - void stateChanged(State state); void messageReceived(const QByteArray &data); signals: - void enabled(); void debugOutput(); }; -void QQmlDebugMsgClient::stateChanged(State state) -{ - if (state == Enabled) { - emit enabled(); - } -} - void QQmlDebugMsgClient::messageReceived(const QByteArray &data) { QPacket ds(connection()->currentDataStreamVersion(), data); diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp index 3cd359cf48..37d4ef1160 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp @@ -251,6 +251,8 @@ public: { parser = jsEngine.evaluate(QLatin1String("JSON.parse")); stringify = jsEngine.evaluate(QLatin1String("JSON.stringify")); + QObject::connect(this, &QQmlDebugClient::stateChanged, + this, &QJSDebugClient::onStateChanged); } void connect(bool redundantRefs = false, bool namesAsObjects = false); @@ -272,7 +274,7 @@ public: protected: //inherited from QQmlDebugClient - void stateChanged(State state); + void onStateChanged(State state); void messageReceived(const QByteArray &data); signals: @@ -660,7 +662,7 @@ void QJSDebugClient::disconnect() sendMessage(packMessage(DISCONNECT, json.toString().toUtf8())); } -void QJSDebugClient::stateChanged(State state) +void QJSDebugClient::onStateChanged(State state) { if (state == Enabled) flushSendBuffer(); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index b38e0bd731..a6f7fa8724 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -92,6 +92,9 @@ QString QQmlDebugTest::connectionStateString(const QQmlDebugConnection *connecti QQmlDebugTestClient::QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c) : QQmlDebugClient(s, c) { + connect(this, &QQmlDebugClient::stateChanged, this, [this](QQmlDebugClient::State newState) { + QCOMPARE(newState, state()); + }); } QByteArray QQmlDebugTestClient::waitForResponse() @@ -105,12 +108,6 @@ QByteArray QQmlDebugTestClient::waitForResponse() return lastMsg; } -void QQmlDebugTestClient::stateChanged(State stat) -{ - QCOMPARE(stat, state()); - emit stateHasChanged(); -} - void QQmlDebugTestClient::messageReceived(const QByteArray &ba) { lastMsg = ba; diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 94ad83bfce..05665f8a28 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -88,11 +88,9 @@ public: QByteArray waitForResponse(); signals: - void stateHasChanged(); void serverMessage(const QByteArray &); protected: - virtual void stateChanged(State state); virtual void messageReceived(const QByteArray &ba); private: diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp index 4dce07d824..896ed608fd 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.cpp @@ -48,5 +48,4 @@ void QQmlDebugTestService::stateAboutToBeChanged(QQmlDebugService::State) void QQmlDebugTestService::stateChanged(State) { Q_ASSERT(QThread::currentThread() != thread()); - emit stateHasChanged(); } diff --git a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h index 37b4a9f98c..9c39c0893d 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugtestservice.h +++ b/tests/auto/qml/debugger/shared/qqmldebugtestservice.h @@ -38,9 +38,6 @@ class QQmlDebugTestService : public QQmlDebugService public: QQmlDebugTestService(const QString &s, float version = 1, QObject *parent = 0); -signals: - void stateHasChanged(); - protected: virtual void messageReceived(const QByteArray &ba); virtual void stateAboutToBeChanged(State state); diff --git a/tools/qmlprofiler/qmlprofilerclient.cpp b/tools/qmlprofiler/qmlprofilerclient.cpp index b69c7e73e1..f6cc6f39fe 100644 --- a/tools/qmlprofiler/qmlprofilerclient.cpp +++ b/tools/qmlprofiler/qmlprofilerclient.cpp @@ -57,6 +57,8 @@ QmlProfilerClient::QmlProfilerClient(QQmlDebugConnection *connection, QmlProfile { Q_D(QmlProfilerClient); setRequestedFeatures(std::numeric_limits::max()); + connect(this, &QQmlDebugClient::stateChanged, + this, &QmlProfilerClient::onStateChanged); connect(this, &QQmlProfilerClient::traceStarted, d->data, &QmlProfilerData::setTraceStartTime); connect(this, &QQmlProfilerClient::traceFinished, @@ -65,7 +67,7 @@ QmlProfilerClient::QmlProfilerClient(QQmlDebugConnection *connection, QmlProfile d->data, &QmlProfilerData::complete); } -void QmlProfilerClient::stateChanged(State state) +void QmlProfilerClient::onStateChanged(State state) { Q_D(QmlProfilerClient); if ((d->enabled && state != Enabled) || (!d->enabled && state == Enabled)) { diff --git a/tools/qmlprofiler/qmlprofilerclient.h b/tools/qmlprofiler/qmlprofilerclient.h index b9d8ce241f..b4b4ad2b2f 100644 --- a/tools/qmlprofiler/qmlprofilerclient.h +++ b/tools/qmlprofiler/qmlprofilerclient.h @@ -48,7 +48,7 @@ signals: void error(const QString &error); private: - void stateChanged(State state) override; + void onStateChanged(State state); }; #endif // QMLPROFILERCLIENT_H -- cgit v1.2.3