diff --git a/sources/diagramcommands.cpp b/sources/diagramcommands.cpp index 4c9fc2635..4c7fa1ad1 100644 --- a/sources/diagramcommands.cpp +++ b/sources/diagramcommands.cpp @@ -1131,3 +1131,47 @@ void ImageResizerCommand::redo() { 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); +} diff --git a/sources/diagramcommands.h b/sources/diagramcommands.h index 66ead5404..ae81fc8e8 100644 --- a/sources/diagramcommands.h +++ b/sources/diagramcommands.h @@ -587,4 +587,19 @@ class ImageResizerCommand : public QUndoCommand { 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 diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index 3a9e1e6f4..b90605aac 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -92,6 +92,7 @@ class Element : public QetGraphicsItem { bool isFree () const; virtual void linkToElement(Element *) {} virtual void unlinkAllElements() {} + virtual void unlinkElement(Element *elmt) {} void initLink(QETProject *); QList linkedElements () const; diff --git a/sources/qetgraphicsitem/reportelement.cpp b/sources/qetgraphicsitem/reportelement.cpp index 2b1eca73e..f43dfc63c 100644 --- a/sources/qetgraphicsitem/reportelement.cpp +++ b/sources/qetgraphicsitem/reportelement.cpp @@ -77,6 +77,17 @@ void ReportElement::unlinkAllElements(){ } } } +/** + * @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 diff --git a/sources/qetgraphicsitem/reportelement.h b/sources/qetgraphicsitem/reportelement.h index 99d7a6538..7fc78006a 100644 --- a/sources/qetgraphicsitem/reportelement.h +++ b/sources/qetgraphicsitem/reportelement.h @@ -34,6 +34,7 @@ class ReportElement : public CustomElement { ~ReportElement(); virtual void linkToElement(Element *); virtual void unlinkAllElements(); + virtual void unlinkElement(Element *elmt); virtual int linkType() const; private: diff --git a/sources/ui/folioreportproperties.cpp b/sources/ui/folioreportproperties.cpp index ed3372891..57cf90494 100644 --- a/sources/ui/folioreportproperties.cpp +++ b/sources/ui/folioreportproperties.cpp @@ -4,6 +4,7 @@ #include #include #include +#include /** * @brief FolioReportProperties::FolioReportProperties : Construcor @@ -68,5 +69,7 @@ void FolioReportProperties::BuildRadioList() { * 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)); + } }