diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 9d9f3edf7..4d81c5468 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include /** @@ -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 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 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 locations; + QETProject *project = m_diagram->project(); + XmlElementCollection *collection = + project ? project->embeddedElementCollection() : nullptr; + if (collection) + { + QSet 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. diff --git a/sources/diagramview.h b/sources/diagramview.h index 03eb067d5..ae7b6af33 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -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 *); diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index 3cb2659ec..fd1542c9a 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -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