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
181 protected <T> int connectSignalListener(String signalName, Class<T> argType,
182 QtSignalListener<T> listener)
183 {
184 return connectSignalListener(signalName, new Class<?>[] { argType }, listener);
185 }
186
204 protected int connectSignalListener(String signalName, Class<?>[] argTypes, Object listener)
205 {
206 final int id = QtQuickViewContent.generateSignalId();
207 if (isViewAttached()) {
209 if (!view.connectSignalListener(signalName, argTypes, listener, id))
210 return -1;
211 m_signalListenerIds.add(id);
212 } else {
213 m_signalQueue.add(signalName, argTypes, listener, id);
214 }
215 return id;
216 }
217
228 public boolean disconnectSignalListener(int signalListenerId)
229 {
230 if (isViewAttached()) {
232 m_signalListenerIds.remove(signalListenerId);
233 return view.disconnectSignalListener(signalListenerId);
234 } else {
235 return m_signalQueue.remove(signalListenerId);
236 }
237 }
238
239 static int generateSignalId()
240 {
241 return m_nextSignalId.getAndIncrement();
242 }
243
263 {
265 if (view != null) {
266 view.invokeMethod(name, params);
267 } else {
268 Log.w(TAG,
269 "Cannot call method " + name +
270 " as the QQmlComponent is not loaded in a QtQuickView.");
271 }
272 }
273
282 {
284 if (view != null) {
285 view.invokeMethod(name);
286 } else {
287 Log.w(TAG,
288 "Cannot call method " + name +
289 " as the QQmlComponent is not loaded in a QtQuickView.");
290 }
291 }
292}
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)
GLvoid ** params
GLenum GLuint id
static const char * signalName(int signum) noexcept
EGLImageKHR EGLint * name
QQuickView * view
[0]