LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
symbolgraphicsitem.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_LIBRARY_SYMBOLGRAPHICSITEM_H
21 #define LIBREPCB_LIBRARY_SYMBOLGRAPHICSITEM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
27 #include <librepcb/common/uuid.h>
28 
29 #include <QtCore>
30 #include <QtWidgets>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class Circle;
38 class Polygon;
39 class Text;
40 class IF_GraphicsLayerProvider;
41 class PolygonGraphicsItem;
42 class CircleGraphicsItem;
43 class TextGraphicsItem;
44 
45 namespace library {
46 
47 class Symbol;
48 class SymbolPin;
49 class SymbolPinGraphicsItem;
50 
51 /*******************************************************************************
52  * Class SymbolGraphicsItem
53  ******************************************************************************/
54 
61 class SymbolGraphicsItem final : public QGraphicsItem {
62 public:
63  // Constructors / Destructor
64  SymbolGraphicsItem() = delete;
65  SymbolGraphicsItem(const SymbolGraphicsItem& other) = delete;
66  SymbolGraphicsItem(Symbol& symbol,
67  const IF_GraphicsLayerProvider& lp) noexcept;
68  ~SymbolGraphicsItem() noexcept;
69 
70  // Getters
71  SymbolPinGraphicsItem* getPinGraphicsItem(const Uuid& pin) noexcept;
72  CircleGraphicsItem* getCircleGraphicsItem(const Circle& circle) noexcept;
73  PolygonGraphicsItem* getPolygonGraphicsItem(const Polygon& polygon) noexcept;
74  TextGraphicsItem* getTextGraphicsItem(const Text& text) noexcept;
76  const Point& pos, QList<QSharedPointer<SymbolPinGraphicsItem>>* pins,
77  QList<QSharedPointer<CircleGraphicsItem>>* circles,
78  QList<QSharedPointer<PolygonGraphicsItem>>* polygons,
79  QList<QSharedPointer<TextGraphicsItem>>* texts) noexcept;
80  QList<QSharedPointer<SymbolPinGraphicsItem>> getSelectedPins() noexcept;
81  QList<QSharedPointer<CircleGraphicsItem>> getSelectedCircles() noexcept;
82  QList<QSharedPointer<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
83  QList<QSharedPointer<TextGraphicsItem>> getSelectedTexts() noexcept;
84 
85  // Setters
86  void setPosition(const Point& pos) noexcept;
87  void setRotation(const Angle& rot) noexcept;
88 
89  // General Methods
90  void addPin(SymbolPin& pin) noexcept;
91  void removePin(SymbolPin& pin) noexcept;
92  void addCircle(Circle& circle) noexcept;
93  void removeCircle(Circle& circle) noexcept;
94  void addPolygon(Polygon& polygon) noexcept;
95  void removePolygon(Polygon& polygon) noexcept;
96  void addText(Text& text) noexcept;
97  void removeText(Text& text) noexcept;
98  void setSelectionRect(const QRectF rect) noexcept;
99 
100  // Inherited from QGraphicsItem
101  QRectF boundingRect() const noexcept override { return QRectF(); }
102  QPainterPath shape() const noexcept override { return QPainterPath(); }
103  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
104  QWidget* widget = 0) noexcept override;
105 
106  // Operator Overloadings
107  SymbolGraphicsItem& operator=(const SymbolGraphicsItem& rhs) = delete;
108 
109 private: // Data
113  QHash<const Circle*, QSharedPointer<CircleGraphicsItem>> mCircleGraphicsItems;
114  QHash<const Polygon*, QSharedPointer<PolygonGraphicsItem>>
116  QHash<const Text*, QSharedPointer<TextGraphicsItem>> mTextGraphicsItems;
117 };
118 
119 /*******************************************************************************
120  * End of File
121  ******************************************************************************/
122 
123 } // namespace library
124 } // namespace librepcb
125 
126 #endif // LIBREPCB_LIBRARY_SYMBOLGRAPHICSITEM_H
QRectF boundingRect() const noexceptoverride
Definition: symbolgraphicsitem.h:101
QList< QSharedPointer< SymbolPinGraphicsItem > > getSelectedPins() noexcept
Definition: symbolgraphicsitem.cpp:142
The PolygonGraphicsItem class.
Definition: polygongraphicsitem.h:49
SymbolPinGraphicsItem * getPinGraphicsItem(const Uuid &pin) noexcept
Definition: symbolgraphicsitem.cpp:73
CircleGraphicsItem * getCircleGraphicsItem(const Circle &circle) noexcept
Definition: symbolgraphicsitem.cpp:78
QList< QSharedPointer< PolygonGraphicsItem > > getSelectedPolygons() noexcept
Definition: symbolgraphicsitem.cpp:166
void setPosition(const Point &pos) noexcept
Definition: symbolgraphicsitem.cpp:192
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0) noexceptoverride
Definition: symbolgraphicsitem.cpp:276
Symbol & mSymbol
Definition: symbolgraphicsitem.h:110
QHash< const Polygon *, QSharedPointer< PolygonGraphicsItem > > mPolygonGraphicsItems
Definition: symbolgraphicsitem.h:115
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
void removeCircle(Circle &circle) noexcept
Definition: symbolgraphicsitem.cpp:219
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
QHash< const Circle *, QSharedPointer< CircleGraphicsItem > > mCircleGraphicsItems
Definition: symbolgraphicsitem.h:113
QList< QSharedPointer< CircleGraphicsItem > > getSelectedCircles() noexcept
Definition: symbolgraphicsitem.cpp:154
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
QHash< Uuid, QSharedPointer< SymbolPinGraphicsItem > > mPinGraphicsItems
Definition: symbolgraphicsitem.h:112
void setRotation(const Angle &rot) noexcept
Definition: symbolgraphicsitem.cpp:196
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
void addCircle(Circle &circle) noexcept
Definition: symbolgraphicsitem.cpp:212
QHash< const Text *, QSharedPointer< TextGraphicsItem > > mTextGraphicsItems
Definition: symbolgraphicsitem.h:116
The SymbolPinGraphicsItem class.
Definition: symbolpingraphicsitem.h:56
void setSelectionRect(const QRectF rect) noexcept
Definition: symbolgraphicsitem.cpp:248
void addPin(SymbolPin &pin) noexcept
Definition: symbolgraphicsitem.cpp:200
void addText(Text &text) noexcept
Definition: symbolgraphicsitem.cpp:236
The Circle class.
Definition: circle.h:76
The CircleGraphicsItem class.
Definition: circlegraphicsitem.h:49
void removeText(Text &text) noexcept
Definition: symbolgraphicsitem.cpp:243
TextGraphicsItem * getTextGraphicsItem(const Text &text) noexcept
Definition: symbolgraphicsitem.cpp:88
~SymbolGraphicsItem() noexcept
Definition: symbolgraphicsitem.cpp:65
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:61
QPainterPath shape() const noexceptoverride
Definition: symbolgraphicsitem.h:102
void removePin(SymbolPin &pin) noexcept
Definition: symbolgraphicsitem.cpp:207
int getItemsAtPosition(const Point &pos, QList< QSharedPointer< SymbolPinGraphicsItem >> *pins, QList< QSharedPointer< CircleGraphicsItem >> *circles, QList< QSharedPointer< PolygonGraphicsItem >> *polygons, QList< QSharedPointer< TextGraphicsItem >> *texts) noexcept
Definition: symbolgraphicsitem.cpp:93
The Text class.
Definition: text.h:75
const IF_GraphicsLayerProvider & mLayerProvider
Definition: symbolgraphicsitem.h:111
The SymbolPin class represents one pin of a symbol.
Definition: symbolpin.h:54
The TextGraphicsItem class is the graphical representation of a librepcb::Text.
Definition: textgraphicsitem.h:51
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Polygon class.
Definition: polygon.h:76
void addPolygon(Polygon &polygon) noexcept
Definition: symbolgraphicsitem.cpp:224
void removePolygon(Polygon &polygon) noexcept
Definition: symbolgraphicsitem.cpp:231
PolygonGraphicsItem * getPolygonGraphicsItem(const Polygon &polygon) noexcept
Definition: symbolgraphicsitem.cpp:83
QList< QSharedPointer< TextGraphicsItem > > getSelectedTexts() noexcept
Definition: symbolgraphicsitem.cpp:178