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
QtQuickViewContent.java
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
4package org.qtproject.qt.android;
5
6import android.util.Log;
7import java.lang.ref.WeakReference;
8import java.util.HashMap;
9import java.util.HashSet;
10import java.util.Random;
11
20public abstract class QtQuickViewContent
21{
22 private final static String TAG = "QtQuickViewContent";
23
24 private WeakReference<QtQuickView> m_viewReference;
25 private QtQmlStatusChangeListener m_statusChangeListener = null;
26 private HashSet<Integer> m_signalListenerIds = new HashSet<>();
27 private QtSignalQueue m_signalQueue = new QtSignalQueue();
28
32 public abstract String getLibraryName();
36 public abstract String getModuleName();
40 public abstract String getFilePath();
41
48 {
49 m_statusChangeListener = listener;
51 if (view != null)
52 view.setStatusChangeListener(listener);
53 }
54
62 {
63 if (m_viewReference != null)
64 return m_viewReference.get();
65 return null;
66 }
67
73 protected boolean isViewAttached() { return getQuickView() != null; }
74
78 protected void attachView(QtQuickView view)
79 {
80 m_viewReference = new WeakReference<>(view);
81 if (view != null) {
82 view.setStatusChangeListener(m_statusChangeListener);
83 m_signalQueue.connectQueuedSignalListeners(view);
84 }
85 }
86
91 protected void detachView()
92 {
94 if (view != null) {
95 for (int signalListenerId : m_signalListenerIds)
96 view.disconnectSignalListener(signalListenerId);
97
98 view.setStatusChangeListener(null);
99 m_viewReference.clear();
100 if (m_statusChangeListener != null)
101 m_statusChangeListener.onStatusChanged(QtQmlStatus.NULL);
102 }
103 }
104
109 protected HashMap<String, Object> attributes() { return new HashMap<>(); }
110
127 protected void setProperty(String propertyName, Object value)
128 {
130 if (view == null) {
131 Log.w(TAG, "Cannot set property as the QQmlComponent is not loaded in a QtQuickView.");
132 return;
133 }
134 view.setProperty(propertyName, value);
135 }
136
153 protected <T> T getProperty(String propertyName)
154 {
156 if (view == null) {
157 Log.w(TAG, "Cannot get property as the QQmlComponent is not loaded in a QtQuickView.");
158 return null;
159 }
160 return view.<T>getProperty(propertyName);
161 }
162
176 protected <T> int connectSignalListener(String signalName, Class<T> argType,
177 QtSignalListener<T> listener)
178 {
179 return connectSignalListener(signalName, new Class<?>[] { argType }, listener);
180 }
181
195 protected int connectSignalListener(String signalName, Class<?>[] argTypes, Object listener)
196 {
197 final int id = QtQuickViewContent.generateSignalId();
198 if (isViewAttached()) {
200 view.connectSignalListener(signalName, argTypes, listener, id);
201 m_signalListenerIds.add(id);
202 } else {
203 m_signalQueue.add(signalName, argTypes, listener, id);
204 }
205 return id;
206 }
207
218 public boolean disconnectSignalListener(int signalListenerId)
219 {
220 if (isViewAttached()) {
222 m_signalListenerIds.remove(signalListenerId);
223 return view.disconnectSignalListener(signalListenerId);
224 } else {
225 return m_signalQueue.remove(signalListenerId);
226 }
227 }
228
229 static int generateSignalId()
230 {
231 Random rand = new Random();
232 return rand.nextInt();
233 }
234
254 {
256 if (view != null) {
257 view.invokeMethod(name, params);
258 } else {
259 Log.w(TAG,
260 "Cannot call method " + name +
261 " as the QQmlComponent is not loaded in a QtQuickView.");
262 }
263 }
264
273 {
275 if (view != null) {
276 view.invokeMethod(name);
277 } else {
278 Log.w(TAG,
279 "Cannot call method " + name +
280 " as the QQmlComponent is not loaded in a QtQuickView.");
281 }
282 }
283}
int connectSignalListener(String signalName, Class<?>[] argTypes, Object listener)
void setStatusChangeListener(QtQmlStatusChangeListener listener)
boolean disconnectSignalListener(int signalListenerId)
void invokeMethod(String name, Object[] params)
void setProperty(String propertyName, Object value)
[vector_of_multirole_objects_0]
Definition main.cpp:188
EGLOutputLayerEXT EGLint EGLAttrib value
[3]
#define TAG(x)
GLenum GLuint id
void ** params
static const char * signalName(int signum) noexcept
EGLImageKHR EGLint * name
QQuickView * view
[0]