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
qandroidplatformmenubar.cpp
Go to the documentation of this file.
1// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
7
9
10QAndroidPlatformMenuBar::QAndroidPlatformMenuBar()
11{
12 m_parentWindow = 0;
13 QtAndroidMenu::addMenuBar(this);
14}
15
20
21void QAndroidPlatformMenuBar::insertMenu(QPlatformMenu *menu, QPlatformMenu *before)
22{
23 QMutexLocker lock(&m_menusListMutex);
24 m_menus.insert(std::find(m_menus.begin(),
25 m_menus.end(),
26 static_cast<QAndroidPlatformMenu *>(before)),
27 static_cast<QAndroidPlatformMenu *>(menu));
28 m_menuHash.insert(m_nextMenuId++, menu);
29}
30
31void QAndroidPlatformMenuBar::removeMenu(QPlatformMenu *menu)
32{
33 QMutexLocker lock(&m_menusListMutex);
34 m_menus.erase(std::find(m_menus.begin(),
35 m_menus.end(),
36 static_cast<QAndroidPlatformMenu *>(menu)));
37
38 int maxId = -1;
39 QHash<int, QPlatformMenu *>::iterator it = m_menuHash.begin();
40 while (it != m_menuHash.end()) {
41 if (it.value() == menu) {
42 it = m_menuHash.erase(it);
43 } else {
44 maxId = qMax(maxId, it.key());
45 ++it;
46 }
47 }
48
49 m_nextMenuId = maxId + 1;
50}
51
52int QAndroidPlatformMenuBar::menuId(QPlatformMenu *menu) const
53{
54 QHash<int, QPlatformMenu *>::const_iterator it;
55 for (it = m_menuHash.constBegin(); it != m_menuHash.constEnd(); ++it) {
56 if (it.value() == menu)
57 return it.key();
58 }
59
60 return -1;
61}
62
63void QAndroidPlatformMenuBar::syncMenu(QPlatformMenu *menu)
64{
66}
67
68void QAndroidPlatformMenuBar::handleReparent(QWindow *newParentWindow)
69{
70 if (m_parentWindow == newParentWindow)
71 return;
72 m_parentWindow = newParentWindow;
73 QtAndroidMenu::setMenuBar(this, newParentWindow);
74}
75
77{
78 for (QAndroidPlatformMenu *menu : m_menus) {
79 if (menu->tag() == tag)
80 return menu;
81 }
82
83 return nullptr;
84}
85
87{
88 return m_menuHash.value(menuId);
89}
90
92{
93 return m_parentWindow;
94}
95
100
102{
103 return &m_menusListMutex;
104}
105
106QT_END_NAMESPACE
PlatformMenusType menus() const
QWindow * parentWindow() const override
void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override
void handleReparent(QWindow *newParentWindow) override
void syncMenu(QPlatformMenu *menu) override
int menuId(QPlatformMenu *menu) const
QPlatformMenu * menuForId(int menuId) const
QPlatformMenu * menuForTag(quintptr tag) const override
void removeMenu(QPlatformMenu *menu) override
QList< QAndroidPlatformMenu * > PlatformMenusType
\inmodule QtCore
Definition qmutex.h:346
void removeMenuBar(QAndroidPlatformMenuBar *menuBar)
void syncMenu(QAndroidPlatformMenu *)
void setMenuBar(QAndroidPlatformMenuBar *menuBar, QWindow *window)