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 
58 class SymbolGraphicsItem final : public QGraphicsItem {
59 public:
60  // Constructors / Destructor
61  SymbolGraphicsItem() = delete;
62  SymbolGraphicsItem(const SymbolGraphicsItem& other) = delete;
63  SymbolGraphicsItem(Symbol& symbol,
64  const IF_GraphicsLayerProvider& lp) noexcept;
65  ~SymbolGraphicsItem() noexcept;
66 
67  // Getters
68  SymbolPinGraphicsItem* getPinGraphicsItem(const Uuid& pin) noexcept;
69  CircleGraphicsItem* getCircleGraphicsItem(const Circle& circle) noexcept;
70  PolygonGraphicsItem* getPolygonGraphicsItem(const Polygon& polygon) noexcept;
71  TextGraphicsItem* getTextGraphicsItem(const Text& text) noexcept;
73  const Point& pos, QList<QSharedPointer<SymbolPinGraphicsItem>>* pins,
74  QList<QSharedPointer<CircleGraphicsItem>>* circles,
75  QList<QSharedPointer<PolygonGraphicsItem>>* polygons,
76  QList<QSharedPointer<TextGraphicsItem>>* texts) noexcept;
77  QList<QSharedPointer<SymbolPinGraphicsItem>> getSelectedPins() noexcept;
78  QList<QSharedPointer<CircleGraphicsItem>> getSelectedCircles() noexcept;
79  QList<QSharedPointer<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
80  QList<QSharedPointer<TextGraphicsItem>> getSelectedTexts() noexcept;
81 
82  // Setters
83  void setPosition(const Point& pos) noexcept;
84  void setRotation(const Angle& rot) noexcept;
85 
86  // General Methods
87  void addPin(SymbolPin& pin) noexcept;
88  void removePin(SymbolPin& pin) noexcept;
89  void addCircle(Circle& circle) noexcept;
90  void removeCircle(Circle& circle) noexcept;
91  void addPolygon(Polygon& polygon) noexcept;
92  void removePolygon(Polygon& polygon) noexcept;
93  void addText(Text& text) noexcept;
94  void removeText(Text& text) noexcept;
95  void setSelectionRect(const QRectF rect) noexcept;
96 
97  // Inherited from QGraphicsItem
98  QRectF boundingRect() const noexcept override { return QRectF(); }
99  QPainterPath shape() const noexcept override { return QPainterPath(); }
100  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
101  QWidget* widget = 0) noexcept override;
102 
103  // Operator Overloadings
104  SymbolGraphicsItem& operator=(const SymbolGraphicsItem& rhs) = delete;
105 
106 private: // Data
110  QHash<const Circle*, QSharedPointer<CircleGraphicsItem>> mCircleGraphicsItems;
111  QHash<const Polygon*, QSharedPointer<PolygonGraphicsItem>>
113  QHash<const Text*, QSharedPointer<TextGraphicsItem>> mTextGraphicsItems;
114 };
115 
116 /*******************************************************************************
117  * End of File
118  ******************************************************************************/
119 
120 } // namespace library
121 } // namespace librepcb
122 
123 #endif // LIBREPCB_LIBRARY_SYMBOLGRAPHICSITEM_H
QRectF boundingRect() const noexceptoverride
Definition: symbolgraphicsitem.h:98
QList< QSharedPointer< SymbolPinGraphicsItem > > getSelectedPins() noexcept
Definition: symbolgraphicsitem.cpp:142
The PolygonGraphicsItem class.
Definition: polygongraphicsitem.h:46
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:107
QHash< const Polygon *, QSharedPointer< PolygonGraphicsItem > > mPolygonGraphicsItems
Definition: symbolgraphicsitem.h:112
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
void removeCircle(Circle &circle) noexcept
Definition: symbolgraphicsitem.cpp:219
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
QHash< const Circle *, QSharedPointer< CircleGraphicsItem > > mCircleGraphicsItems
Definition: symbolgraphicsitem.h:110
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:109
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:78
void addCircle(Circle &circle) noexcept
Definition: symbolgraphicsitem.cpp:212
QHash< const Text *, QSharedPointer< TextGraphicsItem > > mTextGraphicsItems
Definition: symbolgraphicsitem.h:113
The SymbolPinGraphicsItem class.
Definition: symbolpingraphicsitem.h:53
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:47
The CircleGraphicsItem class.
Definition: circlegraphicsitem.h:46
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:58
QPainterPath shape() const noexceptoverride
Definition: symbolgraphicsitem.h:99
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:48
const IF_GraphicsLayerProvider & mLayerProvider
Definition: symbolgraphicsitem.h:108
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:48
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Polygon class.
Definition: polygon.h:49
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