diff --git a/src/blackgui/menus/menuaction.cpp b/src/blackgui/menus/menuaction.cpp index ea8edc676..054449825 100644 --- a/src/blackgui/menus/menuaction.cpp +++ b/src/blackgui/menus/menuaction.cpp @@ -293,18 +293,25 @@ namespace BlackGui void CMenuActions::toQMenu(QMenu &menu, bool separateGroups) const { if (this->m_actions.isEmpty()) { return; } - const QStringList keys(this->m_actions.uniqueKeys()); - QMap subMenus; + const QStringList keys(this->m_actions.uniqueKeys()); // Sorted ascending + QMap subMenus; // all sub menus for (const QString &key : keys) { bool addedSeparator = false; - const int pd = pathDepth(key); + const int pathDepth = CMenuActions::pathDepth(key); QList actions; QList menus; this->splitSubMenus(key, actions, menus); - if (actions.isEmpty()) { continue; } + if (actions.isEmpty()) + { + // uncomment this if a subdir shall be displayed, even if there are no actions + // if (!menus.isEmpty()) { currentMenuForAction(menu, menus.fi, menus, subMenus, key, pathDepth); } + + // No actions directly for that level + continue; + } if (!menu.isEmpty() && separateGroups) { menu.addSeparator(); @@ -314,13 +321,13 @@ namespace BlackGui int noActionsWithoutPath = 0; QMenu *currentMenu = nullptr; - // reverse iteration because same key values are inserted and havve reverse order + // reverse iteration because same key values are inserted and have reverse order for (const CMenuAction &menuAction : actions) { // create submenu if required if (!currentMenu) { - currentMenu = currentMenuForAction(menu, menuAction, menus, subMenus, key, pd); + currentMenu = currentMenuForAction(menu, menuAction, menus, subMenus, key, pathDepth); } Q_ASSERT_X(currentMenu, Q_FUNC_INFO, "Missing menu"); Q_ASSERT_X(!menuAction.isSubMenu() && menuAction.getQAction(), Q_FUNC_INFO, "Wrong menu type"); @@ -409,16 +416,16 @@ namespace BlackGui return this->addMenu(CIcons::appModels16(), "Model set", CMenuAction::pathModelSet()); } - QMenu *CMenuActions::currentMenuForAction(QMenu &menu, const CMenuAction &menuAction, const QList &menus, QMap &subMenus, const QString &key, int pd) + QMenu *CMenuActions::currentMenuForAction(QMenu &menu, const CMenuAction &menuAction, const QList &menus, QMap &subMenus, const QString &key, int pathDepth) { - if (pd < 1) { return &menu; } + if (pathDepth < 1) { return &menu; } QMenu *parentMenu = &menu; - if (pd > 1) + if (pathDepth > 1) { - const QString pk(parentPathKey(key)); - parentMenu = subMenus.value(pk); - BLACK_VERIFY_X(parentMenu, Q_FUNC_INFO, "Missing sub menu"); + // find the corresponding submenu. If this is empty the next higher level will be choosen + // if not found at all, use top level menu + parentMenu = findUpwardsInMenus(key, subMenus); if (!parentMenu) { parentMenu = &menu; } } @@ -436,7 +443,7 @@ namespace BlackGui Q_ASSERT_X(subMenu, Q_FUNC_INFO, "Could not create sub menu"); subMenu->setParent(parentMenu); - if (pd > 0 && subMenu) + if (pathDepth > 0 && subMenu) { subMenus.insert(key, subMenu); } @@ -450,11 +457,25 @@ namespace BlackGui return c > 0 ? c : 0; } - QString CMenuActions::parentPathKey(const QString ¤tPath) + QString CMenuActions::parentPath(const QString ¤tPath) { if (!currentPath.contains('/')) { return ""; } const int i = currentPath.lastIndexOf('/'); return currentPath.left(i); } + + QMenu *CMenuActions::findUpwardsInMenus(const QString &key, const QMap &menus) + { + QString k = key; + while (!k.isEmpty() && !menus.isEmpty()) + { + if (menus.contains(k)) + { + return menus[key]; + } + k = parentPath(k); + } + return nullptr; + } } // ns } // ns diff --git a/src/blackgui/menus/menuaction.h b/src/blackgui/menus/menuaction.h index 7c203846a..05b68bfff 100644 --- a/src/blackgui/menus/menuaction.h +++ b/src/blackgui/menus/menuaction.h @@ -318,7 +318,8 @@ namespace BlackGui static int pathDepth(const QString &path); static QMenu *currentMenuForAction(QMenu &menu, const CMenuAction &menuAction, const QList &menus, QMap &subMenus, const QString &key, int pd); - static QString parentPathKey(const QString &cuurentPath); + static QString parentPath(const QString &cuurentPath); + static QMenu *findUpwardsInMenus(const QString &key, const QMap &menus); }; } // ns } // ns diff --git a/src/blackgui/views/aircraftmodelview.cpp b/src/blackgui/views/aircraftmodelview.cpp index da1ad7ac3..7870f0f25 100644 --- a/src/blackgui/views/aircraftmodelview.cpp +++ b/src/blackgui/views/aircraftmodelview.cpp @@ -67,7 +67,7 @@ namespace BlackGui switch (mode) { case CAircraftModelListModel::StashModel: - this->m_menus = MenuDefaultNoClear | MenuHighlightDbData; + this->m_menus = MenuDefaultNoClear; break; case CAircraftModelListModel::Database: this->m_menus = MenuDefaultDbViews; @@ -76,11 +76,11 @@ namespace BlackGui this->m_menus = MenuDefaultNoClear | MenuStashing; break; case CAircraftModelListModel::OwnSimulatorModelMapping: - this->m_menus = MenuDefaultNoClear | MenuStashing | MenuHighlightDbData | MenuLoadAndSave; + this->m_menus = MenuDefaultNoClear | MenuStashing | MenuLoadAndSave; break; case CAircraftModelListModel::OwnSimulatorModel: default: - this->m_menus = MenuDefaultNoClear | MenuBackend | MenuHighlightDbData; + this->m_menus = MenuDefaultNoClear | MenuBackend; break; } } diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 0a5889913..ef490cbcd 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -630,7 +630,6 @@ namespace BlackGui this->m_displayAutomatically = a->isChecked(); } - void CViewBaseNonTemplate::ps_setSingleSelection() { if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection) diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index b3cb54c97..86d4dd15b 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -119,9 +119,8 @@ namespace BlackGui MenuDefaultDbViews = MenuToggleSelectionMode | MenuBackend, // special menus, should be in derived classes, but enums cannot be inherited // maybe shifted in the future to elsewhere - MenuHighlightDbData = 1 << 10, //!< highlight DB data - MenuHighlightStashed = 1 << 11, //!< highlight stashed models - MenuCanStashModels = 1 << 12, //!< stash models + MenuHighlightStashed = 1 << 10, //!< highlight stashed models + MenuCanStashModels = 1 << 11, //!< stash models MenuStashing = MenuHighlightStashed | MenuCanStashModels, }; Q_DECLARE_FLAGS(Menu, MenuFlag) diff --git a/src/blackgui/views/viewdbobjects.cpp b/src/blackgui/views/viewdbobjects.cpp index 24c3f1c53..eefb8bee6 100644 --- a/src/blackgui/views/viewdbobjects.cpp +++ b/src/blackgui/views/viewdbobjects.cpp @@ -92,28 +92,9 @@ namespace BlackGui template void CViewWithDbObjects::customMenu(Menus::CMenuActions &menuActions) { - if (this->m_menus.testFlag(CViewBaseNonTemplate::MenuHighlightDbData)) - { - if (!this->m_menuFlagActions.contains(CViewBaseNonTemplate::MenuHighlightDbData)) - { - CMenuActions ma; - QAction *added = ma.addAction(CIcons::database16(), "Highlight DB data", CMenuAction::pathViewDatabase(), { this, &CViewWithDbObjects::ps_toggleHighlightDbData }); - added->setCheckable(true); - this->m_menuFlagActions.insert(CViewBaseNonTemplate::MenuHighlightDbData, ma); - } - QAction *a = menuActions.addActions(this->initMenuActions(CViewBaseNonTemplate::MenuHighlightDbData)).first(); - a->setChecked(this->derivedModel()->highlightDbData()); - } CViewBase::customMenu(menuActions); } - template - void CViewWithDbObjects::ps_toggleHighlightDbData() - { - bool h = this->derivedModel()->highlightDbData(); - this->derivedModel()->setHighlightDbData(!h); - } - template COrderableViewWithDbObjects::COrderableViewWithDbObjects(QWidget *parent) : CViewWithDbObjects::CViewWithDbObjects(parent) diff --git a/src/blackgui/views/viewdbobjects.h b/src/blackgui/views/viewdbobjects.h index cb2fbb0ee..e2cb687ea 100644 --- a/src/blackgui/views/viewdbobjects.h +++ b/src/blackgui/views/viewdbobjects.h @@ -69,10 +69,6 @@ namespace BlackGui //! \copydoc BlackGui::Views::CViewBaseNonTemplate::customMenu virtual void customMenu(BlackGui::Menus::CMenuActions &menuActions) override; - - protected slots: - //! \copydoc BlackGui::Views::CViewBase::ps_toggleHighlightDbData - virtual void ps_toggleHighlightDbData() override; }; //! Base class for views with DB objects also orderable (based on BlackMisc::IOrderableList )