QElectroTech  0.70
crossrefitem.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2019 The QElectroTech Team
3  This file is part of QElectroTech.
4 
5  QElectroTech is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 2 of the License, or
8  (at your option) any later version.
9 
10  QElectroTech is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef CROSSREFITEM_H
19 #define CROSSREFITEM_H
20 
21 #include <QGraphicsObject>
23 #include <QPicture>
24 
25 class Element;
28 
40 class CrossRefItem : public QGraphicsObject
41 {
42  Q_OBJECT
43 
44  //Methods
45  public:
46  explicit CrossRefItem(Element *elmt);
47  explicit CrossRefItem(Element *elmt, DynamicElementTextItem *text);
48  explicit CrossRefItem(Element *elmt, ElementTextItemGroup *group);
49  ~CrossRefItem() override;
50  private:
51  void init();
52  void setUpConnection();
53 
54  public:
55  enum { Type = UserType + 1009 };
56  int type() const override { return Type; }
57 
58  enum CONTACTS {
59  NO = 1,
60  NC = 2,
61  NOC = 3,
62  SW = 4,
63  Power = 8,
64  DelayOn = 16,
65  DelayOff = 32,
66  DelayOnOff = 64,
67  Delay = 112
68  };
69 
70  QRectF boundingRect () const override;
71  QPainterPath shape () const override;
72  QString elementPositionText (const Element *elmt, const bool &add_prefix = false) const;
73 
74  public slots:
75  void updateProperties ();
76  void updateLabel ();
77  void autoPos ();
78 
79  protected:
80  bool sceneEvent(QEvent *event) override;
81  void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
82  void mouseDoubleClickEvent (QGraphicsSceneMouseEvent * event ) override;
83  void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
84  void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
85  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
86 
87  private:
88  void linkedChanged();
89  void buildHeaderContact ();
90  void setUpCrossBoundingRect (QPainter &painter);
91  void drawAsCross (QPainter &painter);
92  void drawAsContacts (QPainter &painter);
93  QRectF drawContact (QPainter &painter, int flags, Element *elmt);
94  void fillCrossRef (QPainter &painter);
95  void AddExtraInfo (QPainter &painter, const QString&);
96  QList<Element *> NOElements() const;
97  QList<Element *> NCElements() const;
98 
99  //Attributes
100  private:
101  Element *m_element; //element to display the cross reference
104  QPainterPath m_shape_path;
107  QMap <Element *, QRectF> m_hovered_contacts_map;
111  QList <QMetaObject::Connection> m_slave_connection;
112  QList <QMetaObject::Connection> m_update_connection;
113 };
114 
115 #endif // CROSSREFITEM_H
116 
The CrossRefItem class This clas provide an item, for show the cross reference, like the contacts lin...
Definition: crossrefitem.h:40
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
CrossRefItem::paint Paint this item.
The DynamicElementTextItem class This class provide a simple text field of element who can be added o...
ElementTextItemGroup * m_group
Definition: crossrefitem.h:110
The XRefProperties class this class store properties used by XrefItem.
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override
CrossRefItem::mouseDoubleClickEvent.
CrossRefItem(Element *elmt)
CrossRefItem::CrossRefItem.
void updateLabel()
CrossRefItem::updateLabel Update the content of the item.
QList< QMetaObject::Connection > m_slave_connection
Definition: crossrefitem.h:111
QRectF drawContact(QPainter &painter, int flags, Element *elmt)
CrossRefItem::drawContact Draw one contact, the type of contact to draw is define in ...
void fillCrossRef(QPainter &painter)
CrossRefItem::fillCrossRef Fill the content of the cross ref.
QPainterPath shape() const override
CrossRefItem::shape.
void linkedChanged()
Element * m_hovered_contact
Definition: crossrefitem.h:108
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
QPicture m_hdr_no_ctc
Definition: crossrefitem.h:103
void buildHeaderContact()
CrossRefItem::buildHeaderContact Draw the QPicture of m_hdr_no_ctc and m_hdr_nc_ctc.
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
void setUpCrossBoundingRect(QPainter &painter)
CrossRefItem::setUpCrossBoundingRect Get the numbers of slaves elements linked to this parent element...
QPicture m_hdr_nc_ctc
Definition: crossrefitem.h:103
QPainterPath m_shape_path
Definition: crossrefitem.h:104
QList< QMetaObject::Connection > m_update_connection
Definition: crossrefitem.h:112
QPicture m_drawing
Definition: crossrefitem.h:103
bool sceneEvent(QEvent *event) override
int m_drawed_contacts
Definition: crossrefitem.h:106
void AddExtraInfo(QPainter &painter, const QString &)
CrossRefItem::AddExtraInfo Add the comment info of the parent item if needed.
void updateProperties()
CrossRefItem::updateProperties update the curent properties.
int type() const override
Definition: crossrefitem.h:56
QRectF boundingRect() const override
CrossRefItem::boundingRect.
The ElementTextItemGroup class This class represent a group of element text Texts in the group can be...
QString elementPositionText(const Element *elmt, const bool &add_prefix=false) const
CrossRefItem::elementPositionText.
~CrossRefItem() override
CrossRefItem::~CrossRefItem Default destructor.
QMap< Element *, QRectF > m_hovered_contacts_map
Definition: crossrefitem.h:107
void init()
CrossRefItem::init init this Xref.
XRefProperties m_properties
Definition: crossrefitem.h:105
void drawAsContacts(QPainter &painter)
CrossRefItem::drawAsContacts Draw this crossref with symbolic contacts.
Element * m_element
Definition: crossrefitem.h:101
DynamicElementTextItem * m_text
Definition: crossrefitem.h:109
QRectF m_bounding_rect
Definition: crossrefitem.h:102
void setUpConnection()
CrossRefItem::setUpConnection Set up several connection to keep up to date the Xref.
QList< Element * > NOElements() const
CrossRefItem::NOElements.
QList< Element * > NCElements() const
CrossRefItem::NCElements.
void autoPos()
CrossRefItem::autoPos Calculate and set position automaticaly.
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override
void drawAsCross(QPainter &painter)
CrossRefItem::drawAsCross Draw this crossref with a cross.