diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2014-07-03 19:17:02 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2014-07-15 11:31:48 +0200 |
commit | 003596fad52690127afca0d7025b62bad7fd013e (patch) | |
tree | 7b68f95ce3a519018b309990f85bf7e044307fe9 /src/webchannel/qwebchannel.cpp | |
parent | 125c5f7dc270ab58e5f876cf8bc8aaf56d9e8f1b (diff) | |
download | qtwebchannel-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/qwebchannel.cpp')
-rw-r--r-- | src/webchannel/qwebchannel.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
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; |