add undo command for linkable element

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2716 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2014-01-07 20:11:28 +00:00
parent b1704f8260
commit 6e58482495
6 changed files with 76 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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<Element *> linkedElements () const;

View File

@@ -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

View File

@@ -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:

View File

@@ -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 @@ 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));
}
}