[qet] [3033] Cross ref item: user can select if xref must be displayed has a table or a contacts list. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 3033
Author: blacksun
Date: 2014-04-28 17:41:58 +0200 (Mon, 28 Apr 2014)
Log Message:
-----------
Cross ref item: user can select if xref must be displayed has a table or a contacts list.
Option is found in config dialog under the tab Cross ref.
Modified Paths:
--------------
trunk/sources/projectconfigpages.cpp
trunk/sources/properties/xrefproperties.cpp
trunk/sources/properties/xrefproperties.h
trunk/sources/qetgraphicsitem/crossrefitem.cpp
trunk/sources/qetgraphicsitem/crossrefitem.h
trunk/sources/ui/xrefpropertieswidget.cpp
trunk/sources/ui/xrefpropertieswidget.ui
Modified: trunk/sources/projectconfigpages.cpp
===================================================================
--- trunk/sources/projectconfigpages.cpp 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/projectconfigpages.cpp 2014-04-28 15:41:58 UTC (rev 3033)
@@ -288,7 +288,7 @@
conductor_ = new ConductorPropertiesWidget();
conductor_ -> setContentsMargins(0, 0, 0, 0);
report_ = new ReportPropertieWidget("_");
- xref_ = new XRefPropertiesWidget();
+ xref_ = new XRefPropertiesWidget(XRefProperties());
}
/**
Modified: trunk/sources/properties/xrefproperties.cpp
===================================================================
--- trunk/sources/properties/xrefproperties.cpp 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/properties/xrefproperties.cpp 2014-04-28 15:41:58 UTC (rev 3033)
@@ -33,6 +33,8 @@
*/
void XRefProperties::toSettings(QSettings &settings, const QString prefix) const {
settings.setValue(prefix + "showpowerctc", m_show_power_ctc);
+ QString display = m_display == Cross? "cross" : "contacts";
+ settings.setValue(prefix + "displayhas", display);
}
/**
@@ -43,6 +45,8 @@
*/
void XRefProperties::fromSettings(const QSettings &settings, const QString prefix) {
m_show_power_ctc = settings.value(prefix + "showpowerctc", false).toBool();
+ QString display = settings.value(prefix + "displayhas", "cross").toString();
+ display == "cross"? m_display = Cross : m_display = Contacts;
}
/**
@@ -52,6 +56,8 @@
*/
void XRefProperties::toXml(QDomElement &xml_element) const {
xml_element.setAttribute("showpowerctc", m_show_power_ctc? "true" : "fasle");
+ QString display = m_display == Cross? "cross" : "contacts";
+ xml_element.setAttribute("displayhas", display);
}
/**
@@ -61,10 +67,13 @@
*/
void XRefProperties::fromXml(const QDomElement &xml_element) {
m_show_power_ctc = xml_element.attribute("showpowerctc") == "true";
+ QString display = xml_element.attribute("displayhas", "cross");
+ display == "cross"? m_display = Cross : m_display = Contacts;
}
bool XRefProperties::operator ==(const XRefProperties &xrp) const{
- return (m_show_power_ctc == xrp.m_show_power_ctc);
+ return (m_show_power_ctc == xrp.m_show_power_ctc &&
+ m_display == xrp.m_display);
}
bool XRefProperties::operator !=(const XRefProperties &xrp) const {
Modified: trunk/sources/properties/xrefproperties.h
===================================================================
--- trunk/sources/properties/xrefproperties.h 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/properties/xrefproperties.h 2014-04-28 15:41:58 UTC (rev 3033)
@@ -29,6 +29,11 @@
public:
XRefProperties();
+ enum DisplayHas {
+ Cross,
+ Contacts
+ };
+
virtual void toSettings (QSettings &settings, const QString = QString()) const;
virtual void fromSettings (const QSettings &settings, const QString = QString());
virtual void toXml (QDomElement &xml_element) const;
@@ -40,8 +45,12 @@
void setShowPowerContac (const bool a) {m_show_power_ctc = a;}
bool showPowerContact () const {return m_show_power_ctc;}
+ void setDisplayHas (const DisplayHas dh) {m_display = dh;}
+ DisplayHas displayHas () const {return m_display;}
+
private:
bool m_show_power_ctc;
+ DisplayHas m_display;
};
#endif // XREFPROPERTIES_H
Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp 2014-04-28 15:41:58 UTC (rev 3033)
@@ -84,50 +84,14 @@
pen_.setWidthF(0.2);
qp.setPen(pen_);
- //calcul the size of the cross
- setUpCrossBoundingRect();
+ XRefProperties::DisplayHas dh = m_properties.displayHas();
+ if (dh == XRefProperties::Cross) {
+ drawHasCross(qp);
+ }
+ else if (dh == XRefProperties::Contacts) {
+ drawHasContacts(qp);
+ }
- //draw the cross
- QRectF br = boundingRect();
- qp.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line
- qp.drawLine(br.width()/2-(crossWidth/2), header, br.width()/2+(crossWidth/2), header); //horizontal line
-
- //draw the symbolic NO
- qreal xoffset = br.width()/2 - 25;
- qp.drawLine(xoffset+5, 3, xoffset+10, 3);
- QPointF p1[3] = {
- QPointF(xoffset+10, 0),
- QPointF(xoffset+15, 3),
- QPointF(xoffset+20, 3),
- };
- qp.drawPolyline(p1,3);
-
- //draw the symbolic NC
- xoffset = br.width()/2;
- QPointF p2[3] = {
- QPointF(xoffset+5, 3),
- QPointF(xoffset+10, 3),
- QPointF(xoffset+10, 0)
- };
- qp.drawPolyline(p2,3);
- QPointF p3[3] = {
- QPointF(xoffset+9, 0),
- QPointF(xoffset+15, 3),
- QPointF(xoffset+20, 3),
- };
- qp.drawPolyline(p3,3);
-
- ///keep this code for possible next feature
- ///choice to use symbolic or text.
- //draw the header
- /*qp.setFont(QETApp::diagramTextsFont(7));
- QRectF header_rect (0,0,30,10);
- qp.drawText(header_rect, Qt::AlignCenter, "NO");
- header_rect.setRect(30, 0, 30, 10);
- qp.drawText(header_rect, Qt::AlignCenter, "NC");*/
-
- //and fill it
- fillCrossRef(qp);
AddExtraInfo(qp);
qp.end();
@@ -242,6 +206,181 @@
}
/**
+ * @brief CrossRefItem::drawHasCross
+ * Draw this crossref with a cross
+ * @param painter, painter to use
+ */
+void CrossRefItem::drawHasCross(QPainter &painter) {
+ //calcul the size of the cross
+ setUpCrossBoundingRect();
+
+ //draw the cross
+ QRectF br = boundingRect();
+ painter.drawLine(br.width()/2, 0, br.width()/2, br.height()); //vertical line
+ painter.drawLine(br.width()/2-(crossWidth/2), header, br.width()/2+(crossWidth/2), header); //horizontal line
+
+ //draw the symbolic NO
+ qreal xoffset = br.width()/2 - 25;
+ painter.drawLine(xoffset+5, 3, xoffset+10, 3);
+ QPointF p1[3] = {
+ QPointF(xoffset+10, 0),
+ QPointF(xoffset+15, 3),
+ QPointF(xoffset+20, 3),
+ };
+ painter.drawPolyline(p1,3);
+
+ //draw the symbolic NC
+ xoffset = br.width()/2;
+ QPointF p2[3] = {
+ QPointF(xoffset+5, 3),
+ QPointF(xoffset+10, 3),
+ QPointF(xoffset+10, 0)
+ };
+ painter.drawPolyline(p2,3);
+ QPointF p3[3] = {
+ QPointF(xoffset+9, 0),
+ QPointF(xoffset+15, 3),
+ QPointF(xoffset+20, 3),
+ };
+ painter.drawPolyline(p3,3);
+
+ ///keep this code for possible next feature
+ ///choice to use symbolic or text.
+ //draw the header
+ /*qp.setFont(QETApp::diagramTextsFont(7));
+ QRectF header_rect (0,0,30,10);
+ qp.drawText(header_rect, Qt::AlignCenter, "NO");
+ header_rect.setRect(30, 0, 30, 10);
+ qp.drawText(header_rect, Qt::AlignCenter, "NC");*/
+
+ //and fill it
+ fillCrossRef(painter);
+}
+
+/**
+ * @brief CrossRefItem::drawHasContacts
+ * Draw this crossref with symbolic contacts
+ * @param painter painter to use
+ */
+void CrossRefItem::drawHasContacts(QPainter &painter) {
+ m_drawed_contacts = 0;
+
+ painter.save();
+ QPen pen_;
+ pen_.setWidthF(0.3);
+ painter.setPen(pen_);
+ painter.setFont(QETApp::diagramTextsFont(5));
+
+ //Draw each linked contact
+ foreach (Element *elmt, m_element->linkedElements()) {
+ DiagramContext info = elmt->kindInformations();
+
+ for (int i=0; i<info["number"].toInt(); i++) {
+ int option = 0;
+
+ info["state"].toString() == "NO"? option = NO : option = NC;
+
+ QString type = info["type"].toString();
+ if (type == "power") option += Power;
+ else if (type == "delayOn") option += DelayOn;
+ else if (type == "delayOff") option += DelayOff;
+
+ QString contact_str;
+ contact_str += QString::number(elmt->diagram()->folioIndex() + 1);
+ contact_str += "-";
+ contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString();
+ drawContact(painter, option, contact_str);
+ }
+ }
+
+ QRectF br(0,0,crossWidth, m_drawed_contacts*10+4);
+ m_bounding_rect = br;
+ m_shape_path.addRect(br);
+ painter.restore();
+}
+
+/**
+ * @brief CrossRefItem::drawContact
+ * draw one contacte, the type of contact to draw is define in ctc.
+ * @param painter painter to use
+ * @param ctc option for draw the contact, see enum CONTACTS
+ */
+void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
+ int offset = m_drawed_contacts*10;
+
+ //draw the basic line
+ painter.drawLine(0, offset+6, 8, offset+6);
+ painter.drawLine(16, offset+6, 24, offset+6);
+
+ ///take exemple of this code for display the terminal text
+ /*QFont font = QETApp::diagramTextsFont(4);
+ font.setBold(true);
+ painter.setFont(font);
+ QRectF bt(0, offset, 24, 10);
+ int txt = 10 + m_drawed_contacts;
+ painter.drawText(bt, Qt::AlignLeft|Qt::AlignTop, QString::number(txt));
+ painter.drawText(bt, Qt::AlignRight|Qt::AlignTop, QString::number(txt));
+ painter.setFont(QETApp::diagramTextsFont(5));*/
+
+ //draw open contact
+ if (flags &NO) {
+ painter.drawLine(8, offset+9, 16, offset+6);
+ }
+ //draw close contact
+ if (flags &NC) {
+ QPointF p1[3] = {
+ QPointF(8, offset+6),
+ QPointF(9, offset+6),
+ QPointF(9, offset+2.5)
+ };
+ painter.drawPolyline(p1,3);
+ painter.drawLine(8, offset+3, 16, offset+6);
+ }
+
+ //draw half circle for power contact
+ if (flags &Power) {
+ QRectF arc(4, offset+4, 4, 4);
+ if (flags &NO)
+ painter.drawArc(arc, 180*16, 180*16);
+ else
+ painter.drawArc(arc, 0, 180*16);
+ }
+
+ // draw half circle for delay contact
+ if(flags &DelayOn || flags &DelayOff) {
+ // for delay on contact
+ if (flags &DelayOn) {
+ if (flags &NO) {
+ painter.drawLine(12, offset+4, 12, offset+6);
+ QRectF r(9.5, offset+1, 5, 3);
+ painter.drawArc(r, 180*16, 180*16);
+ }
+ if (flags &NC) {
+ painter.drawLine(QPointF(13.5, offset+2), QPointF(13.5, offset+3.5));
+ QRectF r(11, offset-1, 5, 3);
+ painter.drawArc(r, 180*16, 180*16);
+ }
+ }
+ // for delay off contact
+ else {
+ if (flags &NO) {
+ painter.drawLine(12, offset+3, 12, offset+6);
+ QRectF r(9.5, offset+2, 5, 3);
+ painter.drawArc(r, 0, 180*16);
+ }
+ if (flags &NC) {
+ painter.drawLine(QPointF(13.5, offset+1), QPointF(13.5, offset+3.5));
+ QRectF r(11, offset, 5, 3);
+ painter.drawArc(r, 0, 180*16);
+ }
+ }
+ }
+
+ painter.drawText(20, offset, 30, 10, Qt::AlignRight | Qt::AlignVCenter, str);
+ ++m_drawed_contacts;
+}
+
+/**
* @brief CrossRefItem::fillCrossRef
* Fill the content of the cross ref
* @param painter painter to use.
@@ -262,13 +401,16 @@
painter.setFont(QETApp::diagramTextsFont(5));
qreal middle_cross = m_bounding_rect.width()/2;
+
+ QString contact_str;
+ int i =0;
//fill the NO
- QString contact_str;
foreach (Element *elmt, NO_list) {
+ ++i;
contact_str += QString::number(elmt->diagram()->folioIndex() + 1);
contact_str += "-";
contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString();
- contact_str += "\n";
+ if(NO_list.size() > i) contact_str += "\n";
}
QRectF rect_(middle_cross - (crossWidth/2),
header,
@@ -278,11 +420,12 @@
//fill the NC
contact_str.clear();
+ i = 0;
foreach (Element *elmt, NC_list) {
contact_str += QString::number(elmt->diagram()->folioIndex() + 1);
contact_str += "-";
contact_str += elmt->diagram()->convertPosition(elmt -> scenePos()).toString();
- contact_str += "\n";
+ if (NC_list.size() > i) contact_str += "\n";
}
rect_.setRect(middle_cross,
header,
Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h 2014-04-28 15:41:58 UTC (rev 3033)
@@ -42,6 +42,14 @@
enum { Type = UserType + 1009 };
virtual int type() const { return Type; }
+ enum CONTACTS {
+ NO = 1,
+ NC = 2,
+ Power = 4,
+ DelayOn = 8,
+ DelayOff = 16
+ };
+
QRectF boundingRect() const;
virtual QPainterPath shape() const;
@@ -52,14 +60,17 @@
void autoPos();
protected:
- virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *e);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *e);
+ virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *e);
+ virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *e);
private:
void setUpCrossBoundingRect();
- void fillCrossRef(QPainter &painter);
- void AddExtraInfo(QPainter &painter);
+ void drawHasCross (QPainter &painter);
+ void drawHasContacts (QPainter &painter);
+ void drawContact (QPainter &painter, int flags, QString str = QString());
+ void fillCrossRef (QPainter &painter);
+ void AddExtraInfo (QPainter &painter);
//Attributes
private:
@@ -68,6 +79,7 @@
QPicture m_drawing;
QPainterPath m_shape_path;
XRefProperties m_properties;
+ int m_drawed_contacts;
};
#endif // CROSSREFITEM_H
Modified: trunk/sources/ui/xrefpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.cpp 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/ui/xrefpropertieswidget.cpp 2014-04-28 15:41:58 UTC (rev 3033)
@@ -31,6 +31,7 @@
m_properties(properties)
{
ui->setupUi(this);
+ connect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_show_power_cb, SLOT(setEnabled(bool)));
updateDisplay();
}
@@ -40,6 +41,7 @@
*/
XRefPropertiesWidget::~XRefPropertiesWidget()
{
+ disconnect(ui->m_display_has_cross_rb, SIGNAL(toggled(bool)), ui->m_show_power_cb, SLOT(setEnabled(bool)));
delete ui;
}
@@ -58,7 +60,10 @@
* @return the propertie edited by this widget
*/
XRefProperties XRefPropertiesWidget::properties() {
- m_properties.setShowPowerContac(ui->cb_show_power->isChecked());
+ if (ui->m_display_has_cross_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Cross);
+ else if (ui->m_display_has_contacts_rb->isChecked()) m_properties.setDisplayHas(XRefProperties::Contacts);
+ m_properties.setShowPowerContac(ui->m_show_power_cb->isChecked());
+
return m_properties;
}
@@ -68,7 +73,9 @@
* @param ro
*/
void XRefPropertiesWidget::setReadOnly(bool ro) {
- ui->cb_show_power->setDisabled(ro);
+ ui->m_display_has_cross_rb->setDisabled(ro);
+ ui->m_display_has_contacts_rb->setDisabled(ro);
+ ui->m_show_power_cb->setDisabled(ro);
}
/**
@@ -76,5 +83,14 @@
* Update display with the content of the properties
*/
void XRefPropertiesWidget::updateDisplay() {
- ui->cb_show_power->setChecked(m_properties.showPowerContact());
+ XRefProperties::DisplayHas dh = m_properties.displayHas();
+ if (dh == XRefProperties::Cross) {
+ ui->m_display_has_cross_rb->setChecked(true);
+ }
+ else if (dh == XRefProperties::Contacts) {
+ ui->m_display_has_contacts_rb->setChecked(true);
+ }
+
+ ui->m_show_power_cb->setChecked(m_properties.showPowerContact());
+ ui->m_show_power_cb->setDisabled(!ui->m_display_has_cross_rb->isChecked());
}
Modified: trunk/sources/ui/xrefpropertieswidget.ui
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.ui 2014-04-28 08:58:02 UTC (rev 3032)
+++ trunk/sources/ui/xrefpropertieswidget.ui 2014-04-28 15:41:58 UTC (rev 3033)
@@ -15,7 +15,34 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QCheckBox" name="cb_show_power">
+ <widget class="QGroupBox" name="m_display_gb">
+ <property name="title">
+ <string>Représentation:</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="m_display_has_cross_rb">
+ <property name="text">
+ <string>Afficher en croix</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="m_display_has_contacts_rb">
+ <property name="text">
+ <string>Afficher en contacts</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="m_show_power_cb">
<property name="text">
<string>Afficher les contacts de puissance dans la croix</string>
</property>