diff framework/MainWindowBase.cpp @ 394:71b21d6e66be

Try descending through menu hierarchy from the top rather than just looking for any objects that are children of menus
author Chris Cannam
date Wed, 13 Aug 2014 15:05:19 +0100
parents ff43500426da
children 2f54917f1599
line wrap: on
line diff
--- a/framework/MainWindowBase.cpp	Wed Aug 13 11:49:45 2014 +0100
+++ b/framework/MainWindowBase.cpp	Wed Aug 13 15:05:19 2014 +0100
@@ -288,7 +288,10 @@
     m_appShortcuts.clear();
 
     QMenuBar *mb = menuBar();
-    QList<QMenu *> menus = mb->findChildren<QMenu *>();
+
+    QList<QMenu *> menus = mb->findChildren<QMenu *>
+        (QString(), Qt::FindDirectChildrenOnly);
+
     foreach (QMenu *menu, menus) {
         if (menu) finaliseMenu(menu);
     }
@@ -347,25 +350,36 @@
     }
 
     foreach (QAction *a, menu->actions()) {
-        QWidgetList ww = a->associatedWidgets();
-        bool hasButton = false;
-        foreach (QWidget *w, ww) {
-            if (qobject_cast<QAbstractButton *>(w)) {
-                hasButton = true;
-                break;
+
+        if (a->isSeparator()) {
+            continue;
+        } else if (a->menu()) {
+            cerr << "recursing to menu: " << a->menu()->title() << endl;
+            finaliseMenu(a->menu());
+        } else {
+
+            QWidgetList ww = a->associatedWidgets();
+            bool hasButton = false;
+            foreach (QWidget *w, ww) {
+                if (qobject_cast<QAbstractButton *>(w)) {
+                    hasButton = true;
+                    break;
+                }
+            }
+            if (hasButton) continue;
+            QKeySequence sc = a->shortcut();
+            if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
+                QShortcut *newSc = new QShortcut(sc, a->parentWidget());
+                QObject::connect(newSc, SIGNAL(activated()),
+                                 m_menuShortcutMapper, SLOT(map()));
+                cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl;
+                m_menuShortcutMapper->setMapping(newSc, a);
+                m_appShortcuts.push_back(newSc);
             }
         }
-        if (hasButton) continue;
-        QKeySequence sc = a->shortcut();
-        if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
-            QShortcut *newSc = new QShortcut(sc, a->parentWidget());
-            QObject::connect(newSc, SIGNAL(activated()),
-                             m_menuShortcutMapper, SLOT(map()));
-            cerr << "setting mapping for action " << a << ", name " << a->text() << " on mapper " << m_menuShortcutMapper << " through shortcut " << newSc << " with key " << newSc->key().toString() << endl;
-            m_menuShortcutMapper->setMapping(newSc, a);
-            m_appShortcuts.push_back(newSc);
-        }
     }
+
+    cerr << "finished with menu " << menu << endl;
 #endif
 }