mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-14 20:33:05 +02:00
68 lines
1.7 KiB
C++
68 lines
1.7 KiB
C++
|
#include "masterelement.h"
|
||
|
|
||
|
/**
|
||
|
* @brief MasterElement::MasterElement
|
||
|
* Default constructor
|
||
|
* @param location location of xml definition
|
||
|
* @param qgi parent QGraphicItem
|
||
|
* @param s parent diagram
|
||
|
* @param state int used to know if the creation of element have error
|
||
|
*/
|
||
|
MasterElement::MasterElement(const ElementsLocation &location, QGraphicsItem *qgi, Diagram *s, int *state) :
|
||
|
CustomElement(location, qgi, s, state)
|
||
|
{
|
||
|
link_type_ = Master;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief MasterElement::~MasterElement
|
||
|
* default destructor
|
||
|
*/
|
||
|
MasterElement::~MasterElement() {
|
||
|
unlinkAllElements();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief MasterElement::linkToElement
|
||
|
* Link this master to another element
|
||
|
* For this class element must be a slave
|
||
|
* @param elmt
|
||
|
*/
|
||
|
void MasterElement::linkToElement(Element *elmt) {
|
||
|
// check if this element is already linked
|
||
|
if (connected_elements.contains(elmt)) return;
|
||
|
|
||
|
//check if elmt is a slave
|
||
|
if (elmt->linkType() == SlaveNO || elmt->linkType() == SlaveNC) {
|
||
|
///TODO create the cross ref and connection
|
||
|
connected_elements << elmt;
|
||
|
elmt->linkToElement(this);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief MasterElement::unlinkAllElements
|
||
|
* Unlink all of the element in the QList connected_elements
|
||
|
*/
|
||
|
void MasterElement::unlinkAllElements() {
|
||
|
// if this element is free no need to do something
|
||
|
if (!isFree()) {
|
||
|
foreach(Element *elmt, connected_elements) {
|
||
|
unlinkElement(elmt);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief MasterElement::unlinkElement
|
||
|
* Unlink the given elmt in parametre
|
||
|
* @param elmt element to unlink from this
|
||
|
*/
|
||
|
void MasterElement::unlinkElement(Element *elmt) {
|
||
|
//Ensure elmt is linked to this element
|
||
|
if (connected_elements.contains(elmt)) {
|
||
|
connected_elements.removeOne(elmt);
|
||
|
elmt->unlinkElement(this);
|
||
|
}
|
||
|
}
|