QElectroTech  0.70
linkelementcommand.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef LINKELEMENTCOMMAND_H
19 #define LINKELEMENTCOMMAND_H
20 
21 #include <QUndoCommand>
22 
23 class Element;
24 
31 class LinkElementCommand : public QUndoCommand
32 {
33  public:
34  LinkElementCommand(Element *element_, QUndoCommand *parent = nullptr);
35 
36  int id() const override {return 2;}
37  bool mergeWith(const QUndoCommand *other) override;
38 
39  static bool isLinkable (Element *element_a, Element *element_b, bool already_linked = false);
40 
41  void setLink (const QList<Element *>& element_list);
42  void setLink (Element *element_);
43  void unlink (QList<Element *> element_list);
44  void unlinkAll ();
45 
46  void undo() override;
47  void redo() override;
48 
49  private:
50  void setUpNewLink (const QList<Element *> &element_list, bool already_link);
51  void makeLink (const QList <Element *> &element_list);
52 
53  private:
56  QList<Element *> m_linked_before; //<Linked elements before this command, or when we call "undo"
57  QList<Element *> m_linked_after; //<Linked elements after this command, or when we recall "redo"
58 };
59 
60 #endif // LINKELEMENTCOMMAND_H
void unlink(QList< Element *> element_list)
LinkElementCommand::unlink Unlink all elements of element_list from the edited element.
void setUpNewLink(const QList< Element *> &element_list, bool already_link)
LinkElementCommand::setUpNewLink Update the content of m_link_after with the content of ...
void makeLink(const QList< Element *> &element_list)
LinkElementCommand::makeLink Make the link between m_element and element_list; This method unlink ele...
bool mergeWith(const QUndoCommand *other) override
LinkElementCommand::mergeWith.
QList< Element * > m_linked_before
void unlinkAll()
LinkElementCommand::unlinkAll Unlink all element of the edited element.
The LinkElementCommand class This undo class manage link between elements. In the same instance of th...
void undo() override
LinkElementCommand::undo Undo this command.
void redo() override
LinkElementCommand::redo Redo this command.
static bool isLinkable(Element *element_a, Element *element_b, bool already_linked=false)
LinkElementCommand::isLinkable.
int id() const override
LinkElementCommand(Element *element_, QUndoCommand *parent=nullptr)
LinkElementCommand::LinkElementCommand Constructor.
void setLink(const QList< Element *> &element_list)
LinkElementCommand::setLink Replace all linked elements of edited element by elements stored in This...
QList< Element * > m_linked_after