Debian Codegraph @

tests/manual/cocoa/menurama/menuramaapplication.cpp

raw
1 /****************************************************************************
2 **
3 ** Copyright (C) 2017 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 #include "menuramaapplication.h"
30
31 MenuramaApplication::MenuramaApplication(int &argc, char **argv)
32 : QApplication (argc, argv)
33 {
34 #if 0
35 QMenuBar *mb = new QMenuBar();
36 QMenu *menu = mb->addMenu("App Dynamic");
37 QMenu *dynMenu = menu->addMenu("After aboutToShow()");
38 connect(dynMenu, &QMenu::aboutToShow, [=] {
39 qDebug() << "aboutToShow(), populating" << dynMenu;
40 menuApp->populateMenu(dynMenu, true /*clear*/);
41 });
42 #endif
43 }
44
45 void MenuramaApplication::populateMenu(QMenu *menu, bool clear)
46 {
47 if (clear)
48 menu->clear();
49
50 static const char *sym[] = { "Foo", "Bar", "Baz", "Huux" };
51 static int id = 0;
52 for (unsigned i = 0; i < sizeof(sym) / sizeof(sym[0]); i++)
53 menu->addAction(QStringLiteral("%1 — %2 %3 ")
54 .arg(menu->title()).arg(sym[i]).arg(id));
55 ++id;
56 }
57
58 void MenuramaApplication::addDynMenu(QLatin1String title, QMenu *parentMenu)
59 {
60 if (QAction *a = findAction(title, parentMenu))
61 parentMenu->removeAction(a);
62
63 QMenu *subMenu = new QMenu(title, parentMenu);
64 populateMenu(subMenu, false /*clear*/);
65 parentMenu->addMenu(subMenu);
66 }
67
68 QAction *MenuramaApplication::findAction(QLatin1String title, QMenu *parentMenu)
69 {
70 foreach (QAction *a, parentMenu->actions())
71 if (a->text() == title)
72 return a;
73
74 return nullptr;
75 }