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
qohosjswindowregistry.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 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#include <qohosplugincore.h>
5#include <qohosutils.h>
6#include <render/qohosjswindowregistry.h>
7#include <tuple>
8
10
11QOhosJsWindowRegistry &QOhosJsWindowRegistry::instance(QOhosJsState &jsState)
12{
13 return QtOhos::JsState::castFrom(jsState).getAttachedObjectWithLazyCreate<QOhosJsWindowRegistry>();
14}
15
17
18std::shared_ptr<void> QOhosJsWindowRegistry::registerJsWindow(std::shared_ptr<QArkUi::JsWindowRef> jsWindowRef)
19{
20 auto jsWindowId = jsWindowRef->id();
21
22 bool added = false;
23 std::tie(std::ignore, added) = m_windowRefs.insert({jsWindowRef->id(), jsWindowRef});
24 if (!added) {
25 qOhosReportFatalErrorAndAbort(
26 "%s: Duplicate jsWindow with id: %f", Q_FUNC_INFO, jsWindowId.value());
27 }
28
29 return QtOhos::makeProxyWithJsThreadDeleter(
30 QtOhos::makeDestroyNotifier([this, jsWindowId]() {
31 std::ignore = m_windowRefs.erase(jsWindowId);
32 }));
33}
34
36 QOhosJsState &jsState,
37 const std::function<bool(QOhosJsState &, const QArkUi::JsWindowRef &)> &predicate)
38{
39 std::vector<QArkUi::JsWindowId> result;
40 for (const auto &windowIdRefPair : m_windowRefs) {
41 if (predicate(jsState, *(windowIdRefPair.second)))
42 result.push_back(windowIdRefPair.first);
43 }
44 return result;
45}
46
47std::shared_ptr<QArkUi::JsWindowRef> QOhosJsWindowRegistry::tryFindJsWindowById(QArkUi::JsWindowId jsWinId) const
48{
49 auto jsWinIter = m_windowRefs.find(jsWinId);
50 return jsWinIter != m_windowRefs.end()
51 ? jsWinIter->second
52 : nullptr;
53}
54
56 QtOhos::QObjectThreadSafeRef qwindow) const
57{
58 for (const auto &windowIdRefPair : m_windowRefs) {
59 if (windowIdRefPair.second->owningQWindowRef() == qwindow)
60 return windowIdRefPair.second;
61 }
62 return nullptr;
63}
64
65QT_END_NAMESPACE
std::shared_ptr< QArkUi::JsWindowRef > tryFindJsWindowById(QArkUi::JsWindowId jsWinId) const
std::shared_ptr< QArkUi::JsWindowRef > tryFindJsWindowByQWindowRef(QtOhos::QObjectThreadSafeRef qwindow) const
std::shared_ptr< void > registerJsWindow(std::shared_ptr< QArkUi::JsWindowRef > jsWindowRef)
std::vector< QArkUi::JsWindowId > queryByPredicate(QOhosJsState &jsState, const std::function< bool(QOhosJsState &, const QArkUi::JsWindowRef &)> &predicate)
Combined button and popup list for selecting options.