2015-06-08 18:18:35 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2015-06-08 18:18:35 +00:00
|
|
|
This file is part of QElectroTech.
|
|
|
|
|
|
|
|
QElectroTech is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
QElectroTech is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#ifndef LINKELEMENTCOMMAND_H
|
|
|
|
#define LINKELEMENTCOMMAND_H
|
|
|
|
|
|
|
|
#include <QUndoCommand>
|
|
|
|
|
|
|
|
class Element;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The LinkElementCommand class
|
|
|
|
* This undo class manage link between elements.
|
|
|
|
* In the same instance of this class, we can link and unlink elements from an edited element
|
|
|
|
* This undo class support the merge.
|
|
|
|
*/
|
|
|
|
class LinkElementCommand : public QUndoCommand
|
|
|
|
{
|
|
|
|
public:
|
2017-08-05 02:06:59 +00:00
|
|
|
LinkElementCommand(Element *element_, QUndoCommand *parent = nullptr);
|
2015-06-08 18:18:35 +00:00
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
int id() const override {return 2;}
|
|
|
|
bool mergeWith(const QUndoCommand *other) override;
|
2015-06-08 18:18:35 +00:00
|
|
|
|
|
|
|
static bool isLinkable (Element *element_a, Element *element_b, bool already_linked = false);
|
|
|
|
|
2018-07-19 14:14:31 +00:00
|
|
|
void setLink (const QList<Element *>& element_list);
|
2015-06-08 18:18:35 +00:00
|
|
|
void setLink (Element *element_);
|
|
|
|
void unlink (QList<Element *> element_list);
|
|
|
|
void unlinkAll ();
|
|
|
|
|
2017-08-05 02:10:01 +00:00
|
|
|
void undo() override;
|
|
|
|
void redo() override;
|
2015-06-08 18:18:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setUpNewLink (const QList<Element *> &element_list, bool already_link);
|
|
|
|
void makeLink (const QList <Element *> &element_list);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Element *m_element;
|
2015-06-16 08:26:03 +00:00
|
|
|
bool m_first_redo;
|
2015-06-08 18:18:35 +00:00
|
|
|
QList<Element *> m_linked_before; //<Linked elements before this command, or when we call "undo"
|
|
|
|
QList<Element *> m_linked_after; //<Linked elements after this command, or when we recall "redo"
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LINKELEMENTCOMMAND_H
|