[qet] qet/qet: [5372] Diagram editor : add new context menu action " group the selected texts"

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 5372
Author:   blacksun
Date:     2018-05-18 23:46:36 +0200 (Fri, 18 May 2018)
Log Message:
-----------
Diagram editor : add new context menu action "group the selected texts"

Modified Paths:
--------------
    trunk/sources/diagramview.cpp
    trunk/sources/qetdiagrameditor.cpp
    trunk/sources/qetdiagrameditor.h
    trunk/sources/undocommand/addelementtextcommand.cpp
    trunk/sources/undocommand/addelementtextcommand.h

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2018-05-18 19:36:27 UTC (rev 5371)
+++ trunk/sources/diagramview.cpp	2018-05-18 21:46:36 UTC (rev 5372)
@@ -1068,7 +1068,7 @@
 		} 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();

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2018-05-18 19:36:27 UTC (rev 5371)
+++ trunk/sources/qetdiagrameditor.cpp	2018-05-18 21:46:36 UTC (rev 5372)
@@ -48,6 +48,7 @@
 #include "rotatetextscommand.h"
 #include "diagramcommands.h"
 #include "dialogwaiting.h"
+#include "addelementtextcommand.h"
 
 #include <QMessageBox>
 #include <QStandardPaths>
@@ -358,6 +359,7 @@
     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 @@
 	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 @@
 		findElementInPanel(currentCustomElement()->location());
 	else if (value == "edit_selected_element")
 		dv->editSelection();
+	else if (value == "group_selected_texts")
+	{
+		QList<DynamicElementTextItem *> 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 @@
 	if(!dv)
 	{
 		QList <QAction *> 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 @@
 	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<DynamicElementTextItem *> 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,19 +2211,7 @@
 		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
  */

Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h	2018-05-18 19:36:27 UTC (rev 5371)
+++ trunk/sources/qetdiagrameditor.h	2018-05-18 21:46:36 UTC (rev 5372)
@@ -156,7 +156,6 @@
 
 	private slots:
 		void selectionChanged();
-		//void activeUndoStackCleanChanged (bool clean);
 
 		// attributes
 	private:
@@ -211,6 +210,7 @@
 		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

Modified: trunk/sources/undocommand/addelementtextcommand.cpp
===================================================================
--- trunk/sources/undocommand/addelementtextcommand.cpp	2018-05-18 19:36:27 UTC (rev 5371)
+++ trunk/sources/undocommand/addelementtextcommand.cpp	2018-05-18 21:46:36 UTC (rev 5372)
@@ -86,10 +86,34 @@
 	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<DynamicElementTextItem *> 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"));
+}
+
+/**
  * @brief AddTextsGroupCommand::~AddTextsGroupCommand
  * Destructor
  */
@@ -118,6 +142,11 @@
 				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)

Modified: trunk/sources/undocommand/addelementtextcommand.h
===================================================================
--- trunk/sources/undocommand/addelementtextcommand.h	2018-05-18 19:36:27 UTC (rev 5371)
+++ trunk/sources/undocommand/addelementtextcommand.h	2018-05-18 21:46:36 UTC (rev 5372)
@@ -53,6 +53,7 @@
 	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<DynamicElementTextItem *> texts_list, QUndoCommand *parent = nullptr);
 		~AddTextsGroupCommand() override;
 		
 		void undo() override;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/