diff options
author | Michal Klocek <michal.klocek@qt.io> | 2023-02-02 08:43:05 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2023-02-03 13:37:42 +0100 |
commit | 48d2066d6c9b38f29368e5205a5b7f49ab3fa857 (patch) | |
tree | c40f1f840b7450248e1a0549c0caa75b6d536dd9 /src/webchannelquick/qqmlwebchannel.h | |
parent | 165ecd37b44e6c96c0e85afc5ea4a1bc392e035e (diff) | |
download | qtwebchannel-48d2066d6c9b38f29368e5205a5b7f49ab3fa857.tar.gz |
Fix project structure and auto registry
Create QtWebChannelQuick and move the required sources,
so auto registry works and qml types files and friends
are auto generated. This makes things inline what other
modules do.
This change has a side effect as qqmlwebchannel.h
will change its module, however this is semi-pulibc
header, hopefully only used by QtWebEngine.
[ChangeLog] Created new QtWebChannelQuick which holds
qml sources.
Task-number: QTBUG-110795
Fixes: QTBUG-99959
Change-Id: Ic8aa72f070d6a9e23d918a1210f4df62df739397
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/webchannelquick/qqmlwebchannel.h')
-rw-r--r-- | src/webchannelquick/qqmlwebchannel.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/webchannelquick/qqmlwebchannel.h b/src/webchannelquick/qqmlwebchannel.h new file mode 100644 index 0000000..292ea6c --- /dev/null +++ b/src/webchannelquick/qqmlwebchannel.h @@ -0,0 +1,62 @@ +// Copyright (C) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author +// Milian Wolff <milian.wolff@kdab.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QQMLWEBCHANNEL_H +#define QQMLWEBCHANNEL_H + +#include <QtWebChannelQuick/qwebchannelquickglobal.h> +#include <QtWebChannel/qwebchannel.h> + +#include <QtQml/qqml.h> +#include <QtQml/QQmlListProperty> + +QT_BEGIN_NAMESPACE + +class QQmlWebChannelPrivate; +class QQmlWebChannelAttached; +class Q_WEBCHANNELQUICK_EXPORT QQmlWebChannel : public QWebChannel +{ + Q_OBJECT + Q_DISABLE_COPY(QQmlWebChannel) + + Q_PROPERTY(QQmlListProperty<QObject> transports READ transports) + Q_PROPERTY(QQmlListProperty<QObject> registeredObjects READ registeredObjects) + QML_NAMED_ELEMENT(WebChannel) + QML_ATTACHED(QQmlWebChannelAttached) + QML_ADDED_IN_VERSION(1, 0) +public: + explicit QQmlWebChannel(QObject *parent = nullptr); + 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 qsizetype registeredObjects_count(QQmlListProperty<QObject> *prop); + static QObject *registeredObjects_at(QQmlListProperty<QObject> *prop, qsizetype index); + static void registeredObjects_clear(QQmlListProperty<QObject> *prop); + + static void transports_append(QQmlListProperty<QObject> *prop, QObject *item); + static qsizetype transports_count(QQmlListProperty<QObject> *prop); + static QObject *transports_at(QQmlListProperty<QObject> *prop, qsizetype index); + static void transports_clear(QQmlListProperty<QObject> *prop); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QQmlWebChannel) +QML_DECLARE_TYPEINFO(QQmlWebChannel, QML_HAS_ATTACHED_PROPERTIES) + +#endif // QQMLWEBCHANNEL_H |