diff options
24 files changed, 316 insertions, 134 deletions
diff --git a/src/imports/webchannel/plugin.cpp b/src/imports/webchannel/plugin.cpp index 6507112..235f542 100644 --- a/src/imports/webchannel/plugin.cpp +++ b/src/imports/webchannel/plugin.cpp @@ -42,7 +42,8 @@ #include <qqml.h> #include <QtQml/QQmlExtensionPlugin> -#include "qmlwebchannel.h" +#include <qqmlwebchannel.h> +#include <qqmlwebchannelattached_p.h> QT_BEGIN_NAMESPACE @@ -59,7 +60,7 @@ void QWebChannelPlugin::registerTypes(const char *uri) { int major = 1; int minor = 0; - qmlRegisterType<QmlWebChannel>(uri, major, minor, "WebChannel"); + qmlRegisterType<QQmlWebChannel>(uri, major, minor, "WebChannel"); } QT_END_NAMESPACE diff --git a/src/imports/webchannel/webchannel.pro b/src/imports/webchannel/webchannel.pro index c1959f5..8ae6ef5 100644 --- a/src/imports/webchannel/webchannel.pro +++ b/src/imports/webchannel/webchannel.pro @@ -4,12 +4,6 @@ INCLUDEPATH += ../../webchannel VPATH += ../../webchannel SOURCES += \ - plugin.cpp \ - qmlwebchannel.cpp \ - qmlwebchannelattached.cpp - -HEADERS += \ - qmlwebchannel.h \ - qmlwebchannelattached.h + plugin.cpp load(qml_plugin) diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp index 096bf7b..646398d 100644 --- a/src/webchannel/qmetaobjectpublisher.cpp +++ b/src/webchannel/qmetaobjectpublisher.cpp @@ -395,7 +395,7 @@ QByteArray QMetaObjectPublisher::invokeMethod(QObject *const object, const int m void QMetaObjectPublisher::signalEmitted(const QObject *object, const int signalIndex, const QVariantList &arguments) { - if (!webChannel || webChannel->d->transports.isEmpty()) { + if (!webChannel || webChannel->d_func()->transports.isEmpty()) { return; } if (!signalToPropertyMap.value(object).contains(signalIndex)) { diff --git a/src/webchannel/qmetaobjectpublisher_p.h b/src/webchannel/qmetaobjectpublisher_p.h index dda18ae..4da0c26 100644 --- a/src/webchannel/qmetaobjectpublisher_p.h +++ b/src/webchannel/qmetaobjectpublisher_p.h @@ -172,7 +172,7 @@ protected: void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; private: - friend class QmlWebChannel; + friend class QQmlWebChannelPrivate; friend class QWebChannel; friend class TestWebChannel; diff --git a/src/imports/webchannel/qmlwebchannel.cpp b/src/webchannel/qqmlwebchannel.cpp index e61e9c8..ca99fe5 100644 --- a/src/imports/webchannel/qmlwebchannel.cpp +++ b/src/webchannel/qqmlwebchannel.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qmlwebchannel.h" +#include "qqmlwebchannel.h" #include "qwebchannel_p.h" #include "qmetaobjectpublisher_p.h" @@ -47,20 +47,50 @@ #include <QtQml/QQmlContext> -QT_USE_NAMESPACE +#include "qqmlwebchannelattached_p.h" -QmlWebChannel::QmlWebChannel(QObject *parent) - : QWebChannel(parent) +QT_BEGIN_NAMESPACE + +class QQmlWebChannelPrivate : public QWebChannelPrivate +{ + Q_DECLARE_PUBLIC(QQmlWebChannel) +public: + QVector<QObject*> registeredObjects; + + void _q_objectIdChanged(const QString &newId); +}; + +void QQmlWebChannelPrivate::_q_objectIdChanged(const QString &newId) +{ + Q_Q(QQmlWebChannel); + const QQmlWebChannelAttached *const attached = qobject_cast<QQmlWebChannelAttached*>(q->sender()); + Q_ASSERT(attached); + Q_ASSERT(attached->parent()); + Q_ASSERT(registeredObjects.contains(attached->parent())); + + QObject *const object = attached->parent(); + const QString &oldId = publisher->registeredObjectIds.value(object); + + if (!oldId.isEmpty()) { + q->deregisterObject(object); + } + + q->registerObject(newId, object); +} + +QQmlWebChannel::QQmlWebChannel(QObject *parent) + : QWebChannel(*(new QQmlWebChannelPrivate), parent) { } -QmlWebChannel::~QmlWebChannel() +QQmlWebChannel::~QQmlWebChannel() { } -void QmlWebChannel::registerObjects(const QVariantMap &objects) +void QQmlWebChannel::registerObjects(const QVariantMap &objects) { + Q_D(QQmlWebChannel); QMap<QString, QVariant>::const_iterator it = objects.constBegin(); for (; it != objects.constEnd(); ++it) { QObject *object = it.value().value<QObject*>(); @@ -72,34 +102,12 @@ void QmlWebChannel::registerObjects(const QVariantMap &objects) } } -bool QmlWebChannel::test_clientIsIdle() const +QQmlWebChannelAttached *QQmlWebChannel::qmlAttachedProperties(QObject *obj) { - return d->publisher->clientIsIdle; + return new QQmlWebChannelAttached(obj); } -void QmlWebChannel::objectIdChanged(const QString &newId) -{ - const QmlWebChannelAttached *const attached = qobject_cast<QmlWebChannelAttached*>(sender()); - Q_ASSERT(attached); - Q_ASSERT(attached->parent()); - Q_ASSERT(m_registeredObjects.contains(attached->parent())); - - QObject *const object = attached->parent(); - const QString &oldId = d->publisher->registeredObjectIds.value(object); - - if (!oldId.isEmpty()) { - deregisterObject(object); - } - - registerObject(newId, object); -} - -QmlWebChannelAttached *QmlWebChannel::qmlAttachedProperties(QObject *obj) -{ - return new QmlWebChannelAttached(obj); -} - -void QmlWebChannel::connectTo(QObject *transport) +void QQmlWebChannel::connectTo(QObject *transport) { if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) { QWebChannel::connectTo(realTransport); @@ -108,7 +116,7 @@ void QmlWebChannel::connectTo(QObject *transport) } } -void QmlWebChannel::disconnectFrom(QObject *transport) +void QQmlWebChannel::disconnectFrom(QObject *transport) { if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) { QWebChannel::disconnectFrom(realTransport); @@ -117,7 +125,7 @@ void QmlWebChannel::disconnectFrom(QObject *transport) } } -QQmlListProperty<QObject> QmlWebChannel::registeredObjects() +QQmlListProperty<QObject> QQmlWebChannel::registeredObjects() { return QQmlListProperty<QObject>(this, 0, registeredObjects_append, @@ -126,44 +134,44 @@ QQmlListProperty<QObject> QmlWebChannel::registeredObjects() registeredObjects_clear); } -void QmlWebChannel::registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *object) +void QQmlWebChannel::registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *object) { - const QmlWebChannelAttached *const attached = qobject_cast<QmlWebChannelAttached*>( - qmlAttachedPropertiesObject<QmlWebChannel>(object, false /* don't create */)); + const QQmlWebChannelAttached *const attached = qobject_cast<QQmlWebChannelAttached*>( + qmlAttachedPropertiesObject<QQmlWebChannel>(object, false /* don't create */)); if (!attached) { const QQmlContext *const context = qmlContext(object); qWarning() << "Cannot register object" << context->nameForObject(object) << '(' << object << ") without attached WebChannel.id property. Did you forget to set it?"; return; } - QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object); + QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object); if (!attached->id().isEmpty()) { // TODO: warning in such cases? channel->registerObject(attached->id(), object); } - channel->m_registeredObjects.append(object); - connect(attached, SIGNAL(idChanged(QString)), channel, SLOT(objectIdChanged(QString))); + channel->d_func()->registeredObjects.append(object); + connect(attached, SIGNAL(idChanged(QString)), channel, SLOT(_q_objectIdChanged(QString))); } -int QmlWebChannel::registeredObjects_count(QQmlListProperty<QObject> *prop) +int QQmlWebChannel::registeredObjects_count(QQmlListProperty<QObject> *prop) { - return static_cast<QmlWebChannel*>(prop->object)->m_registeredObjects.size(); + return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.size(); } -QObject *QmlWebChannel::registeredObjects_at(QQmlListProperty<QObject> *prop, int index) +QObject *QQmlWebChannel::registeredObjects_at(QQmlListProperty<QObject> *prop, int index) { - return static_cast<QmlWebChannel*>(prop->object)->m_registeredObjects.at(index); + return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.at(index); } -void QmlWebChannel::registeredObjects_clear(QQmlListProperty<QObject> *prop) +void QQmlWebChannel::registeredObjects_clear(QQmlListProperty<QObject> *prop) { - QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object); - foreach (QObject *object, channel->m_registeredObjects) { + QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object); + foreach (QObject *object, channel->d_func()->registeredObjects) { channel->deregisterObject(object); } - return channel->m_registeredObjects.clear(); + return channel->d_func()->registeredObjects.clear(); } -QQmlListProperty<QObject> QmlWebChannel::transports() +QQmlListProperty<QObject> QQmlWebChannel::transports() { return QQmlListProperty<QObject>(this, 0, transports_append, @@ -172,28 +180,32 @@ QQmlListProperty<QObject> QmlWebChannel::transports() transports_clear); } -void QmlWebChannel::transports_append(QQmlListProperty<QObject> *prop, QObject *transport) +void QQmlWebChannel::transports_append(QQmlListProperty<QObject> *prop, QObject *transport) { - QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object); + QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object); channel->connectTo(transport); } -int QmlWebChannel::transports_count(QQmlListProperty<QObject> *prop) +int QQmlWebChannel::transports_count(QQmlListProperty<QObject> *prop) { - return static_cast<QmlWebChannel*>(prop->object)->d->transports.size(); + return static_cast<QQmlWebChannel*>(prop->object)->d_func()->transports.size(); } -QObject *QmlWebChannel::transports_at(QQmlListProperty<QObject> *prop, int index) +QObject *QQmlWebChannel::transports_at(QQmlListProperty<QObject> *prop, int index) { - QmlWebChannel *channel = static_cast<QmlWebChannel*>(prop->object); - return dynamic_cast<QObject*>(channel->d->transports.at(index)); + QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object); + return channel->d_func()->transports.at(index); } -void QmlWebChannel::transports_clear(QQmlListProperty<QObject> *prop) +void QQmlWebChannel::transports_clear(QQmlListProperty<QObject> *prop) { QWebChannel *channel = static_cast<QWebChannel*>(prop->object); - foreach (QWebChannelAbstractTransport *transport, channel->d->transports) { + foreach (QWebChannelAbstractTransport *transport, channel->d_func()->transports) { channel->disconnectFrom(transport); } - Q_ASSERT(channel->d->transports.isEmpty()); + Q_ASSERT(channel->d_func()->transports.isEmpty()); } + +QT_END_NAMESPACE + +#include "moc_qqmlwebchannel.cpp" diff --git a/src/imports/webchannel/qmlwebchannel.h b/src/webchannel/qqmlwebchannel.h index 6bc7127..3bbd2a0 100644 --- a/src/imports/webchannel/qmlwebchannel.h +++ b/src/webchannel/qqmlwebchannel.h @@ -39,48 +39,45 @@ ** ****************************************************************************/ -#ifndef QMLWEBCHANNEL_H -#define QMLWEBCHANNEL_H +#ifndef QQMLWEBCHANNEL_H +#define QQMLWEBCHANNEL_H -#include <qwebchannel.h> - -#include "qmlwebchannelattached.h" - -#include <QVector> +#include <QtWebChannel/QWebChannel> +#include <QtWebChannel/qwebchannelglobal.h> #include <QtQml/qqml.h> #include <QtQml/QQmlListProperty> QT_BEGIN_NAMESPACE -class QmlWebChannel : public QWebChannel +class QQmlWebChannelPrivate; +class QQmlWebChannelAttached; +class Q_WEBCHANNEL_EXPORT QQmlWebChannel : public QWebChannel { Q_OBJECT + Q_DISABLE_COPY(QQmlWebChannel) Q_PROPERTY( QQmlListProperty<QObject> transports READ transports ); Q_PROPERTY( QQmlListProperty<QObject> registeredObjects READ registeredObjects ) public: - explicit QmlWebChannel(QObject *parent = 0); - virtual ~QmlWebChannel(); + explicit QQmlWebChannel(QObject *parent = 0); + virtual ~QQmlWebChannel(); Q_INVOKABLE void registerObjects(const QVariantMap &objects); QQmlListProperty<QObject> registeredObjects(); QQmlListProperty<QObject> transports(); - // TODO: remove this by replacing QML with C++ tests - Q_INVOKABLE bool test_clientIsIdle() const; - - static QmlWebChannelAttached *qmlAttachedProperties(QObject *obj); + static QQmlWebChannelAttached *qmlAttachedProperties(QObject *obj); Q_INVOKABLE void connectTo(QObject *transport); Q_INVOKABLE void disconnectFrom(QObject *transport); -private Q_SLOTS: - void objectIdChanged(const QString &newId); - private: + Q_DECLARE_PRIVATE(QQmlWebChannel) + Q_PRIVATE_SLOT(d_func(), void _q_objectIdChanged(const QString &newId)); + static void registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *item); static int registeredObjects_count(QQmlListProperty<QObject> *prop); static QObject *registeredObjects_at(QQmlListProperty<QObject> *prop, int index); @@ -90,13 +87,11 @@ private: static int transports_count(QQmlListProperty<QObject> *prop); static QObject *transports_at(QQmlListProperty<QObject> *prop, int index); static void transports_clear(QQmlListProperty<QObject> *prop); - - QVector<QObject*> m_registeredObjects; }; -QML_DECLARE_TYPE( QmlWebChannel ) -QML_DECLARE_TYPEINFO( QmlWebChannel, QML_HAS_ATTACHED_PROPERTIES ) +QML_DECLARE_TYPE( QQmlWebChannel ) +QML_DECLARE_TYPEINFO( QQmlWebChannel, QML_HAS_ATTACHED_PROPERTIES ) QT_END_NAMESPACE -#endif // QMLWEBCHANNEL_H +#endif // QQMLWEBCHANNEL_H diff --git a/src/imports/webchannel/qmlwebchannelattached.cpp b/src/webchannel/qqmlwebchannelattached.cpp index 637feb2..cfe03f8 100644 --- a/src/imports/webchannel/qmlwebchannelattached.cpp +++ b/src/webchannel/qqmlwebchannelattached.cpp @@ -39,27 +39,27 @@ ** ****************************************************************************/ -#include "qmlwebchannelattached.h" +#include "qqmlwebchannelattached_p.h" QT_USE_NAMESPACE -QmlWebChannelAttached::QmlWebChannelAttached(QObject *parent) +QQmlWebChannelAttached::QQmlWebChannelAttached(QObject *parent) : QObject(parent) { } -QmlWebChannelAttached::~QmlWebChannelAttached() +QQmlWebChannelAttached::~QQmlWebChannelAttached() { } -QString QmlWebChannelAttached::id() const +QString QQmlWebChannelAttached::id() const { return m_id; } -void QmlWebChannelAttached::setId(const QString &id) +void QQmlWebChannelAttached::setId(const QString &id) { if (id != m_id) { m_id = id; diff --git a/src/imports/webchannel/qmlwebchannelattached.h b/src/webchannel/qqmlwebchannelattached_p.h index 3d60122..09d18d3 100644 --- a/src/imports/webchannel/qmlwebchannelattached.h +++ b/src/webchannel/qqmlwebchannelattached_p.h @@ -39,21 +39,23 @@ ** ****************************************************************************/ -#ifndef QMLWEBCHANNELATTACHED_H -#define QMLWEBCHANNELATTACHED_H +#ifndef QQMLWEBCHANNELATTACHED_H +#define QQMLWEBCHANNELATTACHED_H #include <QObject> +#include "qwebchannelglobal.h" + QT_BEGIN_NAMESPACE -class QmlWebChannelAttached : public QObject +class Q_WEBCHANNEL_EXPORT QQmlWebChannelAttached : public QObject { Q_OBJECT Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged FINAL ) public: - explicit QmlWebChannelAttached(QObject *parent = 0); - virtual ~QmlWebChannelAttached(); + explicit QQmlWebChannelAttached(QObject *parent = 0); + virtual ~QQmlWebChannelAttached(); QString id() const; void setId(const QString &id); @@ -67,4 +69,4 @@ private: QT_END_NAMESPACE -#endif // QMLWEBCHANNELATTACHED_H +#endif // QQMLWEBCHANNELATTACHED_H diff --git a/src/webchannel/qwebchannel.cpp b/src/webchannel/qwebchannel.cpp index 651de58..d0b968e 100644 --- a/src/webchannel/qwebchannel.cpp +++ b/src/webchannel/qwebchannel.cpp @@ -72,13 +72,26 @@ void QWebChannelPrivate::_q_transportDestroyed(QObject *object) } } +void QWebChannelPrivate::init() +{ + Q_Q(QWebChannel); + publisher = new QMetaObjectPublisher(q); + QObject::connect(publisher, SIGNAL(blockUpdatesChanged(bool)), + q, SIGNAL(blockUpdatesChanged(bool))); +} + QWebChannel::QWebChannel(QObject *parent) -: QObject(parent) -, d(new QWebChannelPrivate) +: QObject(*(new QWebChannelPrivate), parent) +{ + Q_D(QWebChannel); + d->init(); +} + +QWebChannel::QWebChannel(QWebChannelPrivate &dd, QObject *parent) +: QObject(dd, parent) { - d->publisher = new QMetaObjectPublisher(this); - connect(d->publisher, SIGNAL(blockUpdatesChanged(bool)), - SIGNAL(blockUpdatesChanged(bool))); + Q_D(QWebChannel); + d->init(); } QWebChannel::~QWebChannel() @@ -87,6 +100,7 @@ QWebChannel::~QWebChannel() void QWebChannel::registerObjects(const QHash< QString, QObject * > &objects) { + Q_D(QWebChannel); const QHash<QString, QObject *>::const_iterator end = objects.constEnd(); for (QHash<QString, QObject *>::const_iterator it = objects.constBegin(); it != end; ++it) { d->publisher->registerObject(it.key(), it.value()); @@ -95,32 +109,38 @@ void QWebChannel::registerObjects(const QHash< QString, QObject * > &objects) QHash<QString, QObject *> QWebChannel::registeredObjects() const { + Q_D(const QWebChannel); return d->publisher->registeredObjects; } void QWebChannel::registerObject(const QString &id, QObject *object) { + Q_D(QWebChannel); d->publisher->registerObject(id, object); } void QWebChannel::deregisterObject(QObject *object) { + Q_D(QWebChannel); // handling of deregistration is analogously to handling of a destroyed signal d->publisher->signalEmitted(object, s_destroyedSignalIndex, QVariantList() << QVariant::fromValue(object)); } bool QWebChannel::blockUpdates() const { + Q_D(const QWebChannel); return d->publisher->blockUpdates; } void QWebChannel::setBlockUpdates(bool block) { + Q_D(QWebChannel); d->publisher->setBlockUpdates(block); } void QWebChannel::connectTo(QWebChannelAbstractTransport *transport) { + Q_D(QWebChannel); Q_ASSERT(transport); if (!d->transports.contains(transport)) { d->transports << transport; @@ -134,6 +154,7 @@ void QWebChannel::connectTo(QWebChannelAbstractTransport *transport) void QWebChannel::disconnectFrom(QWebChannelAbstractTransport *transport) { + Q_D(QWebChannel); const int idx = d->transports.indexOf(transport); if (idx != -1) { disconnect(transport, 0, this, 0); @@ -143,6 +164,7 @@ void QWebChannel::disconnectFrom(QWebChannelAbstractTransport *transport) void QWebChannel::sendMessage(const QJsonValue &id, const QJsonValue &data) const { + Q_D(const QWebChannel); if (d->transports.isEmpty()) { qWarning("QWebChannel is not connected to any transports, cannot send messages."); return; diff --git a/src/webchannel/qwebchannel.h b/src/webchannel/qwebchannel.h index 3e6f7a1..a4f34b4 100644 --- a/src/webchannel/qwebchannel.h +++ b/src/webchannel/qwebchannel.h @@ -90,20 +90,22 @@ public: */ void setBlockUpdates(bool block); - void connectTo(QWebChannelAbstractTransport *transport); - void disconnectFrom(QWebChannelAbstractTransport *transport); - Q_SIGNALS: void blockUpdatesChanged(bool block); public Q_SLOTS: + void connectTo(QWebChannelAbstractTransport *transport); + void disconnectFrom(QWebChannelAbstractTransport *transport); + void sendMessage(const QJsonValue &id, const QJsonValue &data = QJsonValue()) const; private: - QScopedPointer<QWebChannelPrivate> d; - Q_PRIVATE_SLOT(d, void _q_transportDestroyed(QObject*)); + Q_DECLARE_PRIVATE(QWebChannel) + QWebChannel(QWebChannelPrivate &dd, QObject *parent = 0); + Q_PRIVATE_SLOT(d_func(), void _q_transportDestroyed(QObject*)); + friend class QMetaObjectPublisher; - friend class QmlWebChannel; + friend class QQmlWebChannel; friend class TestWebChannel; }; diff --git a/src/webchannel/qwebchannel_p.h b/src/webchannel/qwebchannel_p.h index fbdf2ef..62b2cd5 100644 --- a/src/webchannel/qwebchannel_p.h +++ b/src/webchannel/qwebchannel_p.h @@ -44,6 +44,7 @@ #include "qwebchannelglobal.h" +#include <private/qobject_p.h> #include <QVector> QT_BEGIN_NAMESPACE @@ -54,11 +55,15 @@ class QMetaObjectPublisher; Q_WEBCHANNEL_EXPORT QByteArray generateJSONMessage(const QJsonValue &id, const QJsonValue &data, bool response); -struct Q_WEBCHANNEL_EXPORT QWebChannelPrivate +class Q_WEBCHANNEL_EXPORT QWebChannelPrivate : public QObjectPrivate { + Q_DECLARE_PUBLIC(QWebChannel) +public: QVector<QWebChannelAbstractTransport*> transports; QMetaObjectPublisher *publisher; + void init(); + void _q_transportDestroyed(QObject* object); }; diff --git a/src/webchannel/webchannel.pro b/src/webchannel/webchannel.pro index 82bd79f..d368237 100644 --- a/src/webchannel/webchannel.pro +++ b/src/webchannel/webchannel.pro @@ -1,5 +1,5 @@ TARGET = QtWebChannel -QT = core +QT = core-private CONFIG += warn_on strict_flags load(qt_module) @@ -28,6 +28,16 @@ SOURCES += \ qtHaveModule(qml) { QT += qml DEFINES += HAVE_QML=1 + + SOURCES += \ + qqmlwebchannel.cpp \ + qqmlwebchannelattached.cpp + + PUBLIC_HEADERS += \ + qqmlwebchannel.h + + PRIVATE_HEADERS += \ + qqmlwebchannelattached_p.h } HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 1d588ac..f912bf0 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -9,6 +9,10 @@ find_package(Qt5Core REQUIRED) include("${_Qt5CTestMacros}") +# Qt5Qml is an optional dependency of QWebChannel headers. Make sure we find it +# in the test. +set(Qt5_MODULE_TEST_DEPENDS Qml) + test_module_includes( WebChannel QWebChannel ) diff --git a/tests/auto/qml/Client.qml b/tests/auto/qml/Client.qml index 609fbac..2a47395 100644 --- a/tests/auto/qml/Client.qml +++ b/tests/auto/qml/Client.qml @@ -149,7 +149,7 @@ Item { verify(msg); verify(msg.data); compare(msg.data.type, Client.QWebChannelMessageTypes.idle); - verify(webChannel.test_clientIsIdle()) + verify(webChannel.clientIsIdle()) } function awaitMessageSkipIdle() diff --git a/tests/auto/qml/qml.cpp b/tests/auto/qml/qml.cpp index 0612bdb..9e3989c 100644 --- a/tests/auto/qml/qml.cpp +++ b/tests/auto/qml/qml.cpp @@ -47,10 +47,12 @@ #endif #include "testtransport.h" +#include "testwebchannel.h" int main(int argc, char **argv) { qmlRegisterType<TestTransport>("QtWebChannel.Tests", 1, 0, "TestTransport"); + qmlRegisterType<TestWebChannel>("QtWebChannel.Tests", 1, 0, "TestWebChannel"); return quick_test_main(argc, argv, "qml", QUICK_TEST_SOURCE_DIR); } diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index ddef2cb..b0c52b5 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -1,4 +1,4 @@ -QT += testlib webchannel +QT += testlib core-private webchannel-private TEMPLATE = app TARGET = qml @@ -9,10 +9,12 @@ IMPORTPATH += $$OUT_PWD/../../../qml $$PWD SOURCES += \ qml.cpp \ - testtransport.cpp + testtransport.cpp \ + testwebchannel.cpp HEADERS += \ - testtransport.h + testtransport.h \ + testwebchannel.h OTHER_FILES += \ WebChannelTest.qml \ diff --git a/tests/auto/qml/testwebchannel.cpp b/tests/auto/qml/testwebchannel.cpp new file mode 100644 index 0000000..2d31b87 --- /dev/null +++ b/tests/auto/qml/testwebchannel.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebChannel module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testwebchannel.h" + +#include <private/qwebchannel_p.h> +#include <private/qmetaobjectpublisher_p.h> + +QT_BEGIN_NAMESPACE + +TestWebChannel::TestWebChannel(QObject *parent) + : QQmlWebChannel(parent) +{ + +} + +TestWebChannel::~TestWebChannel() +{ + +} + +bool TestWebChannel::clientIsIdle() const +{ + return QWebChannel::d_func()->publisher->clientIsIdle; +} + +QT_END_NAMESPACE diff --git a/tests/auto/qml/testwebchannel.h b/tests/auto/qml/testwebchannel.h new file mode 100644 index 0000000..a172493 --- /dev/null +++ b/tests/auto/qml/testwebchannel.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebChannel module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef TESTWEBCHANNEL_H +#define TESTWEBCHANNEL_H + +#include <QtWebChannel/QQmlWebChannel> + +QT_BEGIN_NAMESPACE + +class TestWebChannel : public QQmlWebChannel +{ + Q_OBJECT + +public: + explicit TestWebChannel(QObject *parent = 0); + virtual ~TestWebChannel(); + + Q_INVOKABLE bool clientIsIdle() const; +}; + +QT_END_NAMESPACE + +#endif // TESTWEBCHANNEL_H diff --git a/tests/auto/qml/tst_bench.qml b/tests/auto/qml/tst_bench.qml index 833720e..e1354d7 100644 --- a/tests/auto/qml/tst_bench.qml +++ b/tests/auto/qml/tst_bench.qml @@ -43,6 +43,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebChannel 1.0 +import QtWebChannel.Tests 1.0 import "qrc:///qwebchannel/qwebchannel.js" as Client TestCase { @@ -53,7 +54,7 @@ TestCase { id: client } - WebChannel { + TestWebChannel { id: webChannel transports: [client.serverTransport] } diff --git a/tests/auto/qml/tst_metaobjectpublisher.qml b/tests/auto/qml/tst_metaobjectpublisher.qml index 880b30d..62b9866 100644 --- a/tests/auto/qml/tst_metaobjectpublisher.qml +++ b/tests/auto/qml/tst_metaobjectpublisher.qml @@ -43,6 +43,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebChannel 1.0 +import QtWebChannel.Tests 1.0 import "qrc:///qwebchannel/qwebchannel.js" as Client TestCase { @@ -95,7 +96,7 @@ TestCase { } } - WebChannel { + TestWebChannel { id: webChannel transports: [client.serverTransport] registeredObjects: [myObj, myOtherObj, myFactory] diff --git a/tests/auto/qml/tst_multiclient.qml b/tests/auto/qml/tst_multiclient.qml index 6c4b9b7..739ace7 100644 --- a/tests/auto/qml/tst_multiclient.qml +++ b/tests/auto/qml/tst_multiclient.qml @@ -43,6 +43,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebChannel 1.0 +import QtWebChannel.Tests 1.0 import "qrc:///qwebchannel/qwebchannel.js" as Client TestCase { @@ -70,7 +71,7 @@ TestCase { WebChannel.id: "foo" } - WebChannel { + TestWebChannel { id: webChannel transports: [client1.serverTransport, client2.serverTransport] registeredObjects: [foo] diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml index 3c404d3..0443802 100644 --- a/tests/auto/qml/tst_webchannel.qml +++ b/tests/auto/qml/tst_webchannel.qml @@ -43,6 +43,7 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebChannel 1.0 +import QtWebChannel.Tests 1.0 import "qrc:///qwebchannel/qwebchannel.js" as Client TestCase { @@ -52,7 +53,7 @@ TestCase { id: client } - WebChannel { + TestWebChannel { id: webChannel transports: [client.serverTransport] } diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 10baaa3..632d055 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -83,7 +83,7 @@ void TestWebChannel::testRegisterObjects() QHash<QString, QObject*> objects; objects[QStringLiteral("plain")] = &plain; objects[QStringLiteral("channel")] = &channel; - objects[QStringLiteral("publisher")] = channel.d->publisher; + objects[QStringLiteral("publisher")] = channel.d_func()->publisher; objects[QStringLiteral("test")] = this; channel.registerObjects(objects); @@ -95,7 +95,7 @@ void TestWebChannel::testInfoForObject() obj.setObjectName("myTestObject"); QWebChannel channel; - const QJsonObject info = channel.d->publisher->classInfoForObject(&obj); + const QJsonObject info = channel.d_func()->publisher->classInfoForObject(&obj); QCOMPARE(info.keys(), QStringList() << "enums" << "methods" << "properties" << "signals"); @@ -227,19 +227,19 @@ void TestWebChannel::testInvokeMethodConversion() { int method = metaObject()->indexOfMethod("setInt(int)"); QVERIFY(method != -1); - QVERIFY(!channel.d->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); + QVERIFY(!channel.d_func()->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); QCOMPARE(m_lastInt, args.at(0).toInt()); } { int method = metaObject()->indexOfMethod("setDouble(double)"); QVERIFY(method != -1); - QVERIFY(!channel.d->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); + QVERIFY(!channel.d_func()->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); QCOMPARE(m_lastDouble, args.at(0).toDouble()); } { int method = metaObject()->indexOfMethod("setVariant(QVariant)"); QVERIFY(method != -1); - QVERIFY(!channel.d->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); + QVERIFY(!channel.d_func()->publisher->invokeMethod(this, method, args, QJsonValue()).isEmpty()); QCOMPARE(m_lastVariant, args.at(0).toVariant()); } } @@ -265,7 +265,7 @@ void TestWebChannel::benchClassInfo() QBENCHMARK { foreach (const QObject *object, objects) { - channel.d->publisher->classInfoForObject(object); + channel.d_func()->publisher->classInfoForObject(object); } } } @@ -278,7 +278,7 @@ void TestWebChannel::benchInitializeClients() QObject parent; channel.registerObjects(createObjects(&parent)); - QMetaObjectPublisher *publisher = channel.d->publisher; + QMetaObjectPublisher *publisher = channel.d_func()->publisher; QBENCHMARK { publisher->initializeClients(); @@ -302,15 +302,15 @@ void TestWebChannel::benchPropertyUpdates() } channel.registerObjects(objects); - channel.d->publisher->initializeClients(); + channel.d_func()->publisher->initializeClients(); QBENCHMARK { foreach (BenchObject *obj, objectList) { obj->change(); } - channel.d->publisher->clientIsIdle = true; - channel.d->publisher->sendPendingPropertyUpdates(); + channel.d_func()->publisher->clientIsIdle = true; + channel.d_func()->publisher->sendPendingPropertyUpdates(); } } diff --git a/tests/auto/webchannel/webchannel.pro b/tests/auto/webchannel/webchannel.pro index 71036dd..40b324e 100644 --- a/tests/auto/webchannel/webchannel.pro +++ b/tests/auto/webchannel/webchannel.pro @@ -1,4 +1,4 @@ -QT = core webchannel-private testlib +QT = core-private webchannel-private testlib CONFIG += testcase strict_flags warn_on |