mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-08 06:42:34 +01:00
Cross ref item, check properties for show power contacts or not.
Change properties in project is applied immediately to cross ref git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2985 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -54,15 +54,15 @@ void MasterElement::linkToElement(Element *elmt) {
|
||||
connected_elements << elmt;
|
||||
elmt->linkToElement(this);
|
||||
|
||||
if (elmt->kindInformations()["type"].toString() != "power") {
|
||||
if (!cri_) {
|
||||
if (elmt->kindInformations()["type"].toString() == "power" && !diagram()->defaultXRefProperties().showPowerContact()) return;
|
||||
|
||||
if (!cri_) {
|
||||
cri_ = new CrossRefItem(this); //create cross ref item if not yet
|
||||
diagram()->addItem(cri_);
|
||||
}
|
||||
connect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
|
||||
cri_->updateLabel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +92,17 @@ void MasterElement::unlinkElement(Element *elmt) {
|
||||
disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
|
||||
|
||||
bool delete_cri = true;
|
||||
foreach(Element *elmt, linkedElements())
|
||||
if (elmt->kindInformations()["type"].toString() != "power") delete_cri = false;
|
||||
|
||||
//if power contact isn't show, make sure they are only power contacts linked
|
||||
//or nothing befor remove cri_
|
||||
if (!diagram()->defaultXRefProperties().showPowerContact()) {
|
||||
foreach(Element *elmt, linkedElements())
|
||||
if (elmt->kindInformations()["type"].toString() != "power") delete_cri = false;
|
||||
}
|
||||
//else only make sur list is empty
|
||||
else {
|
||||
if (!linkedElements().isEmpty()) delete_cri = false;
|
||||
}
|
||||
|
||||
if (delete_cri) {
|
||||
diagram()->removeItem(cri_);
|
||||
@@ -106,6 +115,25 @@ void MasterElement::unlinkElement(Element *elmt) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MasterElement::itemChange
|
||||
* Réimplemente the protected method item change
|
||||
* This is used to make connection/disconnection when this item is added/removed from a diagram
|
||||
* @return
|
||||
*/
|
||||
QVariant MasterElement::itemChange(GraphicsItemChange change, const QVariant &value) {
|
||||
if (change == QGraphicsItem::ItemSceneChange) {
|
||||
if (diagram())
|
||||
disconnect(diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(reLink()));
|
||||
}
|
||||
else if (change == QGraphicsItem::ItemSceneHasChanged) {
|
||||
if (diagram())
|
||||
connect(diagram(), SIGNAL(XRefPropertiesChanged(XRefProperties)), this, SLOT(reLink()));
|
||||
}
|
||||
return QetGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief MasterElement::updateLabel
|
||||
* update label of this element
|
||||
@@ -119,3 +147,17 @@ void MasterElement::updateLabel() {
|
||||
setTaggedText("label", "_", false):
|
||||
setTaggedText("label", label, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief MasterElement::reLink
|
||||
* Relink all linked element.
|
||||
* this method is notably used when xref properties changes
|
||||
* for update the content of th e XRef
|
||||
*/
|
||||
void MasterElement::reLink() {
|
||||
QList <Element *> elmt_list = linkedElements();
|
||||
unlinkAllElements();
|
||||
foreach (Element *elmt, elmt_list) {
|
||||
linkToElement(elmt);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user