[qet] qet/qet: [4783] Cross ref item minir fix :

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4783
Author:   blacksun
Date:     2016-11-16 17:01:53 +0100 (Wed, 16 Nov 2016)
Log Message:
-----------
Cross ref item minir fix :
Some variable was not assigned.
Improve the bounding rect to be more accurate

Modified Paths:
--------------
    trunk/sources/autoNum/assignvariables.cpp
    trunk/sources/autoNum/assignvariables.h
    trunk/sources/qetgraphicsitem/crossrefitem.cpp
    trunk/sources/qetgraphicsitem/crossrefitem.h
    trunk/sources/qetgraphicsitem/element.cpp
    trunk/sources/qetgraphicsitem/element.h

Modified: trunk/sources/autoNum/assignvariables.cpp
===================================================================
--- trunk/sources/autoNum/assignvariables.cpp	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/autoNum/assignvariables.cpp	2016-11-16 16:01:53 UTC (rev 4783)
@@ -32,7 +32,7 @@
 	 * @param elmt - parent element (if any) of the formula
 	 * @return the string with variable assigned.
 	 */
-	QString AssignVariables::formulaToLabel(QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt)
+	QString AssignVariables::formulaToLabel(QString formula, sequenceStruct &seqStruct, Diagram *diagram, const Element *elmt)
 	{
 		AssignVariables av(formula, seqStruct, diagram, elmt);
 		seqStruct = av.m_seq_struct;
@@ -39,7 +39,7 @@
 		return av.m_assigned_label;
 	}
 
-	AssignVariables::AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt):
+	AssignVariables::AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, const Element *elmt):
 	m_diagram(diagram),
 	m_arg_formula(formula),
 	m_assigned_label(formula),

Modified: trunk/sources/autoNum/assignvariables.h
===================================================================
--- trunk/sources/autoNum/assignvariables.h	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/autoNum/assignvariables.h	2016-11-16 16:01:53 UTC (rev 4783)
@@ -44,10 +44,10 @@
 	class AssignVariables
 	{
 		public:
-			static QString formulaToLabel (QString formula, sequenceStruct &seqStruct, Diagram *diagram, Element *elmt = nullptr);
+			static QString formulaToLabel (QString formula, sequenceStruct &seqStruct, Diagram *diagram, const Element *elmt = nullptr);
 
 		private:
-			AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, Element *elmt = nullptr);
+			AssignVariables(QString formula, sequenceStruct seqStruct , Diagram *diagram, const Element *elmt = nullptr);
 			void assignTitleBlockVar();
 			void assignProjectVar();
 			void assignSequence();
@@ -56,7 +56,7 @@
 			QString m_arg_formula;
 			QString m_assigned_label;
 			sequenceStruct m_seq_struct;
-			Element *m_element = nullptr;
+			const Element *m_element = nullptr;
 	};
 
 

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-11-16 16:01:53 UTC (rev 4783)
@@ -22,6 +22,7 @@
 #include "elementtextitem.h"
 #include "diagram.h"
 #include "qgraphicsitemutility.h"
+#include "assignvariables.h"
 
 //define the height of the header.
 #define header 5
@@ -88,19 +89,15 @@
  * @return the string corresponding to the position of @elmt in the diagram.
  * if @add_prefix is true, prefix (for power and delay contact) is added to the poistion text.
  */
-QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const{
-
-	QString txt;
+QString CrossRefItem::elementPositionText(const Element *elmt, const bool &add_prefix) const
+{
 	XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
-	txt = xrp.masterLabel();
-	txt.replace("%f", QString::number(elmt->diagram()->folioIndex()+1));
-	txt.replace("%F", elmt->diagram() -> border_and_titleblock.folio());
-	txt.replace("%M", elmt->diagram() -> border_and_titleblock.machine());
-	txt.replace("%LM", elmt->diagram() -> border_and_titleblock.locmach());
-	txt.replace("%c", QString::number(elmt->diagram() -> convertPosition(elmt -> scenePos()).number()));
-	txt.replace("%l", elmt->diagram() -> convertPosition(elmt -> scenePos()).letter());
+	QString formula = xrp.masterLabel();
+	autonum::sequenceStruct seq;
+	QString txt = autonum::AssignVariables::formulaToLabel(formula, seq, elmt->diagram(), elmt);
 
-	if (add_prefix) {
+	if (add_prefix)
+	{
 		if      (elmt->kindInformations()["type"].toString() == "power")        txt.prepend(m_properties.prefix("power"));
 		else if (elmt->kindInformations()["type"].toString().contains("delay")) txt.prepend(m_properties.prefix("delay"));
 		else if (elmt->kindInformations()["state"].toString() == "SW")          txt.prepend(m_properties.prefix("switch"));
@@ -181,7 +178,8 @@
  * @brief CrossRefItem::updateLabel
  * Update the content of the item
  */
-void CrossRefItem::updateLabel() {
+void CrossRefItem::updateLabel()
+{
 		//init the shape and bounding rect
 	m_shape_path    = QPainterPath();
 	prepareGeometryChange();
@@ -200,9 +198,9 @@
 		XRefProperties::DisplayHas dh = m_properties.displayHas();
 
 		if (dh == XRefProperties::Cross)
-			drawHasCross(qp);
+			drawAsCross(qp);
 		else if (dh == XRefProperties::Contacts)
-			drawHasContacts(qp);
+			drawAsContacts(qp);
 	}
 
 	AddExtraInfo(qp, "comment");
@@ -338,11 +336,11 @@
 }
 
 /**
- * @brief CrossRefItem::drawHasCross
+ * @brief CrossRefItem::drawAsCross
  * Draw this crossref with a cross
  * @param painter, painter to use
  */
-void CrossRefItem::drawHasCross(QPainter &painter) {
+void CrossRefItem::drawAsCross(QPainter &painter) {
 		//calcul the size of the cross
 	setUpCrossBoundingRect(painter);
 
@@ -366,20 +364,25 @@
 }
 
 /**
- * @brief CrossRefItem::drawHasContacts
+ * @brief CrossRefItem::drawAsContacts
  * Draw this crossref with symbolic contacts
  * @param painter painter to use
  */
-void CrossRefItem::drawHasContacts(QPainter &painter) {
-	if (m_element -> isFree()) return;
+void CrossRefItem::drawAsContacts(QPainter &painter)
+{
+	if (m_element -> isFree())
+		return;
 
 	m_drawed_contacts = 0;
+	QRectF bounding_rect;
 
 	//Draw each linked contact
-	foreach (Element *elmt,  m_element->linkedElements()) {
+	foreach (Element *elmt,  m_element->linkedElements())
+	{
 		DiagramContext info = elmt->kindInformations();
 
-		for (int i=0; i<info["number"].toInt(); i++) {
+		for (int i=0; i<info["number"].toInt(); i++)
+		{
 			int option = 0;
 
 			QString state = info["state"].toString();
@@ -392,14 +395,15 @@
 			else if (type == "delayOn")  option += DelayOn;
 			else if (type == "delayOff") option += DelayOff;
 
-			drawContact(painter, option, elementPositionText(elmt));
+			QRectF br = drawContact(painter, option, elementPositionText(elmt));
+			bounding_rect = bounding_rect.united(br);
 		}
 	}
 
-	QRectF br(0, 0, 50, m_drawed_contacts*10+4);
+	bounding_rect.adjust(-4, -4, 4, 4);
 	prepareGeometryChange();
-	m_bounding_rect = br;
-	m_shape_path.addRect(br);
+	m_bounding_rect = bounding_rect;
+	m_shape_path.addRect(bounding_rect);
 }
 
 /**
@@ -408,12 +412,18 @@
  * @param painter, painter to use
  * @param flags, define how to draw the contact (see enul CONTACTS)
  * @param str, the text to display for this contact (the position of the contact).
+ * @return The bounding rect of the draw (contact + text)
  */
-void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
+QRectF CrossRefItem::drawContact(QPainter &painter, int flags, QString str)
+{
 	int offset = m_drawed_contacts*10;
+	QRectF bounding_rect;
 
 	//Draw NO or NC contact
-	if (flags &NOC) {
+	if (flags &NOC)
+	{
+		bounding_rect = QRectF(0, offset, 24, 10);
+
 		//draw the basic line
 		painter.drawLine(0, offset+6, 8, offset+6);
 		painter.drawLine(16, offset+6, 24, offset+6);
@@ -482,12 +492,18 @@
 			}
 		}
 
-		painter.drawText(30, offset, 150, 10, Qt::AlignLeft | Qt::AlignVCenter, str);
+		QRectF text_rect = painter.boundingRect(QRectF(30, offset, 5, 10), Qt::AlignLeft | Qt::AlignVCenter, str);
+		painter.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, str);
+		bounding_rect = bounding_rect.united(text_rect);
+
 		++m_drawed_contacts;
 	}
 
 	//Draw a switch contact
-	else if (flags &SW) {
+	else if (flags &SW)
+	{
+		bounding_rect = QRectF(0, offset, 24, 20);
+
 		//draw the NO side
 		painter.drawLine(0, offset+6, 8, offset+6);
 		//Draw the NC side
@@ -497,6 +513,7 @@
 			QPointF(8, offset+12)
 		};
 		painter.drawPolyline(p1, 3);
+
 		//Draw the common side
 		QPointF p2[3] = {
 			QPointF(7, offset+14),
@@ -504,11 +521,17 @@
 			QPointF(24, offset+11),
 		};
 		painter.drawPolyline(p2, 3);
-		//Draw position text
-		painter.drawText(20, offset+5, 30, 10, Qt::AlignRight | Qt::AlignVCenter, str);
-		//a switch contact take place of two normal contact
+
+			//Draw position text
+		QRectF text_rect = painter.boundingRect(QRectF(30, offset+5, 5, 10), Qt::AlignLeft | Qt::AlignVCenter, str);
+		painter.drawText(text_rect, Qt::AlignLeft | Qt::AlignVCenter, str);
+		bounding_rect = bounding_rect.united(text_rect);
+
+			//a switch contact take place of two normal contact
 		m_drawed_contacts += 2;
 	}
+
+	return bounding_rect;
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/crossrefitem.h
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.h	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/qetgraphicsitem/crossrefitem.h	2016-11-16 16:01:53 UTC (rev 4783)
@@ -39,61 +39,61 @@
 {
 	Q_OBJECT
 
-	//Methods
+		//Methods
 	public:
-	explicit CrossRefItem(Element *elmt);
-	~CrossRefItem();
+		explicit CrossRefItem(Element *elmt);
+		~CrossRefItem();
 
-	enum { Type = UserType + 1009 };
-	virtual int type() const { return Type; }
+		enum { Type = UserType + 1009 };
+		virtual int type() const { return Type; }
 
-	enum CONTACTS {
-		NO       = 1,
-		NC       = 2,
-		NOC      = 3,
-		SW       = 4,
-		Power    = 8,
-		DelayOn  = 16,
-		DelayOff = 32,
-		Delay    = 48
-	};
+		enum CONTACTS {
+			NO       = 1,
+			NC       = 2,
+			NOC      = 3,
+			SW       = 4,
+			Power    = 8,
+			DelayOn  = 16,
+			DelayOff = 32,
+			Delay    = 48
+		};
 
-	QRectF boundingRect			() const;
-	virtual QPainterPath shape	() 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;
-	void setTextLabel(QString label);
+		QRectF boundingRect			() const;
+		virtual QPainterPath shape	() 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;
+		void setTextLabel(QString label);
 
 
 	signals:
 
 	public slots:
-	void updateProperties ();
-	void updateLabel   ();
-	void autoPos	   ();
+		void updateProperties ();
+		void updateLabel   ();
+		void autoPos	   ();
 
 	protected:
-	virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
-	virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
+		virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+		virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
 
 	private:
-	void buildHeaderContact		();
-	void setUpCrossBoundingRect (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, QString);
-	void setTextParent			();
+		void buildHeaderContact		();
+		void setUpCrossBoundingRect (QPainter &painter);
+		void drawAsCross			(QPainter &painter);
+		void drawAsContacts		(QPainter &painter);
+		QRectF drawContact			(QPainter &painter, int flags, QString str = QString());
+		void fillCrossRef			(QPainter &painter);
+		void AddExtraInfo			(QPainter &painter, QString);
+		void setTextParent			();
 
-	//Attributes
+		//Attributes
 	private:
-	Element		  *m_element; //element to display the cross reference
-	QRectF		   m_bounding_rect;
-	QPicture	   m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc;
-	QPainterPath   m_shape_path;
-	XRefProperties m_properties;
-	int			   m_drawed_contacts;
+		Element		  *m_element; //element to display the cross reference
+		QRectF		   m_bounding_rect;
+		QPicture	   m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc;
+		QPainterPath   m_shape_path;
+		XRefProperties m_properties;
+		int			   m_drawed_contacts;
 };
 
 #endif // CROSSREFITEM_H

Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/qetgraphicsitem/element.cpp	2016-11-16 16:01:53 UTC (rev 4783)
@@ -823,7 +823,7 @@
  * @brief Element::getPrefix
  * get Element Prefix
  */
-QString Element::getPrefix() {
+QString Element::getPrefix() const{
 	return m_prefix;
 }
 

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2016-11-15 23:41:46 UTC (rev 4782)
+++ trunk/sources/qetgraphicsitem/element.h	2016-11-16 16:01:53 UTC (rev 4783)
@@ -143,7 +143,7 @@
 		void setSequentialToList(QStringList*, NumerotationContext*, QString);
 		void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
 		void setPrefix(QString);
-		QString getPrefix();
+		QString getPrefix() const;
 		void freezeLabel();
 		void unfreezeLabel();
 		void freezeNewAddedElement();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/