LibrePCB Developers Documentation
sgi_netlabel.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_EDITOR_SGI_NETLABEL_H
21 #define LIBREPCB_EDITOR_SGI_NETLABEL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 
28 #include <QtCore>
29 #include <QtWidgets>
30 
31 #include <memory>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 namespace editor {
38 
39 class GraphicsLayer;
40 class IF_GraphicsLayerProvider;
41 class LineGraphicsItem;
42 
43 /*******************************************************************************
44  * Class SGI_NetLabel
45  ******************************************************************************/
46 
50 class SGI_NetLabel final : public QGraphicsItem {
51 public:
52  // Constructors / Destructor
53  SGI_NetLabel() = delete;
54  SGI_NetLabel(const SGI_NetLabel& other) = delete;
56  std::shared_ptr<const QSet<const NetSignal*>>
57  highlightedNetSignals) noexcept;
58  virtual ~SGI_NetLabel() noexcept;
59 
60  // General Methods
61  SI_NetLabel& getNetLabel() noexcept { return mNetLabel; }
62 
63  // Inherited from QGraphicsItem
64  QRectF boundingRect() const noexcept override { return mBoundingRect; }
65  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
66  QWidget* widget) noexcept override;
67 
68  // Operator Overloadings
69  SGI_NetLabel& operator=(const SGI_NetLabel& rhs) = delete;
70 
71 private: // Methods
72  void netLabelEdited(const SI_NetLabel& obj,
73  SI_NetLabel::Event event) noexcept;
74  virtual QVariant itemChange(GraphicsItemChange change,
75  const QVariant& value) noexcept override;
76  void updatePosition() noexcept;
77  void updateRotation() noexcept;
78  void updateText() noexcept;
79  void updateAnchor() noexcept;
80 
81 private: // Data
83  std::shared_ptr<const QSet<const NetSignal*>> mHighlightedNetSignals;
84  std::shared_ptr<GraphicsLayer> mOriginCrossLayer;
85  std::shared_ptr<GraphicsLayer> mNetLabelLayer;
86  QScopedPointer<LineGraphicsItem> mAnchorGraphicsItem;
87 
88  // Cached Attributes
89  QStaticText mStaticText;
90  QVector<QLineF> mOverlines;
91  QFont mFont;
92  bool mRotate180;
93  QPointF mTextOrigin;
94  QRectF mBoundingRect;
95 
96  // Slots
98 
99  // Static Stuff
100  static QVector<QLineF> sOriginCrossLines;
101 };
102 
103 /*******************************************************************************
104  * End of File
105  ******************************************************************************/
106 
107 } // namespace editor
108 } // namespace librepcb
109 
110 #endif
SGI_NetLabel & operator=(const SGI_NetLabel &rhs)=delete
SI_NetLabel::OnEditedSlot mOnEditedSlot
Definition: sgi_netlabel.h:97
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) noexcept override
Definition: sgi_netlabel.cpp:99
void updatePosition() noexcept
Definition: sgi_netlabel.cpp:179
QRectF boundingRect() const noexcept override
Definition: sgi_netlabel.h:64
std::shared_ptr< GraphicsLayer > mNetLabelLayer
Definition: sgi_netlabel.h:85
virtual ~SGI_NetLabel() noexcept
Definition: sgi_netlabel.cpp:92
Definition: occmodel.cpp:77
void updateAnchor() noexcept
Definition: sgi_netlabel.cpp:230
bool mRotate180
Definition: sgi_netlabel.h:92
QVector< QLineF > mOverlines
Definition: sgi_netlabel.h:90
std::shared_ptr< const QSet< const NetSignal * > > mHighlightedNetSignals
Definition: sgi_netlabel.h:83
SI_NetLabel & getNetLabel() noexcept
Definition: sgi_netlabel.h:61
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:111
void updateText() noexcept
Definition: sgi_netlabel.cpp:187
The SGI_NetLabel class.
Definition: sgi_netlabel.h:50
std::shared_ptr< GraphicsLayer > mOriginCrossLayer
Definition: sgi_netlabel.h:84
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) noexcept override
Definition: sgi_netlabel.cpp:136
void netLabelEdited(const SI_NetLabel &obj, SI_NetLabel::Event event) noexcept
Definition: sgi_netlabel.cpp:153
QPointF mTextOrigin
Definition: sgi_netlabel.h:93
QScopedPointer< LineGraphicsItem > mAnchorGraphicsItem
Definition: sgi_netlabel.h:86
QStaticText mStaticText
Definition: sgi_netlabel.h:89
void updateRotation() noexcept
Definition: sgi_netlabel.cpp:183
static QVector< QLineF > sOriginCrossLines
Definition: sgi_netlabel.h:100
QFont mFont
Definition: sgi_netlabel.h:91
SI_NetLabel & mNetLabel
Definition: sgi_netlabel.h:82
The SI_NetLabel class.
Definition: si_netlabel.h:49
QRectF mBoundingRect
Definition: sgi_netlabel.h:94
Event
Definition: si_netlabel.h:54