QElectroTech  0.70
reportelement.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 "reportelement.h"
19 #include "diagramposition.h"
20 #include "qetproject.h"
21 #include "diagram.h"
22 #include "terminal.h"
23 #include "conductor.h"
24 #include "dynamicelementtextitem.h"
25 
26 ReportElement::ReportElement(const ElementsLocation &location, const QString& link_type,QGraphicsItem *qgi, int *state) :
27  Element(location, qgi, state,
28  link_type == "next_report"? Element::NextReport : Element::PreviousReport),
29  m_inverse_report(link_type == "next_report"? Element::PreviousReport : Element::NextReport)
30 {}
31 
37 {
39  if (terminals().size())
40  disconnect(terminals().first(), nullptr, nullptr, nullptr);
41 }
42 
50 {
51  if (!diagram() && !elmt -> diagram())
52  {
53  qDebug() << "ReportElement : linkToElement : Unable to link this or element to link isn't in a diagram";
54  return;
55  }
56 
57  //ensure elmt isn't already linked
58  bool i = true;
59  if (!this -> isFree() && (connected_elements.first() == elmt))
60  i = false;
61 
62  //ensure elmt is an inverse report of this element
63  if ((elmt->linkType() == m_inverse_report) && i)
64  {
66  connected_elements << elmt;
67  elmt->linkToElement(this);
68  emit linkedElementChanged();
69  }
70 }
71 
77 {
78  if (isFree())
79  return;
80 
81  const QList <Element *> tmp_elmt = connected_elements;
82 
83  for (Element *elmt : tmp_elmt)
84  connected_elements.removeAll(elmt);
85 
86  for(Element *elmt : tmp_elmt)
87  {
88  elmt -> setHighlighted(false);
89  elmt -> unlinkAllElements();
90  }
91 
92  emit linkedElementChanged();
93 }
102  Q_UNUSED (elmt);
104 }
virtual void linkToElement(Element *)
Definition: element.h:133
QSize size() const
Definition: element.cpp:229
virtual kind linkType() const
Definition: element.h:138
QList< Element * > connected_elements
Definition: element.h:171
bool isFree() const
Definition: element.h:201
Diagram * diagram() const
QetGraphicsItem::diagram return the diagram of this item.
virtual void setHighlighted(bool)
Definition: element.cpp:162
void linkedElementChanged()
~ReportElement() override
ReportElement::~ReportElement Destructor.
QList< Terminal * > terminals() const
Element::terminals.
Definition: element.cpp:124
ReportElement(const ElementsLocation &, const QString &link_type, QGraphicsItem *=nullptr, int *=nullptr)
void unlinkElement(Element *elmt) override
ReportElement::unlinkElement unlink the specified element. for reportelement, they must be only one l...
void linkToElement(Element *) override
ReportElement::linkToElement Link this element to the other element.
void unlinkAllElements() override
ReportElement::unLinkAllElements Unlink all of the element in the QList connected_elements.