mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #720, remove highlight DB data menu (we use the DB icon instead)
* removed menu item * fixed menu action, so parents submenus are searched upwards
This commit is contained in:
committed by
Mathew Sutcliffe
parent
009bfc3ed1
commit
a8834d0511
@@ -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<QString, QMenu *> subMenus;
|
||||
const QStringList keys(this->m_actions.uniqueKeys()); // Sorted ascending
|
||||
QMap<QString, QMenu *> subMenus; // all sub menus
|
||||
|
||||
for (const QString &key : keys)
|
||||
{
|
||||
bool addedSeparator = false;
|
||||
const int pd = pathDepth(key);
|
||||
const int pathDepth = CMenuActions::pathDepth(key);
|
||||
|
||||
QList<CMenuAction> actions;
|
||||
QList<CMenuAction> 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<CMenuAction> &menus, QMap<QString, QMenu *> &subMenus, const QString &key, int pd)
|
||||
QMenu *CMenuActions::currentMenuForAction(QMenu &menu, const CMenuAction &menuAction, const QList<CMenuAction> &menus, QMap<QString, QMenu *> &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<QString, QMenu *> &menus)
|
||||
{
|
||||
QString k = key;
|
||||
while (!k.isEmpty() && !menus.isEmpty())
|
||||
{
|
||||
if (menus.contains(k))
|
||||
{
|
||||
return menus[key];
|
||||
}
|
||||
k = parentPath(k);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -318,7 +318,8 @@ namespace BlackGui
|
||||
|
||||
static int pathDepth(const QString &path);
|
||||
static QMenu *currentMenuForAction(QMenu &menu, const CMenuAction &menuAction, const QList<CMenuAction> &menus, QMap<QString, QMenu *> &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<QString, QMenu *> &menus);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,7 +630,6 @@ namespace BlackGui
|
||||
this->m_displayAutomatically = a->isChecked();
|
||||
}
|
||||
|
||||
|
||||
void CViewBaseNonTemplate::ps_setSingleSelection()
|
||||
{
|
||||
if (this->m_originalSelectionMode == ExtendedSelection || this->m_originalSelectionMode == MultiSelection)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -92,28 +92,9 @@ namespace BlackGui
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::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<ModelClass, ContainerType, ObjectType, KeyType>::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<ModelClass, ContainerType, ObjectType>::customMenu(menuActions);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleHighlightDbData()
|
||||
{
|
||||
bool h = this->derivedModel()->highlightDbData();
|
||||
this->derivedModel()->setHighlightDbData(!h);
|
||||
}
|
||||
|
||||
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
|
||||
COrderableViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::COrderableViewWithDbObjects(QWidget *parent) :
|
||||
CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::CViewWithDbObjects(parent)
|
||||
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user