Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qandroidviewsignalmanager_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QANDROIDVIEWSIGNALMANAGER_P_H
5#define QANDROIDVIEWSIGNALMANAGER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qhash.h>
19#include <QtCore/qjnitypes.h>
20#include <QtCore/qjniobject.h>
21#include <QtCore/qmap.h>
22#include <QtCore/qobject.h>
23#include <QtCore/qmutex.h>
24#include <QtQuick/qquickview.h>
25
26QT_BEGIN_NAMESPACE
27
28class QAndroidViewSignalManager : public QObject
29{
30 using connection_key_t = int;
31
32public:
33 explicit QAndroidViewSignalManager(QQuickView *view, QObject *parent = nullptr);
34
35 int qt_metacall(QMetaObject::Call call, int methodId, void **args) override;
36
37 void removeConnection(connection_key_t signalIdx);
38 bool addConnection(const QString &signalName,
39 const QJniArray<jclass> &argTypes,
40 const QJniObject &listener,
41 int id);
42
43private:
44 /*
45 This will store the necessary information to call the listener
46 when the signal is emitted, including the Java function name and
47 signature so that we can call it quickly without recalculating those.
48 */
49 struct ConnectionInfo
50 {
51 QMetaObject::Connection connection;
52 QJniObject listenerObject;
53 QString qmlSignalName;
54
55 QList<QMetaType::Type> qmlArgumentTypes;
56 bool isPropertySignal;
57 std::optional<int> qmlPropertyIndex; // Only filled if isPropertySignal
58 int connectionId;
59 };
60
61 struct QueuedConnectionInfo
62 {
63 connection_key_t id;
64 QString signalName;
65 QJniArray<jclass> argTypes;
66 QJniObject listener;
67 };
68
69 bool hasConnection(connection_key_t key) const;
70 connection_key_t createNewSignalKey() const;
71 void onViewStatusChanged(QQuickView::Status status);
72 bool queueConnection(const QString &signalName,
73 const QJniArray<jclass> &argTypes,
74 const QJniObject &listener,
75 int id);
76
77 QMap<connection_key_t, ConnectionInfo> m_connections;
78 QQuickView *m_view;
79 QVector<QueuedConnectionInfo> m_queuedConnections;
80 QMutex m_queueMutex;
81};
82
84
85#endif // QANDROIDVIEWSIGNALMANAGER_P_H
QObject * parent
Definition qobject.h:73
The QQuickView class provides a window for displaying a Qt Quick user interface.
Definition qquickview.h:21
QJniObject qVariantToQJniObject(const QVariant &data)
std::optional< int > propertyIndexForSignal(const QMetaMethod &signal, const QMetaObject &object)
QByteArray qmlSignalSignature(const QString &signalName, const QJniArray< jclass > &javaArgClasses)
QList< QMetaType::Type > metaMethodArgumentTypes(const QMetaMethod &method)
int indexOfSignal(const QMetaObject &metaObject, const QString &signalName, const QJniArray< jclass > &javaArgClasses)
QByteArray qmlTypeArgStringFromJavaTypeArgs(const QJniArray< jclass > &javaArgClasses)
QJniObject voidStarToQJniObject(const QMetaType::Type type, const void *data)