From 0ca4b9f6c3549cb16263f0bbeb5e3d36d048556b Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sat, 26 Sep 2026 11:40:25 +1200 Subject: [PATCH] Put drawing first in the folio's context menu, rows and columns one level down Right-clicking an empty folio offered Paste here, Folio properties and four row/column actions. Four of six entries change the folio's layout, which is rarely wanted and easy to hit by mistake, while nothing in the menu helps draw. The empty-folio menu now holds the "Ajouter" submenu (text, image, shapes, terminal strip plan -- the same actions as the Edition menu and toolbar), then Folio properties, then the row and column actions in a "Lignes et colonnes" submenu. The selection menu is unchanged. A submenu whose actions are all disabled is dropped, the same way disabled actions already are. Discussion #1033. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG --- sources/diagramview.cpp | 20 +++++++++++++++++--- sources/qetdiagrameditor.cpp | 12 +++++++++--- sources/qetdiagrameditor.h | 4 ++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 843b694be..9a5a27154 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -43,6 +43,7 @@ #include #include #include +#include /** Constructeur @@ -1299,10 +1300,15 @@ QList DiagramView::contextMenuActions() const { if (m_diagram->selectedItems().isEmpty()) { + //Drawing comes first. The row and column actions change + //the folio's layout and are rarely wanted, so they sit one + //level down where a stray click cannot reach them. list << m_paste_here; list << m_separators.at(0); + list << qde->m_add_item_menu->menuAction(); + list << m_separators.at(1); list << qde->m_edit_diagram_properties; - list << qde->m_row_column_actions_group.actions(); + list << qde->m_row_column_menu->menuAction(); } else { @@ -1318,11 +1324,19 @@ QList DiagramView::contextMenuActions() const list << qde->m_depth_action_group->actions(); } - //Remove from the context menu the actions which are disabled. + //Remove from the context menu the actions which are disabled, + //and the submenus in which every action is disabled. const QList actions = list; for(QAction *action : actions) { - if (!action->isEnabled()) { + bool usable = action->isEnabled(); + if (usable && action->menu()) + { + const QList sub_actions = action->menu()->actions(); + usable = std::any_of(sub_actions.cbegin(), sub_actions.cend(), + [](QAction *a) { return a->isEnabled(); }); + } + if (!usable) { list.removeAll(action); } } diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index da26262b2..f1fdcec7a 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1044,9 +1044,9 @@ void QETDiagramEditor::setUpMenu() //toolbar button has no key, so text fields, images and every drawing //shape simply could not be added. m_depth_action_group below has //always been in both places; this brings these into line with it. - QMenu *menu_add_item = menu_edition -> addMenu(tr("A&jouter")); - menu_add_item -> setIcon(QET::Icons::Add); - menu_add_item -> addActions(m_add_item_actions_group.actions()); + m_add_item_menu = menu_edition -> addMenu(tr("A&jouter")); + m_add_item_menu -> setIcon(QET::Icons::Add); + m_add_item_menu -> addActions(m_add_item_actions_group.actions()); menu_edition -> addSeparator(); menu_edition -> addActions(m_select_actions_group.actions()); menu_edition -> addSeparator(); @@ -1056,6 +1056,12 @@ void QETDiagramEditor::setUpMenu() menu_edition -> addSeparator(); menu_edition -> addAction(m_edit_diagram_properties); menu_edition -> addActions(m_row_column_actions_group.actions()); + //Not added to a menu here: it exists so the folio's context menu can + //hold the row and column actions one level down (see + //DiagramView::contextMenuActions()). + m_row_column_menu = new QMenu(tr("Lignes et colonnes"), this); + m_row_column_menu -> setIcon(QET::Icons::EditTableInsertColumnRight); + m_row_column_menu -> addActions(m_row_column_actions_group.actions()); menu_edition -> addSeparator(); menu_edition -> addActions(m_depth_action_group->actions()); menu_edition -> addSeparator(); diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 71ad56244..c0495b948 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -177,6 +177,10 @@ class QETDiagramEditor : public QETMainWindow m_row_column_actions_group, /// Action related to add/remove rows/column in diagram m_selection_actions_group, ///Action related to edit a selected item *m_depth_action_group = nullptr; + + QMenu + *m_add_item_menu = nullptr, ///< Submenu of m_add_item_actions_group + *m_row_column_menu = nullptr; ///< Submenu of m_row_column_actions_group private: QActionGroup