summaryrefslogtreecommitdiff
path: root/src/webchannel
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-07-03 19:17:02 +0200
committerMilian Wolff <milian.wolff@kdab.com>2014-07-15 11:31:48 +0200
commit003596fad52690127afca0d7025b62bad7fd013e (patch)
tree7b68f95ce3a519018b309990f85bf7e044307fe9 /src/webchannel
parent125c5f7dc270ab58e5f876cf8bc8aaf56d9e8f1b (diff)
downloadqtwebchannel-003596fad52690127afca0d7025b62bad7fd013e.tar.gz
Make the QWebChannel QML API publically accessible.
This is required for proper QtWebKit/QtWebEngine integration, as otherwise these modules would have to redo a lot of the QtWebChannel QML API. Furthermore, without this, we could not use the WebChannel.id attached property everywhere, independent of the web browser technology. Change-Id: I032a9326841d505c2f77959a240bbfc71e94b6e8 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/webchannel')
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp2
-rw-r--r--src/webchannel/qmetaobjectpublisher_p.h2
-rw-r--r--src/webchannel/qqmlwebchannel.cpp211
-rw-r--r--src/webchannel/qqmlwebchannel.h97
-rw-r--r--src/webchannel/qqmlwebchannelattached.cpp68
-rw-r--r--src/webchannel/qqmlwebchannelattached_p.h72
-rw-r--r--src/webchannel/qwebchannel.cpp32
-rw-r--r--src/webchannel/qwebchannel.h14
-rw-r--r--src/webchannel/qwebchannel_p.h7
-rw-r--r--src/webchannel/webchannel.pro12
10 files changed, 502 insertions, 15 deletions
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/webchannel/qqmlwebchannel.cpp b/src/webchannel/qqmlwebchannel.cpp
new file mode 100644
index 0000000..ca99fe5
--- /dev/null
+++ b/src/webchannel/qqmlwebchannel.cpp
@@ -0,0 +1,211 @@
+/****************************************************************************
+**
+** 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 "qqmlwebchannel.h"
+
+#include "qwebchannel_p.h"
+#include "qmetaobjectpublisher_p.h"
+#include "qwebchannelabstracttransport.h"
+
+#include <QtQml/QQmlContext>
+
+#include "qqmlwebchannelattached_p.h"
+
+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)
+{
+}
+
+QQmlWebChannel::~QQmlWebChannel()
+{
+
+}
+
+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*>();
+ if (!object) {
+ qWarning("Invalid QObject given to register under name %s", qPrintable(it.key()));
+ continue;
+ }
+ d->publisher->registerObject(it.key(), object);
+ }
+}
+
+QQmlWebChannelAttached *QQmlWebChannel::qmlAttachedProperties(QObject *obj)
+{
+ return new QQmlWebChannelAttached(obj);
+}
+
+void QQmlWebChannel::connectTo(QObject *transport)
+{
+ if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
+ QWebChannel::connectTo(realTransport);
+ } else {
+ qWarning() << "Cannot connect to transport" << transport << " - it is not a QWebChannelAbstractTransport.";
+ }
+}
+
+void QQmlWebChannel::disconnectFrom(QObject *transport)
+{
+ if (QWebChannelAbstractTransport *realTransport = qobject_cast<QWebChannelAbstractTransport*>(transport)) {
+ QWebChannel::disconnectFrom(realTransport);
+ } else {
+ qWarning() << "Cannot disconnect from transport" << transport << " - it is not a QWebChannelAbstractTransport.";
+ }
+}
+
+QQmlListProperty<QObject> QQmlWebChannel::registeredObjects()
+{
+ return QQmlListProperty<QObject>(this, 0,
+ registeredObjects_append,
+ registeredObjects_count,
+ registeredObjects_at,
+ registeredObjects_clear);
+}
+
+void QQmlWebChannel::registeredObjects_append(QQmlListProperty<QObject> *prop, QObject *object)
+{
+ 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;
+ }
+ QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
+ if (!attached->id().isEmpty()) {
+ // TODO: warning in such cases?
+ channel->registerObject(attached->id(), object);
+ }
+ channel->d_func()->registeredObjects.append(object);
+ connect(attached, SIGNAL(idChanged(QString)), channel, SLOT(_q_objectIdChanged(QString)));
+}
+
+int QQmlWebChannel::registeredObjects_count(QQmlListProperty<QObject> *prop)
+{
+ return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.size();
+}
+
+QObject *QQmlWebChannel::registeredObjects_at(QQmlListProperty<QObject> *prop, int index)
+{
+ return static_cast<QQmlWebChannel*>(prop->object)->d_func()->registeredObjects.at(index);
+}
+
+void QQmlWebChannel::registeredObjects_clear(QQmlListProperty<QObject> *prop)
+{
+ QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
+ foreach (QObject *object, channel->d_func()->registeredObjects) {
+ channel->deregisterObject(object);
+ }
+ return channel->d_func()->registeredObjects.clear();
+}
+
+QQmlListProperty<QObject> QQmlWebChannel::transports()
+{
+ return QQmlListProperty<QObject>(this, 0,
+ transports_append,
+ transports_count,
+ transports_at,
+ transports_clear);
+}
+
+void QQmlWebChannel::transports_append(QQmlListProperty<QObject> *prop, QObject *transport)
+{
+ QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
+ channel->connectTo(transport);
+}
+
+int QQmlWebChannel::transports_count(QQmlListProperty<QObject> *prop)
+{
+ return static_cast<QQmlWebChannel*>(prop->object)->d_func()->transports.size();
+}
+
+QObject *QQmlWebChannel::transports_at(QQmlListProperty<QObject> *prop, int index)
+{
+ QQmlWebChannel *channel = static_cast<QQmlWebChannel*>(prop->object);
+ return channel->d_func()->transports.at(index);
+}
+
+void QQmlWebChannel::transports_clear(QQmlListProperty<QObject> *prop)
+{
+ QWebChannel *channel = static_cast<QWebChannel*>(prop->object);
+ foreach (QWebChannelAbstractTransport *transport, channel->d_func()->transports) {
+ channel->disconnectFrom(transport);
+ }
+ Q_ASSERT(channel->d_func()->transports.isEmpty());
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qqmlwebchannel.cpp"
diff --git a/src/webchannel/qqmlwebchannel.h b/src/webchannel/qqmlwebchannel.h
new file mode 100644
index 0000000..3bbd2a0
--- /dev/null
+++ b/src/webchannel/qqmlwebchannel.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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 QQMLWEBCHANNEL_H
+#define QQMLWEBCHANNEL_H
+
+#include <QtWebChannel/QWebChannel>
+#include <QtWebChannel/qwebchannelglobal.h>
+
+#include <QtQml/qqml.h>
+#include <QtQml/QQmlListProperty>
+
+QT_BEGIN_NAMESPACE
+
+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 QQmlWebChannel(QObject *parent = 0);
+ virtual ~QQmlWebChannel();
+
+ Q_INVOKABLE void registerObjects(const QVariantMap &objects);
+ QQmlListProperty<QObject> registeredObjects();
+
+ QQmlListProperty<QObject> transports();
+
+ static QQmlWebChannelAttached *qmlAttachedProperties(QObject *obj);
+
+ Q_INVOKABLE void connectTo(QObject *transport);
+ Q_INVOKABLE void disconnectFrom(QObject *transport);
+
+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);
+ static void registeredObjects_clear(QQmlListProperty<QObject> *prop);
+
+ static void transports_append(QQmlListProperty<QObject> *prop, QObject *item);
+ static int transports_count(QQmlListProperty<QObject> *prop);
+ static QObject *transports_at(QQmlListProperty<QObject> *prop, int index);
+ static void transports_clear(QQmlListProperty<QObject> *prop);
+};
+
+QML_DECLARE_TYPE( QQmlWebChannel )
+QML_DECLARE_TYPEINFO( QQmlWebChannel, QML_HAS_ATTACHED_PROPERTIES )
+
+QT_END_NAMESPACE
+
+#endif // QQMLWEBCHANNEL_H
diff --git a/src/webchannel/qqmlwebchannelattached.cpp b/src/webchannel/qqmlwebchannelattached.cpp
new file mode 100644
index 0000000..cfe03f8
--- /dev/null
+++ b/src/webchannel/qqmlwebchannelattached.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** 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 "qqmlwebchannelattached_p.h"
+
+QT_USE_NAMESPACE
+
+QQmlWebChannelAttached::QQmlWebChannelAttached(QObject *parent)
+ : QObject(parent)
+{
+
+}
+
+QQmlWebChannelAttached::~QQmlWebChannelAttached()
+{
+
+}
+
+QString QQmlWebChannelAttached::id() const
+{
+ return m_id;
+}
+
+void QQmlWebChannelAttached::setId(const QString &id)
+{
+ if (id != m_id) {
+ m_id = id;
+ emit idChanged(id);
+ }
+}
diff --git a/src/webchannel/qqmlwebchannelattached_p.h b/src/webchannel/qqmlwebchannelattached_p.h
new file mode 100644
index 0000000..09d18d3
--- /dev/null
+++ b/src/webchannel/qqmlwebchannelattached_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** 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 QQMLWEBCHANNELATTACHED_H
+#define QQMLWEBCHANNELATTACHED_H
+
+#include <QObject>
+
+#include "qwebchannelglobal.h"
+
+QT_BEGIN_NAMESPACE
+
+class Q_WEBCHANNEL_EXPORT QQmlWebChannelAttached : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY( QString id READ id WRITE setId NOTIFY idChanged FINAL )
+public:
+ explicit QQmlWebChannelAttached(QObject *parent = 0);
+ virtual ~QQmlWebChannelAttached();
+
+ QString id() const;
+ void setId(const QString &id);
+
+Q_SIGNALS:
+ void idChanged(const QString &id);
+
+private:
+ QString m_id;
+};
+
+QT_END_NAMESPACE
+
+#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