mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2863 bfdf4180-ca20-0410-9c96-a3a8aa849046
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);
|
|
}
|
|
}
|