2014-02-22 17:24:20 +00:00
|
|
|
/*
|
2020-06-15 17:42:37 +02:00
|
|
|
Copyright 2006-2020 The QElectroTech Team
|
2014-02-22 17:24:20 +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/>.
|
|
|
|
*/
|
|
|
|
#include "slaveelement.h"
|
2014-03-21 14:40:33 +00:00
|
|
|
#include "diagramposition.h"
|
|
|
|
#include "qetapp.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "diagram.h"
|
2018-01-19 12:17:20 +00:00
|
|
|
#include "dynamicelementtextitem.h"
|
2014-02-22 17:24:20 +00:00
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SlaveElement::SlaveElement
|
|
|
|
Default constructor
|
|
|
|
@param location location of xml definition
|
|
|
|
@param qgi parent QGraphicItem
|
|
|
|
@param state int used to know if the creation of element have error
|
|
|
|
*/
|
2020-08-19 21:27:14 +02:00
|
|
|
SlaveElement::SlaveElement(const ElementsLocation &location,
|
|
|
|
QGraphicsItem *qgi,
|
|
|
|
int *state) :
|
2018-11-10 12:19:30 +00:00
|
|
|
Element(location, qgi, state, Element::Slave)
|
2014-02-22 17:24:20 +00:00
|
|
|
{
|
2017-01-29 13:57:17 +00:00
|
|
|
m_xref_item = nullptr;
|
2015-12-30 09:39:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 17:24:20 +00:00
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SlaveElement::~SlaveElement
|
|
|
|
default destructor
|
|
|
|
*/
|
2014-02-22 17:24:20 +00:00
|
|
|
SlaveElement::~SlaveElement() {
|
|
|
|
unlinkAllElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SlaveElement::linkToElement
|
|
|
|
Link this slave to another element
|
|
|
|
For this class element must be a master
|
|
|
|
@param elmt
|
|
|
|
*/
|
2015-05-27 07:22:50 +00:00
|
|
|
void SlaveElement::linkToElement(Element *elmt)
|
|
|
|
{
|
|
|
|
// check if element is master and if isn't already linked
|
|
|
|
if (elmt->linkType() == Master && !connected_elements.contains(elmt))
|
|
|
|
{
|
2017-08-29 14:54:27 +00:00
|
|
|
if(!isFree())
|
|
|
|
unlinkAllElements();
|
|
|
|
|
2014-02-22 17:24:20 +00:00
|
|
|
connected_elements << elmt;
|
2014-11-01 11:09:58 +00:00
|
|
|
|
|
|
|
elmt -> linkToElement(this);
|
2015-05-27 07:22:50 +00:00
|
|
|
emit linkedElementChanged();
|
2014-02-22 17:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SlaveElement::unlinkAllElements
|
|
|
|
Unlink all of the element in the QList connected_elements
|
|
|
|
*/
|
2015-05-27 07:22:50 +00:00
|
|
|
void SlaveElement::unlinkAllElements()
|
|
|
|
{
|
|
|
|
// if this element is free no need to do something
|
|
|
|
if (!isFree())
|
|
|
|
{
|
2017-02-05 16:18:50 +00:00
|
|
|
foreach(Element *elmt, connected_elements)
|
2014-02-22 17:24:20 +00:00
|
|
|
unlinkElement(elmt);
|
2015-05-27 07:22:50 +00:00
|
|
|
emit linkedElementChanged();
|
2014-02-22 17:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-16 11:19:36 +02:00
|
|
|
@brief SlaveElement::unlinkElement
|
|
|
|
Unlink the given elmt in parametre
|
|
|
|
@param elmt
|
|
|
|
*/
|
2014-12-19 19:18:05 +00:00
|
|
|
void SlaveElement::unlinkElement(Element *elmt)
|
|
|
|
{
|
|
|
|
//Ensure elmt is linked to this element
|
|
|
|
if (connected_elements.contains(elmt))
|
|
|
|
{
|
2014-02-22 17:24:20 +00:00
|
|
|
connected_elements.removeOne(elmt);
|
2014-11-01 11:09:58 +00:00
|
|
|
|
2014-12-19 19:18:05 +00:00
|
|
|
elmt -> unlinkElement (this) ;
|
|
|
|
elmt -> setHighlighted (false);
|
2015-05-27 07:22:50 +00:00
|
|
|
emit linkedElementChanged();
|
2014-02-22 17:24:20 +00:00
|
|
|
}
|
|
|
|
}
|