mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
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:
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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<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 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
|
||||
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 @@ void CrossRefItem::drawHasContacts(QPainter &painter) {
|
||||
* @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 @@ 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;
|
||||
}
|
||||
|
||||
//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 @@ void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
|
||||
QPointF(8, offset+12)
|
||||
};
|
||||
painter.drawPolyline(p1, 3);
|
||||
|
||||
//Draw the common side
|
||||
QPointF p2[3] = {
|
||||
QPointF(7, offset+14),
|
||||
@@ -504,11 +521,17 @@ void CrossRefItem::drawContact(QPainter &painter, int flags, QString str) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,61 +39,61 @@ class CrossRefItem : public QGraphicsObject
|
||||
{
|
||||
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
|
||||
|
||||
@@ -823,7 +823,7 @@ ElementTextItem* Element::setTaggedText(const QString &tagg, const QString &news
|
||||
* @brief Element::getPrefix
|
||||
* get Element Prefix
|
||||
*/
|
||||
QString Element::getPrefix() {
|
||||
QString Element::getPrefix() const{
|
||||
return m_prefix;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class Element : public QetGraphicsItem {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user