[qet] [3042] improve behavior of Xref item (must show or not the power contact) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3042
Author: blacksun
Date: 2014-05-02 20:14:42 +0200 (Fri, 02 May 2014)
Log Message:
-----------
improve behavior of Xref item (must show or not the power contact)
Modified Paths:
--------------
trunk/sources/qetgraphicsitem/crossrefitem.cpp
trunk/sources/qetgraphicsitem/crossrefitem.h
trunk/sources/qetgraphicsitem/masterelement.cpp
Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-04-30 20:38:02 UTC (rev 3041)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-05-02 18:14:42 UTC (rev 3042)
@@ -105,6 +105,7 @@
autoPos();
update();
+ checkMustShow();
}
/**
@@ -467,3 +468,41 @@
painter.restore();
}
}
+
+/**
+ * @brief CrossRefItem::checkMustShow
+ * Check the propertie of this Xref for know if we
+ * must to be show or not
+ */
+void CrossRefItem::checkMustShow() {
+
+ //We always show Xref when is displayed has contact
+ if (m_properties.displayHas() == XRefProperties::Contacts) {
+ this->show();
+ return;
+ }
+
+ //if Xref is display has cross and we must to don't show power contact, check it
+ else if (m_properties.displayHas() == XRefProperties::Cross && !m_properties.showPowerContact()) {
+ bool power = false;
+ foreach (Element *elmt, m_element->linkedElements()) {
+ // contact checked isn't power, show this xref and return;
+ if (elmt->kindInformations()["type"].toString() != "power") {
+ this->show();
+ return;
+ } else {
+ power = true;
+ }
+ }
+ if (power) {
+ this->hide();
+ return;
+ }
+ }
+
+ //By default, show this Xref
+ else {
+ this->show();
+ return;
+ }
+}
Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h 2014-04-30 20:38:02 UTC (rev 3041)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h 2014-05-02 18:14:42 UTC (rev 3042)
@@ -72,6 +72,7 @@
void drawContact (QPainter &painter, int flags, QString str = QString());
void fillCrossRef (QPainter &painter);
void AddExtraInfo (QPainter &painter);
+ void checkMustShow ();
//Attributes
private:
Modified: trunk/sources/qetgraphicsitem/masterelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/masterelement.cpp 2014-04-30 20:38:02 UTC (rev 3041)
+++ trunk/sources/qetgraphicsitem/masterelement.cpp 2014-05-02 18:14:42 UTC (rev 3042)
@@ -54,8 +54,6 @@
connected_elements << elmt;
elmt->linkToElement(this);
- 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_);
@@ -89,32 +87,17 @@
connected_elements.removeOne(elmt);
elmt->unlinkElement(this);
- if (cri_) {
- //update the graphics cross ref
- disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
+ //update the graphics cross ref
+ disconnect(elmt, SIGNAL(positionChange(QPointF)), cri_, SLOT(updateLabel()));
- bool delete_cri = true;
-
- //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_);
- delete cri_;
- cri_ = 0;
- }
- else {
- cri_->updateLabel();
- }
+ if (linkedElements().isEmpty()) {
+ diagram()->removeItem(cri_);
+ delete cri_;
+ cri_ = 0;
}
+ else {
+ cri_->updateLabel();
+ }
}
}