[qet] qet/qet: [5142] Texts group can be removed with the delete key of keybord

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


Revision: 5142
Author:   blacksun
Date:     2017-12-05 22:41:29 +0100 (Tue, 05 Dec 2017)
Log Message:
-----------
Texts group can be removed with the delete key of keybord

Modified Paths:
--------------
    trunk/sources/diagramcontent.cpp
    trunk/sources/diagramcontent.h
    trunk/sources/diagramview.cpp
    trunk/sources/diagramview.h
    trunk/sources/qetdiagrameditor.cpp
    trunk/sources/ui/dynamicelementtextmodel.cpp
    trunk/sources/undocommand/deleteqgraphicsitemcommand.cpp

Modified: trunk/sources/diagramcontent.cpp
===================================================================
--- trunk/sources/diagramcontent.cpp	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/diagramcontent.cpp	2017-12-05 21:41:29 UTC (rev 5142)
@@ -175,6 +175,31 @@
 }
 
 /**
+ * @brief DiagramContent::hasDeletableItems
+ * @return true if this diagram content have deletable item
+ * The deletable items correspond to the selected items of diagram
+ * at the moment of the creation of this DiagramContent,
+ * with the constructor :  DiagramContent::DiagramContent(Diagram *diagram)
+ */
+bool DiagramContent::hasDeletableItems() const
+{
+	for(QGraphicsItem *qgi : m_selected_items)
+	{
+		if (qgi->type() == Element::Type ||
+			qgi->type() == Conductor::Type ||
+			qgi->type() == IndependentTextItem::Type ||
+			qgi->type() == QetShapeItem::Type ||
+			qgi->type() == DiagramImageItem::Type ||
+			qgi->type() == DynamicElementTextItem::Type)
+			return true;
+		if(qgi->type() == QGraphicsItemGroup::Type)
+			if(dynamic_cast<ElementTextItemGroup *>(qgi))
+				return true;
+	}
+	return(false);
+}
+
+/**
  * @brief DiagramContent::clear
  * Remove all items from the diagram content
  */

Modified: trunk/sources/diagramcontent.h
===================================================================
--- trunk/sources/diagramcontent.h	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/diagramcontent.h	2017-12-05 21:41:29 UTC (rev 5142)
@@ -79,6 +79,7 @@
 		QList<DiagramTextItem *> selectedTexts() const;
 		QList<ElementTextItemGroup *> selectedTextsGroup() const;
 		QList<Conductor *> conductors(int = AnyConductor) const;
+		bool hasDeletableItems() const;
 		QList<QGraphicsItem *> items(int = All) const;
 		QString sentence(int = All) const;
 		int count(int = All) const;

Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/diagramview.cpp	2017-12-05 21:41:29 UTC (rev 5142)
@@ -127,20 +127,6 @@
 }
 
 /**
- * @brief DiagramView::deleteSelection
- * Delete the selected items
- */
-void DiagramView::deleteSelection()
-{
-	if (m_diagram -> isReadOnly())
-		return;
-	DiagramContent removed_content = DiagramContent(m_diagram);
-	m_diagram->clearSelection();
-	m_diagram->undoStack().push(new DeleteQGraphicsItemCommand(m_diagram, removed_content));
-	adjustSceneRect();
-}
-
-/**
 	Accepte ou refuse le drag'n drop en fonction du type de donnees entrant
 	@param e le QDragEnterEvent correspondant au drag'n drop tente
 */
@@ -751,25 +737,6 @@
 }
 
 /**
- * @brief DiagramView::hasDeletableItems
- * @return True if a least on of selected item can be deleted
- */
-bool DiagramView::hasDeletableItems()
-{
-	for(QGraphicsItem *qgi : m_diagram->selectedItems())
-	{
-		if (qgi->type() == Element::Type ||
-			qgi->type() == Conductor::Type ||
-			qgi->type() == IndependentTextItem::Type ||
-			qgi->type() == QetShapeItem::Type ||
-			qgi->type() == DiagramImageItem::Type ||
-			qgi->type() == DynamicElementTextItem::Type)
-			return true;
-	}
-	return(false);
-}
-
-/**
 	Ajoute une colonne au schema.
 */
 void DiagramView::addColumn() {

Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/diagramview.h	2017-12-05 21:41:29 UTC (rev 5142)
@@ -68,7 +68,6 @@
 		QETDiagramEditor *diagramEditor() const;
 		bool hasCopiableItems();
 		bool hasTextItems();
-		bool hasDeletableItems();
 		void editSelection();
 		void setEventInterface (DVEventInterface *event_interface);
 	
@@ -119,7 +118,6 @@
 		void selectNothing();
 		void selectAll();
 		void selectInvert();
-		void deleteSelection();
 		void setVisualisationMode();
 		void setSelectionMode();
 		void zoom(const qreal zoom_factor);

Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/qetdiagrameditor.cpp	2017-12-05 21:41:29 UTC (rev 5142)
@@ -47,6 +47,7 @@
 #include "elementtextitem.h"
 #include "undocommand/rotateselectioncommand.h"
 #include "rotatetextscommand.h"
+#include "diagramcommands.h"
 
 #include <QMessageBox>
 #include <QStandardPaths>
@@ -1261,23 +1262,25 @@
 {
 	QString value = action->data().toString();
 	DiagramView *dv = currentDiagram();
+	Diagram *diagram = dv->diagram();
+	DiagramContent dc(diagram);
 
 	if (!dv || value.isEmpty()) return;
 
 	if (value == "delete_selection")
-		dv->deleteSelection();
+	{
+		diagram->clearSelection();
+		diagram->undoStack().push(new DeleteQGraphicsItemCommand(diagram, dc));
+		dv->adjustSceneRect();
+	}
 	else if (value == "rotate_selection")
 	{
-		Diagram *d = dv->diagram();
-		RotateSelectionCommand *c = new RotateSelectionCommand(d);
+		RotateSelectionCommand *c = new RotateSelectionCommand(diagram);
 		if(c->isValid())
-			d->undoStack().push(c);
+			diagram->undoStack().push(c);
 	}
 	else if (value == "rotate_selected_text")
-	{
-		Diagram *d = dv->diagram();
-		d->undoStack().push(new RotateTextsCommand(d));
-	}
+		diagram->undoStack().push(new RotateTextsCommand(diagram));
 	else if (value == "find_selected_element" && currentCustomElement())
 		findElementInPanel(currentCustomElement()->location());
 	else if (value == "edit_selected_element")
@@ -1427,7 +1430,7 @@
 	
 		//Action that need items (elements, conductors, texts...) selected, to be enabled
 	bool copiable_items  = dv->hasCopiableItems();
-	bool deletable_items = dv->hasDeletableItems();
+	bool deletable_items = dc.hasDeletableItems();
 	m_cut              -> setEnabled(!ro && copiable_items);
 	m_copy             -> setEnabled(copiable_items);
 	m_delete_selection -> setEnabled(!ro && deletable_items);

Modified: trunk/sources/ui/dynamicelementtextmodel.cpp
===================================================================
--- trunk/sources/ui/dynamicelementtextmodel.cpp	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/ui/dynamicelementtextmodel.cpp	2017-12-05 21:41:29 UTC (rev 5142)
@@ -452,7 +452,7 @@
 		quc->setText(tr("Modifier la couleur d'un texte d'élément"));
 	}
 	
-	bool frame = text_qsi->child(4,1)->checkState() == Qt::Checked? frame=true : frame=false;
+	bool frame = text_qsi->child(4,1)->checkState() == Qt::Checked? true : false;
 	if(frame != deti->frame())
 	{
 		QUndoCommand *quc = new QPropertyUndoCommand(deti, "frame", QVariant(deti->frame()), QVariant(frame), undo);

Modified: trunk/sources/undocommand/deleteqgraphicsitemcommand.cpp
===================================================================
--- trunk/sources/undocommand/deleteqgraphicsitemcommand.cpp	2017-12-05 20:51:54 UTC (rev 5141)
+++ trunk/sources/undocommand/deleteqgraphicsitemcommand.cpp	2017-12-05 21:41:29 UTC (rev 5142)
@@ -22,6 +22,7 @@
 #include "conductor.h"
 #include "conductortextitem.h"
 #include "elementtextitemgroup.h"
+#include "addelementtextcommand.h"
 
 /**
  * @brief DeleteQGraphicsItemCommand::DeleteQGraphicsItemCommand
@@ -44,6 +45,8 @@
 			
 	}
 	
+		//When remove a deti we must to know his parent item, for re-add deti as child of the parent
+		//when undo this command
 	for(DynamicElementTextItem *deti : m_removed_contents.m_element_texts)
 	{
 		if(deti->parentGroup())
@@ -52,6 +55,21 @@
 			m_elmt_text_hash.insert(deti, deti->parentElement());
 	}
 	
+		//If parent element of ElementTextItemGroup is also in @m_removed_content,
+		//we remove it, because when the element will be removed from the scene every child's will also be removed.
+	const QSet<ElementTextItemGroup *> group_set = m_removed_contents.m_texts_groups;
+	for(ElementTextItemGroup *group : group_set)
+	{
+		if(m_removed_contents.m_elements.contains(group->parentElement()))
+			m_removed_contents.m_texts_groups.remove(group);
+	}
+	
+		//The deletion of the groups is not managed by this undo, but by a RemoveTextsGroupCommand
+	for(ElementTextItemGroup *group : m_removed_contents.m_texts_groups) {
+		new RemoveTextsGroupCommand(group->parentElement(), group, this);}
+	
+	m_removed_contents.m_texts_groups.clear();
+	
 	setText(QString(QObject::tr("supprimer %1", "undo caption - %1 is a sentence listing the removed content")).arg(m_removed_contents.sentence(DiagramContent::All)));
 	m_diagram->qgiManager().manage(m_removed_contents.items(DiagramContent::All));
 }
@@ -87,6 +105,8 @@
 			elmt->addTextToGroup(deti, m_grp_texts_hash.value(deti));
 		}
 	}
+	
+	QUndoCommand::undo();
 }
 
 /**
@@ -131,4 +151,6 @@
 	
 	for(QGraphicsItem *item : m_removed_contents.items())
 		m_diagram->removeItem(item);
+	
+	QUndoCommand::redo();
 }


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