Cross ref item minir fix :

Some variable was not assigned.
Improve the bounding rect to be more accurate


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4783 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2016-11-16 16:01:53 +00:00
parent 743d2b7ace
commit 11d38c6091
6 changed files with 102 additions and 79 deletions

View File

@@ -32,14 +32,14 @@ namespace autonum
* @param elmt - parent element (if any) of the formula * @param elmt - parent element (if any) of the formula
* @return the string with variable assigned. * @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); AssignVariables av(formula, seqStruct, diagram, elmt);
seqStruct = av.m_seq_struct; seqStruct = av.m_seq_struct;
return av.m_assigned_label; 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_diagram(diagram),
m_arg_formula(formula), m_arg_formula(formula),
m_assigned_label(formula), m_assigned_label(formula),

View File

@@ -44,10 +44,10 @@ namespace autonum
class AssignVariables class AssignVariables
{ {
public: 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: 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 assignTitleBlockVar();
void assignProjectVar(); void assignProjectVar();
void assignSequence(); void assignSequence();
@@ -56,7 +56,7 @@ namespace autonum
QString m_arg_formula; QString m_arg_formula;
QString m_assigned_label; QString m_assigned_label;
sequenceStruct m_seq_struct; sequenceStruct m_seq_struct;
Element *m_element = nullptr; const Element *m_element = nullptr;
}; };

View File

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

View File

@@ -39,61 +39,61 @@ class CrossRefItem : public QGraphicsObject
{ {
Q_OBJECT Q_OBJECT
//Methods //Methods
public: public:
explicit CrossRefItem(Element *elmt); explicit CrossRefItem(Element *elmt);
~CrossRefItem(); ~CrossRefItem();
enum { Type = UserType + 1009 }; enum { Type = UserType + 1009 };
virtual int type() const { return Type; } virtual int type() const { return Type; }
enum CONTACTS { enum CONTACTS {
NO = 1, NO = 1,
NC = 2, NC = 2,
NOC = 3, NOC = 3,
SW = 4, SW = 4,
Power = 8, Power = 8,
DelayOn = 16, DelayOn = 16,
DelayOff = 32, DelayOff = 32,
Delay = 48 Delay = 48
}; };
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; void allElementsPositionText (QString &no_str, QString &nc_str,const bool &add_prefix = false) const;
void setTextLabel(QString label); void setTextLabel(QString label);
signals: signals:
public slots: public slots:
void updateProperties (); void updateProperties ();
void updateLabel (); void updateLabel ();
void autoPos (); void autoPos ();
protected: protected:
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ); virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event );
private: private:
void buildHeaderContact (); void buildHeaderContact ();
void setUpCrossBoundingRect (QPainter &painter); void setUpCrossBoundingRect (QPainter &painter);
void drawHasCross (QPainter &painter); void drawAsCross (QPainter &painter);
void drawHasContacts (QPainter &painter); void drawAsContacts (QPainter &painter);
void drawContact (QPainter &painter, int flags, QString str = QString()); QRectF drawContact (QPainter &painter, int flags, QString str = QString());
void fillCrossRef (QPainter &painter); void fillCrossRef (QPainter &painter);
void AddExtraInfo (QPainter &painter, QString); void AddExtraInfo (QPainter &painter, QString);
void setTextParent (); void setTextParent ();
//Attributes //Attributes
private: private:
Element *m_element; //element to display the cross reference Element *m_element; //element to display the cross reference
QRectF m_bounding_rect; QRectF m_bounding_rect;
QPicture m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc; QPicture m_drawing, m_hdr_no_ctc, m_hdr_nc_ctc;
QPainterPath m_shape_path; QPainterPath m_shape_path;
XRefProperties m_properties; XRefProperties m_properties;
int m_drawed_contacts; int m_drawed_contacts;
}; };
#endif // CROSSREFITEM_H #endif // CROSSREFITEM_H

View File

@@ -823,7 +823,7 @@ ElementTextItem* Element::setTaggedText(const QString &tagg, const QString &news
* @brief Element::getPrefix * @brief Element::getPrefix
* get Element Prefix * get Element Prefix
*/ */
QString Element::getPrefix() { QString Element::getPrefix() const{
return m_prefix; return m_prefix;
} }

View File

@@ -143,7 +143,7 @@ class Element : public QetGraphicsItem {
void setSequentialToList(QStringList*, NumerotationContext*, QString); void setSequentialToList(QStringList*, NumerotationContext*, QString);
void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString); void setFolioSequentialToHash(QStringList*, QHash<QString, QStringList>*, QString);
void setPrefix(QString); void setPrefix(QString);
QString getPrefix(); QString getPrefix() const;
void freezeLabel(); void freezeLabel();
void unfreezeLabel(); void unfreezeLabel();
void freezeNewAddedElement(); void freezeNewAddedElement();