QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
linkelementcommand.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2026 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#include <QMap>
23
24class Element;
25
32class LinkElementCommand : public QUndoCommand
33{
34 public:
35 LinkElementCommand(Element *element_, QUndoCommand *parent = nullptr);
36
37 int id() const override {return 2;}
38 bool mergeWith(const QUndoCommand *other) override;
39
40 static bool isLinkable (Element *element_a, Element *element_b, bool already_linked = false);
41
42 void setLink (const QList<Element *>& element_list);
43 void setLink (Element *element_);
44 void unlink (QList<Element *> element_list);
45 void unlinkAll ();
46 void setGroupIndex(int index) { m_group_index = index; }
47 void setGroupIndices(const QMap<Element*, int> &indices) { m_group_indices = indices; }
48
49 void undo() override;
50 void redo() override;
51
52 private:
53 void setUpNewLink (const QList<Element *> &element_list, bool already_link);
54 void makeLink (const QList <Element *> &element_list);
55
56 private:
59 int m_group_index = -1;
60 QMap<Element*, int> m_group_indices;
61 QList<Element *> m_linked_before; //<Linked elements before this command, or when we call "undo"
62 QList<Element *> m_linked_after; //<Linked elements after this command, or when we recall "redo"
63};
64
65#endif // LINKELEMENTCOMMAND_H
Definition element.h:44