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.concurrent.atomic.AtomicInteger;
11
20public abstract class QtQuickViewContent
21{
22 private final static String TAG = "QtQuickViewContent";
23 private static AtomicInteger m_nextSignalId = new AtomicInteger();
24
25 private WeakReference<QtQuickView> m_viewReference;
26 private QtQmlStatusChangeListener m_statusChangeListener = null;
27 private HashSet<Integer> m_signalListenerIds = new HashSet<>();
28 private QtSignalQueue m_signalQueue = new QtSignalQueue();
29
33 public abstract String getLibraryName();
37 public abstract String getModuleName();
41 public abstract String getFilePath();
42
49 {
50 m_statusChangeListener = listener;
52 if (view != null)
53 view.setStatusChangeListener(listener);
54 }
55
63 {
64 if (m_viewReference != null)
65 return m_viewReference.get();
66 return null;
67 }
68
74 protected boolean isViewAttached() { return getQuickView() != null; }
75
79 protected void attachView(QtQuickView view)
80 {
81 m_viewReference = new WeakReference<>(view);
82 if (view != null) {
83 view.setStatusChangeListener(m_statusChangeListener);
84 m_signalQueue.connectQueuedSignalListeners(view);
85 }
86 }
87
92 protected void detachView()
93 {
95 if (view != null) {
96 for (int signalListenerId : m_signalListenerIds)
97 view.disconnectSignalListener(signalListenerId);
98
99 view.setStatusChangeListener(null);
100 m_viewReference.clear();
101 if (m_statusChangeListener != null)
102 m_statusChangeListener.onStatusChanged(QtQmlStatus.NULL);
103 }
104 }
105
110 protected HashMap<String, Object> attributes() { return new HashMap<>(); }
111
128 protected void setProperty(String propertyName, Object value)
129 {
131 if (view == null) {
132 Log.w(TAG, "Cannot set property as the QQmlComponent is not loaded in a QtQuickView.");
133 return;
134 }
135 view.setProperty(propertyName, value);
136 }
137
154 protected <T> T getProperty(String propertyName)
155 {
157 if (view == null) {
158 Log.w(TAG, "Cannot get property as the QQmlComponent is not loaded in a QtQuickView.");
159 return null;
160 }
161 return view.<T>getProperty(propertyName);
162 }
163
177 protected <T> int connectSignalListener(String signalName, Class<T> argType,
178 QtSignalListener<T> listener)
179 {
180 return connectSignalListener(signalName, new Class<?>[] { argType }, listener);
181 }
182
196 protected int connectSignalListener(String signalName, Class<?>[] argTypes, Object listener)
197 {
198 final int id = QtQuickViewContent.generateSignalId();
199 if (isViewAttached()) {
201 view.connectSignalListener(signalName, argTypes, listener, id);
202 m_signalListenerIds.add(id);
203 } else {
204 m_signalQueue.add(signalName, argTypes, listener, id);
205 }
206 return id;
207 }
208
219 public boolean disconnectSignalListener(int signalListenerId)
220 {
221 if (isViewAttached()) {
223 m_signalListenerIds.remove(signalListenerId);
224 return view.disconnectSignalListener(signalListenerId);
225 } else {
226 return m_signalQueue.remove(signalListenerId);
227 }
228 }
229
230 static int generateSignalId()
231 {
232 return m_nextSignalId.getAndIncrement();
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]