qdbusplatformmenu.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbusmenu/qdbusplatformmenu.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtGui module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qdbusplatformmenu_p.h"-
41-
42#include <QDebug>-
43#include <QWindow>-
44-
45QT_BEGIN_NAMESPACE-
46-
47Q_LOGGING_CATEGORY(qLcMenu, "qt.qpa.menu")
executed 1 time by 1 test: return category;
Executed by:
  • tst_QSystemTrayIcon
1
48-
49static int nextDBusID = 1;-
50QHash<int, QDBusPlatformMenuItem *> menuItemsByID;-
51-
52QDBusPlatformMenuItem::QDBusPlatformMenuItem(quintptr tag)-
53 : m_tag(tag ? tag : reinterpret_cast<quintptr>(this)) // QMenu will overwrite this later-
54 , m_subMenu(Q_NULLPTR)-
55 , m_role(NoRole)-
56 , m_isEnabled(true)-
57 , m_isVisible(true)-
58 , m_isSeparator(false)-
59 , m_isCheckable(false)-
60 , m_isChecked(false)-
61 , m_dbusID(nextDBusID++)-
62 , m_hasExclusiveGroup(false)-
63{-
64 menuItemsByID.insert(m_dbusID, this);-
65}
never executed: end of block
0
66-
67QDBusPlatformMenuItem::~QDBusPlatformMenuItem()-
68{-
69 menuItemsByID.remove(m_dbusID);-
70 if (m_subMenu)
m_subMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
71 static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR);
never executed: static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(nullptr);
0
72}
never executed: end of block
0
73-
74void QDBusPlatformMenuItem::setTag(quintptr tag)-
75{-
76 m_tag = tag;-
77}
never executed: end of block
0
78-
79void QDBusPlatformMenuItem::setText(const QString &text)-
80{-
81 qCDebug(qLcMenu) << m_dbusID << text;
never executed: QMessageLogger(__FILE__, 81, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << m_dbusID << text;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
82 m_text = text;-
83}
never executed: end of block
0
84-
85void QDBusPlatformMenuItem::setIcon(const QIcon &icon)-
86{-
87 m_icon = icon;-
88}
never executed: end of block
0
89-
90/*!-
91 Set a submenu under this menu item.-
92*/-
93void QDBusPlatformMenuItem::setMenu(QPlatformMenu *menu)-
94{-
95 if (m_subMenu)
m_subMenuDescription
TRUEnever evaluated
FALSEnever evaluated
0
96 static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(Q_NULLPTR);
never executed: static_cast<QDBusPlatformMenu *>(m_subMenu)->setContainingMenuItem(nullptr);
0
97 m_subMenu = menu;-
98 if (menu)
menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
99 static_cast<QDBusPlatformMenu *>(menu)->setContainingMenuItem(this);
never executed: static_cast<QDBusPlatformMenu *>(menu)->setContainingMenuItem(this);
0
100}
never executed: end of block
0
101-
102void QDBusPlatformMenuItem::setEnabled(bool enabled)-
103{-
104 m_isEnabled = enabled;-
105}
never executed: end of block
0
106-
107void QDBusPlatformMenuItem::setVisible(bool isVisible)-
108{-
109 m_isVisible = isVisible;-
110}
never executed: end of block
0
111-
112void QDBusPlatformMenuItem::setIsSeparator(bool isSeparator)-
113{-
114 m_isSeparator = isSeparator;-
115}
never executed: end of block
0
116-
117void QDBusPlatformMenuItem::setRole(QPlatformMenuItem::MenuRole role)-
118{-
119 m_role = role;-
120}
never executed: end of block
0
121-
122void QDBusPlatformMenuItem::setCheckable(bool checkable)-
123{-
124 m_isCheckable = checkable;-
125}
never executed: end of block
0
126-
127void QDBusPlatformMenuItem::setChecked(bool isChecked)-
128{-
129 m_isChecked = isChecked;-
130}
never executed: end of block
0
131-
132void QDBusPlatformMenuItem::setHasExclusiveGroup(bool hasExclusiveGroup)-
133{-
134 m_hasExclusiveGroup = hasExclusiveGroup;-
135}
never executed: end of block
0
136-
137void QDBusPlatformMenuItem::setShortcut(const QKeySequence &shortcut)-
138{-
139 m_shortcut = shortcut;-
140}
never executed: end of block
0
141-
142void QDBusPlatformMenuItem::trigger()-
143{-
144 emit activated();-
145}
never executed: end of block
0
146-
147QDBusPlatformMenuItem *QDBusPlatformMenuItem::byId(int id)-
148{-
149 // We need to check contains because otherwise QHash would insert-
150 // a default-constructed nullptr value into menuItemsByID-
151 if (menuItemsByID.contains(id))
menuItemsByID.contains(id)Description
TRUEnever evaluated
FALSEnever evaluated
0
152 return menuItemsByID[id];
never executed: return menuItemsByID[id];
0
153 return Q_NULLPTR;
never executed: return nullptr;
0
154}-
155-
156QList<const QDBusPlatformMenuItem *> QDBusPlatformMenuItem::byIds(const QList<int> &ids)-
157{-
158 QList<const QDBusPlatformMenuItem *> ret;-
159 Q_FOREACH (int id, ids) {-
160 if (menuItemsByID.contains(id))
menuItemsByID.contains(id)Description
TRUEnever evaluated
FALSEnever evaluated
0
161 ret << menuItemsByID[id];
never executed: ret << menuItemsByID[id];
0
162 }
never executed: end of block
0
163 return ret;
never executed: return ret;
0
164}-
165-
166-
167QDBusPlatformMenu::QDBusPlatformMenu(quintptr tag)-
168 : m_tag(tag ? tag : reinterpret_cast<quintptr>(this))-
169 , m_isEnabled(true)-
170 , m_isVisible(true)-
171 , m_isSeparator(false)-
172 , m_revision(1)-
173 , m_containingMenuItem(Q_NULLPTR)-
174{-
175}
never executed: end of block
0
176-
177QDBusPlatformMenu::~QDBusPlatformMenu()-
178{-
179 if (m_containingMenuItem)
m_containingMenuItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
180 m_containingMenuItem->setMenu(Q_NULLPTR);
never executed: m_containingMenuItem->setMenu(nullptr);
0
181}
never executed: end of block
0
182-
183void QDBusPlatformMenu::insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before)-
184{-
185 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
186 QDBusPlatformMenuItem *beforeItem = static_cast<QDBusPlatformMenuItem *>(before);-
187 int idx = m_items.indexOf(beforeItem);-
188 qCDebug(qLcMenu) << item->dbusID() << item->text();
never executed: QMessageLogger(__FILE__, 188, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << item->dbusID() << item->text();
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
189 if (idx < 0)
idx < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
190 m_items.append(item);
never executed: m_items.append(item);
0
191 else-
192 m_items.insert(idx, item);
never executed: m_items.insert(idx, item);
0
193 m_itemsByTag.insert(item->tag(), item);-
194 if (item->menu())
item->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
195 syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));
never executed: syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));
0
196 emitUpdated();-
197}
never executed: end of block
0
198-
199void QDBusPlatformMenu::removeMenuItem(QPlatformMenuItem *menuItem)-
200{-
201 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
202 m_items.removeAll(item);-
203 m_itemsByTag.remove(menuItem->tag());-
204 if (item->menu()) {
item->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
205 // disconnect from the signals we connected to in syncSubMenu()-
206 const QDBusPlatformMenu *menu = static_cast<const QDBusPlatformMenu *>(item->menu());-
207 disconnect(menu, &QDBusPlatformMenu::propertiesUpdated,-
208 this, &QDBusPlatformMenu::propertiesUpdated);-
209 disconnect(menu, &QDBusPlatformMenu::updated,-
210 this, &QDBusPlatformMenu::updated);-
211 }
never executed: end of block
0
212 emitUpdated();-
213}
never executed: end of block
0
214-
215void QDBusPlatformMenu::syncSubMenu(const QDBusPlatformMenu *menu)-
216{-
217 // The adaptor is only connected to the propertiesUpdated signal of the top-level-
218 // menu, so the submenus should transfer their signals to their parents.-
219 connect(menu, &QDBusPlatformMenu::propertiesUpdated,-
220 this, &QDBusPlatformMenu::propertiesUpdated, Qt::UniqueConnection);-
221 connect(menu, &QDBusPlatformMenu::updated,-
222 this, &QDBusPlatformMenu::updated, Qt::UniqueConnection);-
223}
never executed: end of block
0
224-
225void QDBusPlatformMenu::syncMenuItem(QPlatformMenuItem *menuItem)-
226{-
227 QDBusPlatformMenuItem *item = static_cast<QDBusPlatformMenuItem *>(menuItem);-
228 // if a submenu was added to this item, we need to connect to its signals-
229 if (item->menu())
item->menu()Description
TRUEnever evaluated
FALSEnever evaluated
0
230 syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));
never executed: syncSubMenu(static_cast<const QDBusPlatformMenu *>(item->menu()));
0
231 // TODO keep around copies of the QDBusMenuLayoutItems so they can be updated?-
232 // or eliminate them by putting dbus streaming operators in this class instead?-
233 // or somehow tell the dbusmenu client that something has changed, so it will ask for properties again-
234 QDBusMenuItemList updated;-
235 QDBusMenuItemKeysList removed;-
236 updated << QDBusMenuItem(item);-
237 qCDebug(qLcMenu) << updated;
never executed: QMessageLogger(__FILE__, 237, __PRETTY_FUNCTION__, qLcMenu().categoryName()).debug() << updated;
qt_category_enabledDescription
TRUEnever evaluated
FALSEnever evaluated
0
238 emit propertiesUpdated(updated, removed);-
239}
never executed: end of block
0
240-
241void QDBusPlatformMenu::emitUpdated()-
242{-
243 if (m_containingMenuItem)
m_containingMenuItemDescription
TRUEnever evaluated
FALSEnever evaluated
0
244 emit updated(++m_revision, m_containingMenuItem->dbusID());
never executed: updated(++m_revision, m_containingMenuItem->dbusID());
0
245 else-
246 emit updated(++m_revision, 0);
never executed: updated(++m_revision, 0);
0
247}-
248-
249void QDBusPlatformMenu::setTag(quintptr tag)-
250{-
251 m_tag = tag;-
252}
never executed: end of block
0
253-
254void QDBusPlatformMenu::setText(const QString &text)-
255{-
256 m_text = text;-
257}
never executed: end of block
0
258-
259void QDBusPlatformMenu::setIcon(const QIcon &icon)-
260{-
261 m_icon = icon;-
262}
never executed: end of block
0
263-
264void QDBusPlatformMenu::setEnabled(bool enabled)-
265{-
266 m_isEnabled = enabled;-
267}
never executed: end of block
0
268-
269void QDBusPlatformMenu::setVisible(bool isVisible)-
270{-
271 m_isVisible = isVisible;-
272}
never executed: end of block
0
273-
274void QDBusPlatformMenu::setContainingMenuItem(QDBusPlatformMenuItem *item)-
275{-
276 m_containingMenuItem = item;-
277}
never executed: end of block
0
278-
279QPlatformMenuItem *QDBusPlatformMenu::menuItemAt(int position) const-
280{-
281 return m_items.value(position);
never executed: return m_items.value(position);
0
282}-
283-
284QPlatformMenuItem *QDBusPlatformMenu::menuItemForTag(quintptr tag) const-
285{-
286 return m_itemsByTag[tag];
never executed: return m_itemsByTag[tag];
0
287}-
288-
289const QList<QDBusPlatformMenuItem *> QDBusPlatformMenu::items() const-
290{-
291 return m_items;
never executed: return m_items;
0
292}-
293-
294QPlatformMenuItem *QDBusPlatformMenu::createMenuItem() const-
295{-
296 QDBusPlatformMenuItem *ret = new QDBusPlatformMenuItem();-
297 return ret;
never executed: return ret;
0
298}-
299-
300QPlatformMenu *QDBusPlatformMenu::createSubMenu() const-
301{-
302 return new QDBusPlatformMenu;
never executed: return new QDBusPlatformMenu;
0
303}-
304-
305QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9