mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Xref item: minor improvement
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3066 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -89,6 +89,27 @@ QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_p
|
|||||||
return txt;
|
return txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief CrossRefItem::allElementsPositionText
|
||||||
|
* Return the text of all elements linked to @m_element, in several QString
|
||||||
|
* according to the type of linked elements. Each text of elements are separate by "\n"
|
||||||
|
* @param no_str the string of NO contacts
|
||||||
|
* @param nc_str the string of NC contacts
|
||||||
|
* @param add_prefix must add prefix to text (true) or not (false);
|
||||||
|
*/
|
||||||
|
void CrossRefItem::allElementsPositionText(QString &no_str, QString &nc_str, const bool &add_prefix) const {
|
||||||
|
QString *tmp_str;
|
||||||
|
foreach (Element *elmt, m_element->linkedElements()) {
|
||||||
|
QString state = elmt->kindInformations()["state"].toString();
|
||||||
|
|
||||||
|
if (state == "NO") tmp_str = &no_str;
|
||||||
|
else if (state == "NC") tmp_str = &nc_str;
|
||||||
|
|
||||||
|
if (!tmp_str->isEmpty()) *tmp_str += "\n";
|
||||||
|
*tmp_str += elementPositionText(elmt, add_prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CrossRefItem::setProperties(const XRefProperties &xrp) {
|
void CrossRefItem::setProperties(const XRefProperties &xrp) {
|
||||||
if (m_properties != xrp) {
|
if (m_properties != xrp) {
|
||||||
m_properties = xrp;
|
m_properties = xrp;
|
||||||
@@ -256,16 +277,8 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) {
|
|||||||
//No need to calcul if nothing is linked
|
//No need to calcul if nothing is linked
|
||||||
if (!m_element->isFree()) {
|
if (!m_element->isFree()) {
|
||||||
|
|
||||||
QString no_str, nc_str, *tmp_str;
|
QString no_str, nc_str;
|
||||||
foreach (Element *elmt, m_element->linkedElements()) {
|
allElementsPositionText(no_str, nc_str, true);
|
||||||
QString state = elmt->kindInformations()["state"].toString();
|
|
||||||
|
|
||||||
if (state == "NO") tmp_str = &no_str;
|
|
||||||
else if (state == "NC") tmp_str = &nc_str;
|
|
||||||
|
|
||||||
if (!tmp_str->isEmpty()) *tmp_str += "\n";
|
|
||||||
*tmp_str += elementPositionText(elmt, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Adjust the size of default_bounding if needed.
|
//Adjust the size of default_bounding if needed.
|
||||||
//We calcule the size by using a single text
|
//We calcule the size by using a single text
|
||||||
@@ -435,46 +448,18 @@ void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
|
|||||||
void CrossRefItem::fillCrossRef(QPainter &painter) {
|
void CrossRefItem::fillCrossRef(QPainter &painter) {
|
||||||
if (m_element->isFree()) return;
|
if (m_element->isFree()) return;
|
||||||
|
|
||||||
QList <Element *> NO_list;
|
QString no_str, nc_str;
|
||||||
QList <Element *> NC_list;
|
allElementsPositionText(no_str, nc_str, true);
|
||||||
|
|
||||||
//find each no and nc of connected element to m_element
|
|
||||||
foreach (Element *elmt, m_element->linkedElements()) {
|
|
||||||
if (elmt->kindInformations()["type"].toString() == "power" && !m_properties.showPowerContact()) continue;
|
|
||||||
QString state = elmt->kindInformations()["state"].toString();
|
|
||||||
if (state == "NO") NO_list << elmt;
|
|
||||||
else if (state == "NC") NC_list << elmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
qreal middle_cross = m_bounding_rect.width()/2;
|
qreal middle_cross = m_bounding_rect.width()/2;
|
||||||
|
|
||||||
QString contact_str;
|
QRectF rect_(0, header, middle_cross, boundingRect().height()-header);
|
||||||
int i =0;
|
painter.drawText(rect_, Qt::AlignTop | Qt::AlignLeft, no_str);
|
||||||
//fill the NO
|
|
||||||
foreach (Element *elmt, NO_list) {
|
rect_.moveTopLeft(QPointF (middle_cross, header));
|
||||||
++i;
|
painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, nc_str);
|
||||||
contact_str += elementPositionText(elmt, true);
|
|
||||||
if(NO_list.size() > i) contact_str += "\n";
|
|
||||||
}
|
|
||||||
QRectF rect_(0,
|
|
||||||
header,
|
|
||||||
middle_cross,
|
|
||||||
m_bounding_rect.height()-header);
|
|
||||||
painter.drawText(rect_, Qt::AlignTop | Qt::AlignLeft, contact_str);
|
|
||||||
|
|
||||||
//fill the NC
|
|
||||||
contact_str.clear();
|
|
||||||
i = 0;
|
|
||||||
foreach (Element *elmt, NC_list) {
|
|
||||||
++i;
|
|
||||||
contact_str += elementPositionText(elmt, true);
|
|
||||||
if (NC_list.size() > i) contact_str += "\n";
|
|
||||||
}
|
|
||||||
rect_.setRect(middle_cross,
|
|
||||||
header,
|
|
||||||
middle_cross,
|
|
||||||
m_bounding_rect.height()-header);
|
|
||||||
painter.drawText(rect_, Qt::AlignTop | Qt::AlignRight, contact_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,3 +525,4 @@ void CrossRefItem::checkMustShow() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class CrossRefItem : public QGraphicsObject
|
|||||||
QRectF boundingRect () const;
|
QRectF boundingRect () const;
|
||||||
virtual QPainterPath shape () const;
|
virtual QPainterPath shape () const;
|
||||||
QString elementPositionText (const Element *elmt, const bool &add_prefix = false) const;
|
QString elementPositionText (const Element *elmt, const bool &add_prefix = false) const;
|
||||||
|
void allElementsPositionText (QString &no_str, QString &nc_str,const bool &add_prefix = false) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@@ -87,3 +88,4 @@ class CrossRefItem : public QGraphicsObject
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif // CROSSREFITEM_H
|
#endif // CROSSREFITEM_H
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user