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 <qohosutils.h>
5#include <render/qohosjswindowregistry.h>
6#include <tuple>
7
9
10QOhosJsWindowRegistry::QOhosJsWindowRegistry() = default;
11
12std::shared_ptr<void> QOhosJsWindowRegistry::registerJsWindow(std::shared_ptr<QArkUi::JsWindowRef> jsWindowRef)
13{
14 auto jsWindowId = jsWindowRef->id();
15
16 bool added = false;
17 std::tie(std::ignore, added) = m_windowRefs.insert({jsWindowRef->id(), jsWindowRef});
18 if (!added) {
19 qOhosReportFatalErrorAndAbort(
20 "%s: Duplicate jsWindow with id: %f", Q_FUNC_INFO, jsWindowId.value());
21 }
22
23 return QtOhos::makeProxyWithJsThreadDeleter(
24 QtOhos::makeDestroyNotifier([this, jsWindowId]() {
25 std::ignore = m_windowRefs.erase(jsWindowId);
26 }));
27}
28
30 QtOhos::JsState &jsState,
31 const std::function<bool(QtOhos::JsState &, const QArkUi::JsWindowRef &)> &predicate)
32{
33 std::vector<QArkUi::JsWindowId> result;
34 for (const auto &windowIdRefPair : m_windowRefs) {
35 if (predicate(jsState, *(windowIdRefPair.second)))
36 result.push_back(windowIdRefPair.first);
37 }
38 return result;
39}
40
41std::shared_ptr<QArkUi::JsWindowRef> QOhosJsWindowRegistry::tryFindJsWindowById(QArkUi::JsWindowId jsWinId) const
42{
43 auto jsWinIter = m_windowRefs.find(jsWinId);
44 return jsWinIter != m_windowRefs.end()
45 ? jsWinIter->second
46 : nullptr;
47}
48
49QT_END_NAMESPACE
std::shared_ptr< QArkUi::JsWindowRef > tryFindJsWindowById(QArkUi::JsWindowId jsWinId) const
std::vector< QArkUi::JsWindowId > queryByPredicate(QtOhos::JsState &jsState, const std::function< bool(QtOhos::JsState &, const QArkUi::JsWindowRef &)> &predicate)
std::shared_ptr< void > registerJsWindow(std::shared_ptr< QArkUi::JsWindowRef > jsWindowRef)
Combined button and popup list for selecting options.