QElectroTech  0.70
slaveelement.cpp
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 #include "slaveelement.h"
19 #include "diagramposition.h"
20 #include "qetapp.h"
21 #include "diagram.h"
22 #include "dynamicelementtextitem.h"
23 
32 SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
33  Element(location, qgi, state, Element::Slave)
34 {
35  m_xref_item = nullptr;
36 }
37 
44 }
45 
53 {
54  // check if element is master and if isn't already linked
55  if (elmt->linkType() == Master && !connected_elements.contains(elmt))
56  {
57  if(!isFree())
59 
60  connected_elements << elmt;
61 
62  elmt -> linkToElement(this);
63  emit linkedElementChanged();
64  }
65 }
66 
72 {
73  // if this element is free no need to do something
74  if (!isFree())
75  {
76  foreach(Element *elmt, connected_elements)
77  unlinkElement(elmt);
78  emit linkedElementChanged();
79  }
80 }
81 
88 {
89  //Ensure elmt is linked to this element
90  if (connected_elements.contains(elmt))
91  {
92  connected_elements.removeOne(elmt);
93 
94  elmt -> unlinkElement (this) ;
95  elmt -> setHighlighted (false);
96  emit linkedElementChanged();
97  }
98 }
virtual kind linkType() const
Definition: element.h:138
SlaveElement(const ElementsLocation &, QGraphicsItem *=nullptr, int *=nullptr)
SlaveElement::SlaveElement Default constructor.
QList< Element * > connected_elements
Definition: element.h:171
bool isFree() const
Definition: element.h:201
void linkToElement(Element *elmt) override
SlaveElement::linkToElement Link this slave to another element For this class element must be a maste...
virtual void setHighlighted(bool)
Definition: element.cpp:162
void linkedElementChanged()
void unlinkAllElements() override
SlaveElement::unlinkAllElements Unlink all of the element in the QList connected_elements.
~SlaveElement() override
SlaveElement::~SlaveElement default destructor.
void unlinkElement(Element *elmt) override
SlaveElement::unlinkElement Unlink the given elmt in parametre.
QGraphicsTextItem * m_xref_item
Definition: slaveelement.h:35