Place the last element and folio references from the folio's context menu

Right-clicking an empty folio now also offers:

- "Insérer le dernier élément": the same action as Édition and the A
  key, shown once something has been placed.
- "Renvoi de folio": the folio report elements the project already
  uses, read from its embedded collection, with dated copies of the same
  element listed once. A project that has none yet gets the coming and
  going arrows of the common collection. An entry places its element
  where the menu was opened.

The submenu is rebuilt each time the menu opens, from the embedded
collection's XML, not from the folios' scenes. It is left empty, and so
hidden, on a read-only folio.

Discussion #1033.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
(cherry picked from commit 94e3f61bf93689066b3964f2316e3c8f1ee7b673)
This commit is contained in:
ispyisail
2026-09-26 12:06:50 +12:00
parent 92cbc8fd2a
commit c1d9e60656
3 changed files with 84 additions and 2 deletions
+79
View File
@@ -44,6 +44,7 @@
#include <QDropEvent>
#include <QPainter>
#include <QPointer>
#include <QSet>
#include <algorithm>
/**
@@ -97,6 +98,9 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
m_create_template = new QAction(tr("Créer un template", "context menu action"), this);
connect(m_create_template, &QAction::triggered, this, &DiagramView::createTemplateFromSelection);
//Filled each time the context menu opens, see updateFolioReportMenu()
m_folio_report_menu = new QMenu(tr("Renvoi de folio"), this);
//setup three separators, to be use in context menu
for(int i=0 ; i<3 ; ++i)
{
@@ -1471,6 +1475,8 @@ QList<QAction *> DiagramView::contextMenuActions() const
//level down where a stray click cannot reach them.
list << m_paste_here;
list << m_separators.at(0);
list << qde->m_insert_last_element;
list << m_folio_report_menu->menuAction();
list << qde->m_add_item_menu->menuAction();
list << m_separators.at(1);
list << qde->m_edit_diagram_properties;
@@ -1582,6 +1588,7 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e)
{
m_paste_here_pos = menu_pos;
m_paste_here->setEnabled(Diagram::clipboardMayContainDiagram());
updateFolioReportMenu();
}
QList <QAction *> list = contextMenuActions();
@@ -1594,6 +1601,78 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e)
}
}
/**
@brief DiagramView::updateFolioReportMenu
Fill the "Renvoi de folio" submenu of the context menu with the folio
report elements this project already uses -- the ones in its embedded
collection -- or, when it has none yet, the coming and going arrows of
the common collection. An entry places its element where the context
menu was opened. Left empty, and so hidden, on a read-only diagram.
*/
void DiagramView::updateFolioReportMenu()
{
m_folio_report_menu->clear();
if (m_diagram->isReadOnly()) {
return;
}
QList<ElementsLocation> locations;
QETProject *project = m_diagram->project();
XmlElementCollection *collection =
project ? project->embeddedElementCollection() : nullptr;
if (collection)
{
QSet<QString> names;
const QDomNodeList definitions =
collection->root().elementsByTagName(QStringLiteral("definition"));
for (int i = 0 ; i < definitions.count() ; ++i)
{
const QDomElement definition = definitions.at(i).toElement();
const QString link_type = definition.attribute(QStringLiteral("link_type"));
if (link_type != QLatin1String("next_report")
&& link_type != QLatin1String("previous_report")) {
continue;
}
const ElementsLocation location =
collection->domToLocation(definition.parentNode().toElement());
//A project keeps dated copies of the same element
//(01previous_folio-20140521204742.elmt), so list each name once.
if (!location.exist() || names.contains(location.name())) {
continue;
}
names.insert(location.name());
locations << location;
}
}
if (locations.isEmpty())
{
for (const auto path : {
"common://10_electric/10_allpole/100_folio_referencing/01coming_arrow.elmt",
"common://10_electric/10_allpole/100_folio_referencing/02going_arrow.elmt"})
{
const ElementsLocation location(QString::fromLatin1(path));
if (location.exist()) {
locations << location;
}
}
}
std::sort(locations.begin(), locations.end(),
[](const ElementsLocation &a, const ElementsLocation &b) {
return a.name().localeAwareCompare(b.name()) < 0;
});
for (const ElementsLocation &location : std::as_const(locations))
{
QAction *action = m_folio_report_menu->addAction(location.icon(),
location.name());
connect(action, &QAction::triggered, this, [this, location]() {
startElementPlacement(location, mapToScene(m_paste_here_pos));
});
}
}
/**
* @brief DiagramView::createTemplateFromSelection
* Triggered from the context menu to create a new template (macro) from the current selection.
+3
View File
@@ -31,6 +31,7 @@ class QETDiagramEditor;
class DVEventInterface;
class QInputEvent;
class QGestureEvent;
class QMenu;
/**
This class provides a widget to render an electric diagram in an editable,
@@ -55,6 +56,7 @@ class DiagramView : public PaletteGraphicsView
QAction *m_paste_here = nullptr;
QAction *m_multi_paste = nullptr;
QAction *m_create_template = nullptr;
QMenu *m_folio_report_menu = nullptr;
QPoint m_paste_here_pos;
QPoint m_last_mouse_pos = QPoint(-1, -1);
QPointF m_drag_last_pos;
@@ -118,6 +120,7 @@ class DiagramView : public PaletteGraphicsView
private:
void handleElementDrop(QDropEvent *);
void updateFolioReportMenu();
void handleTitleBlockDrop(QDropEvent *);
void handleTextDrop(QDropEvent *);
void scrollOnMovement(QKeyEvent *);
+2 -2
View File
@@ -177,7 +177,8 @@ class QETDiagramEditor : public QETMainWindow
*m_edit_diagram_properties, ///< Show a dialog to edit diagram properties
*m_conductor_reset, ///< Reset paths of selected conductors
*m_cut, ///< Cut selection to clipboard
*m_copy; ///< Copy selection to clipboard
*m_copy, ///< Copy selection to clipboard
*m_insert_last_element = nullptr; ///< Place the last placed element again
QActionGroup
m_row_column_actions_group, /// Action related to add/remove rows/column in diagram
@@ -274,7 +275,6 @@ class QETDiagramEditor : public QETMainWindow
ElementsCollectionWidget *m_element_collection_widget;
/// Last element placed from the collection, for "insert last"
ElementsLocation m_last_inserted_element;
QAction *m_insert_last_element = nullptr;
DiagramPropertiesEditorDockWidget *m_selection_properties_editor;
/// Elements panel