[qet] [2716] add undo command for linkable element

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


Revision: 2716
Author:   blacksun
Date:     2014-01-07 21:11:28 +0100 (Tue, 07 Jan 2014)
Log Message:
-----------
add undo command for linkable element

Modified Paths:
--------------
    trunk/sources/diagramcommands.cpp
    trunk/sources/diagramcommands.h
    trunk/sources/qetgraphicsitem/element.h
    trunk/sources/qetgraphicsitem/reportelement.cpp
    trunk/sources/qetgraphicsitem/reportelement.h
    trunk/sources/ui/folioreportproperties.cpp

Modified: trunk/sources/diagramcommands.cpp
===================================================================
--- trunk/sources/diagramcommands.cpp	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/diagramcommands.cpp	2014-01-07 20:11:28 UTC (rev 2716)
@@ -1131,3 +1131,47 @@
 	else setText(QObject::tr("R\351duire une image \340 %1 %").arg(new_size*100));
 	image_ -> setScale(new_size);
 }
+
+/**
+ * @brief LinkElementsCommand::LinkElementsCommand
+ *Constructor
+ * @param elmt1 element to Link
+ * @param elmt2 element to link
+ * @param parent parent undo command
+ */
+LinkElementsCommand::LinkElementsCommand(Element *elmt1, Element *elmt2, QUndoCommand *parent) :
+	QUndoCommand(parent),
+	diagram_(elmt1->diagram()),
+	elmt_1(elmt1),
+	elmt_2(elmt2)
+{
+	if (elmt1->linkType() & Element::AllReport &&
+		elmt2->linkType() & Element::AllReport)
+		setText(QObject::tr("Lier deux reports de folio",
+							"title for undo LinkElementsCommand if two elements are folio report"));
+	else setText(QObject::tr("Lier deux éléments"));
+}
+
+/**
+ * @brief LinkElementsCommand::~LinkElementsCommand
+ *destructor
+ */
+LinkElementsCommand::~LinkElementsCommand(){}
+
+/**
+ * @brief LinkElementsCommand::undo
+ *Undo command
+ */
+void LinkElementsCommand::undo() {
+	diagram_->showMe();
+	elmt_1->unlinkElement(elmt_2);
+}
+
+/**
+ * @brief LinkElementsCommand::redo
+ *redo command
+ */
+void LinkElementsCommand::redo() {
+	diagram_->showMe();
+	elmt_1->linkToElement(elmt_2);
+}

Modified: trunk/sources/diagramcommands.h
===================================================================
--- trunk/sources/diagramcommands.h	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/diagramcommands.h	2014-01-07 20:11:28 UTC (rev 2716)
@@ -587,4 +587,19 @@
 	Diagram *diagram;
 };
 
+class LinkElementsCommand : public QUndoCommand {
+	public:
+	// constructor destructor
+	LinkElementsCommand (Element *elmt1, Element *elmt2, QUndoCommand *parent = 0);
+	virtual ~LinkElementsCommand();
+	//methods
+	virtual void undo();
+	virtual void redo();
+
+	private:
+	//attributes
+	Diagram*diagram_;
+	Element *elmt_1, *elmt_2;
+};
+
 #endif

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/qetgraphicsitem/element.h	2014-01-07 20:11:28 UTC (rev 2716)
@@ -92,6 +92,7 @@
 	bool isFree () const;
 	virtual void linkToElement(Element *) {}
 	virtual void unlinkAllElements() {}
+	virtual void unlinkElement(Element *elmt) {}
 	void initLink(QETProject *);
 	QList<Element *> linkedElements () const;
 

Modified: trunk/sources/qetgraphicsitem/reportelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.cpp	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/qetgraphicsitem/reportelement.cpp	2014-01-07 20:11:28 UTC (rev 2716)
@@ -77,6 +77,17 @@
 		}
 	}
 }
+/**
+ * @brief ReportElement::unlinkElement
+ *unlink the specified element.
+ *for reportelement, they must be only one linked element, so we call
+ *unlinkAllElements for clear the connected_elements list.
+ * @param elmt
+ */
+void ReportElement::unlinkElement(Element *elmt) {
+	Q_UNUSED (elmt);
+	unlinkAllElements();
+}
 
 /**
  * @brief ReportElement::linkType

Modified: trunk/sources/qetgraphicsitem/reportelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/reportelement.h	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/qetgraphicsitem/reportelement.h	2014-01-07 20:11:28 UTC (rev 2716)
@@ -34,6 +34,7 @@
 	~ReportElement();
 	virtual void linkToElement(Element *);
 	virtual void unlinkAllElements();
+	virtual void unlinkElement(Element *elmt);
 	virtual int linkType() const;
 
 	private:

Modified: trunk/sources/ui/folioreportproperties.cpp
===================================================================
--- trunk/sources/ui/folioreportproperties.cpp	2014-01-07 13:40:32 UTC (rev 2715)
+++ trunk/sources/ui/folioreportproperties.cpp	2014-01-07 20:11:28 UTC (rev 2716)
@@ -4,6 +4,7 @@
 #include <diagramposition.h>
 #include <elementprovider.h>
 #include <qetgraphicsitem/elementtextitem.h>
+#include <diagramcommands.h>
 
 /**
  * @brief FolioReportProperties::FolioReportProperties : Construcor
@@ -68,5 +69,7 @@
  * Apply the new properties for this folio report
  */
 void FolioReportProperties::Apply() {
-	if (element_to_link) element_to_link->linkToElement(element_);
+	if (element_to_link) {
+		element_->diagram()->undoStack().push(new LinkElementsCommand(element_, element_to_link));
+	}
 }


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