Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QtQmlComponent.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;
10
19public abstract class QtQmlComponent
20{
21 private final static String TAG = "QtQmlComponent";
22
23 private WeakReference<QtQuickView> m_viewReference;
24 private QtQmlStatusChangeListener m_statusChangeListener = null;
25 private HashSet<Integer> m_signalListenerIds = new HashSet<>();
26
30 protected abstract String getLibraryName();
34 protected abstract String getModuleName();
38 protected abstract String getFilePath();
39
46 {
47 m_statusChangeListener = listener;
49 if (view != null)
50 view.setStatusChangeListener(listener);
51 }
52
60 {
61 if (m_viewReference != null)
62 return m_viewReference.get();
63 return null;
64 }
65
71 protected boolean isViewAttached() { return getQuickView() != null; }
72
76 protected void attachView(QtQuickView view)
77 {
78 m_viewReference = new WeakReference<>(view);
79 if (view != null)
80 view.setStatusChangeListener(m_statusChangeListener);
81 }
82
87 protected void detachView()
88 {
90 if (view != null) {
91 for (int signalListenerId : m_signalListenerIds)
92 view.disconnectSignalListener(signalListenerId);
93
94 view.setStatusChangeListener(null);
95 m_viewReference.clear();
96 if (m_statusChangeListener != null)
97 m_statusChangeListener.onStatusChanged(QtQmlStatus.NULL);
98 }
99 }
100
105 protected HashMap<String, Object> attributes() { return new HashMap<>(); }
106
123 protected void setProperty(String propertyName, Object value)
124 {
126 if (view == null) {
127 Log.w(TAG, "Cannot set property as the QQmlComponent is not loaded in a QtQuickView.");
128 return;
129 }
130 view.setProperty(propertyName, value);
131 }
132
149 protected <T> T getProperty(String propertyName)
150 {
152 if (view == null) {
153 Log.w(TAG, "Cannot get property as the QQmlComponent is not loaded in a QtQuickView.");
154 return null;
155 }
156 return view.<T>getProperty(propertyName);
157 }
158
170 protected <T> int connectSignalListener(String signalName, Class<T> argType,
171 QtSignalListener<T> listener)
172 {
173 QtQuickView view = getQuickView();
174 if (view == null) {
175 Log.w(TAG,
176 "Cannot connect signal listener as the QQmlComponent is not loaded in a "
177 + "QtQuickView.");
178 return -1;
179 }
180 int signalListenerId = view.connectSignalListener(signalName, argType, listener);
181 m_signalListenerIds.add(signalListenerId);
182 return signalListenerId;
183 }
184
194 public boolean disconnectSignalListener(int signalListenerId)
195 {
197 if (view == null) {
198 Log.w(TAG,
199 "Cannot disconnect signal listener as the QQmlComponent is not loaded in a "
200 + "QtQuickView.");
201 return false;
202 }
203 m_signalListenerIds.remove(signalListenerId);
204 return view.disconnectSignalListener(signalListenerId);
205 }
206}
Definition main.cpp:8
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
HashMap< String, Object > attributes()
void setStatusChangeListener(QtQmlStatusChangeListener listener)
boolean disconnectSignalListener(int signalListenerId)
void setProperty(String propertyName, Object value)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define TAG(x)
QQuickView * view
[0]