2014-02-22 17:24:20 +00:00
|
|
|
/*
|
2017-01-20 10:55:49 +00:00
|
|
|
Copyright 2006-2017 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"
|
|
|
|
#include "elementtextitem.h"
|
2014-07-21 20:44:32 +00:00
|
|
|
#include "diagram.h"
|
2014-02-22 17:24:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SlaveElement::SlaveElement
|
|
|
|
* 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
|
|
|
|
*/
|
2014-12-14 13:06:21 +00:00
|
|
|
SlaveElement::SlaveElement(const ElementsLocation &location, QGraphicsItem *qgi, int *state) :
|
|
|
|
CustomElement(location, qgi, state)
|
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
|
|
|
link_type_ = Slave;
|
2016-07-13 21:25:29 +00:00
|
|
|
connect(this, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
|
2015-12-30 09:39:22 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 17:24:20 +00:00
|
|
|
/**
|
|
|
|
* @brief SlaveElement::~SlaveElement
|
|
|
|
* default destructor
|
|
|
|
*/
|
|
|
|
SlaveElement::~SlaveElement() {
|
|
|
|
unlinkAllElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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))
|
|
|
|
{
|
2014-02-22 17:24:20 +00:00
|
|
|
if(!isFree()) unlinkAllElements();
|
2016-07-13 21:25:29 +00:00
|
|
|
this->disconnect();
|
2014-02-22 17:24:20 +00:00
|
|
|
connected_elements << elmt;
|
2014-11-01 11:09:58 +00:00
|
|
|
|
|
|
|
connect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
|
|
|
|
connect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
|
2014-11-24 18:17:20 +00:00
|
|
|
connect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)),this, SLOT(updateLabel()));
|
2014-11-01 11:09:58 +00:00
|
|
|
connect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
|
2014-11-01 22:01:59 +00:00
|
|
|
connect(diagram()->project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
|
2016-05-21 21:30:14 +00:00
|
|
|
connect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel()));
|
2016-07-05 20:14:14 +00:00
|
|
|
connect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
|
2014-11-01 11:09:58 +00:00
|
|
|
|
2014-03-21 14:40:33 +00:00
|
|
|
updateLabel();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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())
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
|
|
|
disconnect(elmt, SIGNAL(xChanged()), this, SLOT(updateLabel()));
|
|
|
|
disconnect(elmt, SIGNAL(yChanged()), this, SLOT(updateLabel()));
|
2014-11-24 18:17:20 +00:00
|
|
|
disconnect(elmt, SIGNAL(elementInfoChange(DiagramContext, DiagramContext)),this, SLOT(updateLabel()));
|
2014-11-01 11:09:58 +00:00
|
|
|
disconnect(diagram()->project(), SIGNAL(projectDiagramsOrderChanged(QETProject*,int,int)), this, SLOT(updateLabel()));
|
2014-11-01 22:01:59 +00:00
|
|
|
disconnect(diagram()->project(), SIGNAL(diagramRemoved(QETProject*,Diagram*)), this, SLOT(updateLabel()));
|
2016-05-22 00:42:52 +00:00
|
|
|
disconnect(elmt -> diagram(), SIGNAL(XRefPropertiesChanged()), this, SLOT(updateLabel()));
|
2016-07-05 20:14:14 +00:00
|
|
|
disconnect(elmt, SIGNAL(updateLabel()), this, SLOT(updateLabel()));
|
2014-11-01 11:09:58 +00:00
|
|
|
|
2017-01-29 13:57:17 +00:00
|
|
|
delete m_xref_item; m_xref_item = NULL;
|
|
|
|
|
|
|
|
if (ElementTextItem *eti = this->taggedText("label"))
|
|
|
|
eti->setPlainText("_");
|
|
|
|
|
2014-03-21 14:40:33 +00:00
|
|
|
updateLabel();
|
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
|
|
|
}
|
|
|
|
}
|
2014-03-21 14:40:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SlaveElement::updateLabel
|
|
|
|
* update the label (tagged with label) of this element.
|
|
|
|
* If this element is connected to a master,
|
|
|
|
* the label show the string tagged by "label" of the master
|
|
|
|
* and add a qgraphicstextitem for show the position of the master
|
|
|
|
*/
|
2016-07-17 10:16:37 +00:00
|
|
|
void SlaveElement::updateLabel()
|
|
|
|
{
|
|
|
|
QString label;
|
|
|
|
if (ElementTextItem *eti = this->taggedText("label"))
|
|
|
|
label = eti->toPlainText();
|
2014-03-21 14:40:33 +00:00
|
|
|
QString Xreflabel;
|
|
|
|
bool no_editable = false;
|
|
|
|
|
|
|
|
//must be linked to set the label of master
|
2016-11-09 16:06:04 +00:00
|
|
|
if (linkedElements().count())
|
|
|
|
{
|
2014-03-21 14:40:33 +00:00
|
|
|
no_editable = true;
|
|
|
|
Element *elmt = linkedElements().first();
|
|
|
|
label = elmt -> elementInformations()["label"].toString();
|
2016-05-23 22:01:22 +00:00
|
|
|
XRefProperties xrp = elmt->diagram()->defaultXRefProperties(elmt->kindInformations()["type"].toString());
|
|
|
|
Xreflabel = xrp.slaveLabel();
|
2016-11-09 16:06:04 +00:00
|
|
|
Xreflabel = autonum::AssignVariables::formulaToLabel(Xreflabel, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
|
|
|
label = autonum::AssignVariables::formulaToLabel(label, elmt->rSequenceStruct(), elmt->diagram(), elmt);
|
2014-03-21 14:40:33 +00:00
|
|
|
}
|
2017-01-29 13:57:17 +00:00
|
|
|
else
|
|
|
|
label = autonum::AssignVariables::formulaToLabel(label, m_autoNum_seq, diagram(), this);
|
2014-03-21 14:40:33 +00:00
|
|
|
|
|
|
|
// set the new label
|
|
|
|
ElementTextItem *eti = setTaggedText("label", label, no_editable);
|
2017-01-29 13:57:17 +00:00
|
|
|
if (eti && !isFree())
|
|
|
|
{
|
|
|
|
if (m_xref_item)
|
|
|
|
m_xref_item->setPlainText(Xreflabel);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_xref_item = new QGraphicsTextItem(Xreflabel, eti);
|
|
|
|
m_xref_item->setFont(QETApp::diagramTextsFont(5));
|
|
|
|
m_xref_item->setPos(eti -> boundingRect().bottomLeft());
|
2014-03-21 14:40:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|