diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 98c82885c..b7a761953 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -1068,7 +1068,7 @@ void DiagramView::contextMenuEvent(QContextMenuEvent *e) { } else { m_context_menu -> addAction(qde -> m_cut); m_context_menu -> addAction(qde -> m_copy); - m_context_menu->addAction(m_multi_paste); + m_context_menu -> addAction(m_multi_paste); m_context_menu -> addSeparator(); m_context_menu -> addAction(qde -> m_conductor_reset); m_context_menu -> addSeparator(); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index c4919a7fe..7291cfba1 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -48,6 +48,7 @@ #include "rotatetextscommand.h" #include "diagramcommands.h" #include "dialogwaiting.h" +#include "addelementtextcommand.h" #include #include @@ -358,6 +359,7 @@ void QETDiagramEditor::setUpActions() m_rotate_texts = m_selection_actions_group.addAction( QET::Icons::ObjectRotateRight, tr("Orienter les textes") ); m_find_element = m_selection_actions_group.addAction( QET::Icons::ZoomDraw, tr("Retrouver dans le panel") ); m_edit_selection = m_selection_actions_group.addAction( QET::Icons::ElementEdit, tr("Éditer l'item sélectionné") ); + m_group_selected_texts = m_selection_actions_group.addAction(QET::Icons::textGroup, tr("Grouper les textes séléctionné")); m_delete_selection -> setShortcut( QKeySequence::Delete); m_rotate_selection -> setShortcut( QKeySequence( tr("Space") ) ); @@ -374,6 +376,7 @@ void QETDiagramEditor::setUpActions() m_rotate_texts ->setData("rotate_selected_text"); m_find_element ->setData("find_selected_element"); m_edit_selection ->setData("edit_selected_element"); + m_group_selected_texts ->setData("group_selected_texts"); connect(&m_selection_actions_group, &QActionGroup::triggered, this, &QETDiagramEditor::selectionGroupTriggered); @@ -1283,6 +1286,14 @@ void QETDiagramEditor::selectionGroupTriggered(QAction *action) findElementInPanel(currentCustomElement()->location()); else if (value == "edit_selected_element") dv->editSelection(); + else if (value == "group_selected_texts") + { + QList deti_list = dc.m_element_texts.toList(); + if(deti_list.size() <= 1) + return; + + diagram->undoStack().push(new AddTextsGroupCommand(deti_list.first()->parentElement(), tr("Groupe"), deti_list)); + } } void QETDiagramEditor::rowColumnGroupTriggered(QAction *action) @@ -1404,7 +1415,7 @@ void QETDiagramEditor::slot_updateComplexActions() if(!dv) { QList action_list; - action_list << m_conductor_reset << m_find_element << m_cut << m_copy << m_delete_selection << m_rotate_selection << m_edit_selection; + action_list << m_conductor_reset << m_find_element << m_cut << m_copy << m_delete_selection << m_rotate_selection << m_edit_selection << m_group_selected_texts; for(QAction *action : action_list) action->setEnabled(false); @@ -1439,6 +1450,22 @@ void QETDiagramEditor::slot_updateComplexActions() int selected_conductor_texts = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == ConductorTextItem::Type) selected_conductor_texts++;} int selected_dynamic_elmt_text = 0; for(DiagramTextItem *dti : texts) {if(dti->type() == DynamicElementTextItem::Type) selected_dynamic_elmt_text++;} m_rotate_texts->setEnabled(!ro && (selected_texts || groups.size())); + + //Action that need only element text selected + QList deti_list = dc.m_element_texts.toList(); + if(deti_list.size() > 1 && dc.count() == deti_list.count()) + { + Element *elmt = deti_list.first()->parentElement(); + bool ok = true; + for(DynamicElementTextItem *deti : deti_list) + { + if(elmt != deti->parentElement()) + ok = false; + } + m_group_selected_texts->setEnabled(!ro && ok); + } + else + m_group_selected_texts->setDisabled(true); // actions need only one editable item int selected_image = dc.count(DiagramContent::Images); @@ -2184,18 +2211,6 @@ void QETDiagramEditor::selectionChanged() m_selection_properties_editor->setDiagram(dv->diagram()); } -///** -// * @brief QETDiagramEditor::activeUndoStackCleanChanged -// * Enable the QAction save_file when @clean is set to false -// * @clean at true do nothing; -// * @param clean -// */ -//void QETDiagramEditor::activeUndoStackCleanChanged(bool clean) { -// if (!clean) { -// //save_file -> setEnabled(true); -// } -//} - /** * @brief QETDiagramEditor::slot_generateTerminalBlock diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index be6278e24..57710fd14 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -156,7 +156,6 @@ class QETDiagramEditor : public QETMainWindow { private slots: void selectionChanged(); - //void activeUndoStackCleanChanged (bool clean); // attributes private: @@ -211,6 +210,7 @@ class QETDiagramEditor : public QETMainWindow { QAction *m_rotate_selection; ///< Rotate selected elements and text items by 90 degrees QAction *m_rotate_texts; ///< Direct selected text items to a specific angle QAction *m_find_element; ///< Find the selected element in the panel + QAction *m_group_selected_texts = nullptr; QActionGroup m_file_actions_group; ///Actions related to file (open, close, save...) QAction *m_close_file; ///< Close current project file diff --git a/sources/undocommand/addelementtextcommand.cpp b/sources/undocommand/addelementtextcommand.cpp index 80c8070c6..d97ecbd79 100644 --- a/sources/undocommand/addelementtextcommand.cpp +++ b/sources/undocommand/addelementtextcommand.cpp @@ -86,7 +86,31 @@ AddTextsGroupCommand::AddTextsGroupCommand(Element *element, QDomElement dom_ele m_element(element), m_dom_element(dom_element) { - setText(QObject::tr("Ajouter un groupe de textes d'élément")); + setText(QObject::tr("Ajouter un groupe de textes d'élément")); +} + +/** + * @brief AddTextsGroupCommand::AddTextsGroupCommand + * @param element : The element to add a new group + * @param texts_list : a list of texts to add to the created group (texts must be child of element) + * @param parent : parent undo + */ +AddTextsGroupCommand::AddTextsGroupCommand(Element *element, QString groupe_name, QList texts_list, QUndoCommand *parent) : + QUndoCommand(parent), + m_element(element), + m_name(groupe_name) +{ + for(DynamicElementTextItem *deti : texts_list) + { + deti->setSelected(false); + if(deti->parentElement() == element) + { + m_deti_list << deti; + deti->setSelected(false); + } + } + + setText(QObject::tr("Grouper des textes d'élément")); } /** @@ -118,6 +142,11 @@ void AddTextsGroupCommand::redo() m_deti_list = m_group.data()->texts(); m_group.data()->updateAlignment(); } + else + { + for(DynamicElementTextItem *deti : m_deti_list) + m_element.data()->addTextToGroup(deti, m_group.data()); + } m_first_undo = false; } else if(m_group) diff --git a/sources/undocommand/addelementtextcommand.h b/sources/undocommand/addelementtextcommand.h index 67b4112ac..852215507 100644 --- a/sources/undocommand/addelementtextcommand.h +++ b/sources/undocommand/addelementtextcommand.h @@ -53,6 +53,7 @@ class AddTextsGroupCommand : public QUndoCommand public: AddTextsGroupCommand(Element *element, QString groupe_name, QUndoCommand *parent = nullptr); AddTextsGroupCommand(Element *element, QDomElement dom_element, QUndoCommand *parent = nullptr); + AddTextsGroupCommand(Element *element, QString groupe_name, QList texts_list, QUndoCommand *parent = nullptr); ~AddTextsGroupCommand() override; void undo() override;