From 11d38c6091e12aff2fec03d1821c4b45dec670e4 Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 16 Nov 2016 16:01:53 +0000 Subject: [PATCH] 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 --- sources/autoNum/assignvariables.cpp | 4 +- sources/autoNum/assignvariables.h | 6 +- sources/qetgraphicsitem/crossrefitem.cpp | 87 +++++++++++++++--------- sources/qetgraphicsitem/crossrefitem.h | 80 +++++++++++----------- sources/qetgraphicsitem/element.cpp | 2 +- sources/qetgraphicsitem/element.h | 2 +- 6 files changed, 102 insertions(+), 79 deletions(-) diff --git a/sources/autoNum/assignvariables.cpp b/sources/autoNum/assignvariables.cpp index 8cc6016b1..0164b502e 100644 --- a/sources/autoNum/assignvariables.cpp +++ b/sources/autoNum/assignvariables.cpp @@ -32,14 +32,14 @@ namespace autonum * @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; 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), diff --git a/sources/autoNum/assignvariables.h b/sources/autoNum/assignvariables.h index fde7c2dd9..eebbb0808 100644 --- a/sources/autoNum/assignvariables.h +++ b/sources/autoNum/assignvariables.h @@ -44,10 +44,10 @@ namespace autonum 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 @@ namespace autonum QString m_arg_formula; QString m_assigned_label; sequenceStruct m_seq_struct; - Element *m_element = nullptr; + const Element *m_element = nullptr; }; diff --git a/sources/qetgraphicsitem/crossrefitem.cpp b/sources/qetgraphicsitem/crossrefitem.cpp index 49e8b1e5f..79d69f132 100644 --- a/sources/qetgraphicsitem/crossrefitem.cpp +++ b/sources/qetgraphicsitem/crossrefitem.cpp @@ -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 @@ QPainterPath CrossRefItem::shape() const{ * @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 @@ void CrossRefItem::updateProperties() { * @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 @@ void CrossRefItem::updateLabel() { 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 @@ void CrossRefItem::setUpCrossBoundingRect(QPainter &painter) { } /** - * @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 @@ void CrossRefItem::drawHasCross(QPainter &painter) { } /** - * @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*, QString); void setPrefix(QString); - QString getPrefix(); + QString getPrefix() const; void freezeLabel(); void unfreezeLabel(); void freezeNewAddedElement();