LibrePCB Developers Documentation
Loading...
Searching...
No Matches
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_EDITOR_SYMBOLGRAPHICSITEM_H
21#define LIBREPCB_EDITOR_SYMBOLGRAPHICSITEM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
29
30#include <QtCore>
31#include <QtWidgets>
32
33#include <memory>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39namespace editor {
40
41class CircleGraphicsItem;
42class GraphicsLayerList;
43class ImageGraphicsItem;
44class PolygonGraphicsItem;
45class SymbolPinGraphicsItem;
46class TextGraphicsItem;
47
48/*******************************************************************************
49 * Class SymbolGraphicsItem
50 ******************************************************************************/
51
55class SymbolGraphicsItem final : public QGraphicsItemGroup {
56public:
57 enum class FindFlag {
58 // Item types
59 Pins = (1 << 0),
60 Circles = (1 << 1),
61 Polygons = (1 << 2),
62 Texts = (1 << 3),
63 Images = (1 << 4),
65
66 // Match behavior
67 AcceptNearMatch = (1 << 10),
68 };
69 Q_DECLARE_FLAGS(FindFlags, FindFlag)
70
71 // Constructors / Destructor
73 SymbolGraphicsItem(const SymbolGraphicsItem& other) = delete;
74 SymbolGraphicsItem(Symbol& symbol, const GraphicsLayerList& layers,
75 QPointer<const Component> cmp,
76 std::shared_ptr<const ComponentSymbolVariantItem> cmpItem,
77 const QStringList& localeOrder,
78 bool hideUnusedPins) noexcept;
79 ~SymbolGraphicsItem() noexcept;
80
81 // Getters
83 std::shared_ptr<SymbolPin> pin) noexcept {
84 return mPinGraphicsItems.value(pin);
85 }
86 std::shared_ptr<CircleGraphicsItem> getGraphicsItem(
87 std::shared_ptr<Circle> circle) noexcept {
88 return mCircleGraphicsItems.value(circle);
89 }
90 std::shared_ptr<PolygonGraphicsItem> getGraphicsItem(
91 std::shared_ptr<Polygon> polygon) noexcept {
92 return mPolygonGraphicsItems.value(polygon);
93 }
94 std::shared_ptr<TextGraphicsItem> getGraphicsItem(
95 std::shared_ptr<Text> text) noexcept {
96 return mTextGraphicsItems.value(text);
97 }
98 std::shared_ptr<ImageGraphicsItem> getGraphicsItem(
99 std::shared_ptr<Image> iamge) noexcept {
100 return mImageGraphicsItems.value(iamge);
101 }
102 QList<std::shared_ptr<SymbolPinGraphicsItem>> getSelectedPins() noexcept;
103 QList<std::shared_ptr<CircleGraphicsItem>> getSelectedCircles() noexcept;
104 QList<std::shared_ptr<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
105 QList<std::shared_ptr<TextGraphicsItem>> getSelectedTexts() noexcept;
106 QList<std::shared_ptr<ImageGraphicsItem>> getSelectedImages() noexcept;
107 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
108 const QPainterPath& posAreaSmall, const QPainterPath& posAreaLarge,
109 FindFlags flags) noexcept;
110
111 // Setters
112 void setPosition(const Point& pos) noexcept;
113 void setRotation(const Angle& rot) noexcept;
114
115 // General Methods
116 void updateAllTexts() noexcept;
117 void setSelectionRect(const QRectF rect) noexcept;
118
119 // Operator Overloadings
120 SymbolGraphicsItem& operator=(const SymbolGraphicsItem& rhs) = delete;
121
122private: // Methods
123 void syncPins() noexcept;
124 void syncCircles() noexcept;
125 void syncPolygons() noexcept;
126 void syncTexts() noexcept;
127 void syncImages() noexcept;
128 void symbolEdited(const Symbol& symbol, Symbol::Event event) noexcept;
129 void substituteText(TextGraphicsItem& text) noexcept;
130
131private: // Data
134 QPointer<const Component> mComponent; // Can be nullptr.
135 std::shared_ptr<const ComponentSymbolVariantItem> mItem; // Can be nullptr.
136 const QStringList mLocaleOrder;
137 const bool mHideUnusedPins;
138 QMap<std::shared_ptr<SymbolPin>, std::shared_ptr<SymbolPinGraphicsItem>>
140 QMap<std::shared_ptr<Circle>, std::shared_ptr<CircleGraphicsItem>>
142 QMap<std::shared_ptr<Polygon>, std::shared_ptr<PolygonGraphicsItem>>
144 QMap<std::shared_ptr<Text>, std::shared_ptr<TextGraphicsItem>>
146 QMap<std::shared_ptr<Image>, std::shared_ptr<ImageGraphicsItem>>
148
149 // Slots
150 Symbol::OnEditedSlot mOnEditedSlot;
151};
152
153} // namespace editor
154} // namespace librepcb
155
156Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::SymbolGraphicsItem::FindFlags)
157
158/*******************************************************************************
159 * End of File
160 ******************************************************************************/
161
162#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The Circle class.
Definition circle.h:46
The Component class represents a "generic" device in the library.
Definition component.h:73
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition componentsymbolvariantitem.h:54
The Image class.
Definition image.h:49
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Polygon class.
Definition polygon.h:45
The Symbol class represents the part of a component which is added to schematics.
Definition symbol.h:56
The SymbolPin class represents one pin of a symbol.
Definition symbolpin.h:51
The Text class.
Definition text.h:48
The CircleGraphicsItem class.
Definition circlegraphicsitem.h:48
The GraphicsLayerList class.
Definition graphicslayerlist.h:48
The ImageGraphicsItem class is the graphical representation of a librepcb::Image.
Definition imagegraphicsitem.h:52
The PolygonGraphicsItem class.
Definition polygongraphicsitem.h:48
The SymbolGraphicsItem class.
Definition symbolgraphicsitem.h:55
std::shared_ptr< CircleGraphicsItem > getGraphicsItem(std::shared_ptr< Circle > circle) noexcept
Definition symbolgraphicsitem.h:86
QMap< std::shared_ptr< Polygon >, std::shared_ptr< PolygonGraphicsItem > > mPolygonGraphicsItems
Definition symbolgraphicsitem.h:143
QPointer< const Component > mComponent
Definition symbolgraphicsitem.h:134
std::shared_ptr< const ComponentSymbolVariantItem > mItem
Definition symbolgraphicsitem.h:135
void syncCircles() noexcept
Definition symbolgraphicsitem.cpp:281
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const QPainterPath &posAreaSmall, const QPainterPath &posAreaLarge, FindFlags flags) noexcept
Definition symbolgraphicsitem.cpp:134
QList< std::shared_ptr< CircleGraphicsItem > > getSelectedCircles() noexcept
Definition symbolgraphicsitem.cpp:91
Symbol & mSymbol
Definition symbolgraphicsitem.h:132
std::shared_ptr< SymbolPinGraphicsItem > getGraphicsItem(std::shared_ptr< SymbolPin > pin) noexcept
Definition symbolgraphicsitem.h:82
void syncImages() noexcept
Definition symbolgraphicsitem.cpp:351
const GraphicsLayerList & mLayers
Definition symbolgraphicsitem.h:133
QList< std::shared_ptr< PolygonGraphicsItem > > getSelectedPolygons() noexcept
Definition symbolgraphicsitem.cpp:102
QList< std::shared_ptr< ImageGraphicsItem > > getSelectedImages() noexcept
Definition symbolgraphicsitem.cpp:124
void symbolEdited(const Symbol &symbol, Symbol::Event event) noexcept
Definition symbolgraphicsitem.cpp:376
std::shared_ptr< ImageGraphicsItem > getGraphicsItem(std::shared_ptr< Image > iamge) noexcept
Definition symbolgraphicsitem.h:98
void updateAllTexts() noexcept
Definition symbolgraphicsitem.cpp:220
std::shared_ptr< TextGraphicsItem > getGraphicsItem(std::shared_ptr< Text > text) noexcept
Definition symbolgraphicsitem.h:94
QMap< std::shared_ptr< Circle >, std::shared_ptr< CircleGraphicsItem > > mCircleGraphicsItems
Definition symbolgraphicsitem.h:141
void syncPins() noexcept
Definition symbolgraphicsitem.cpp:258
FindFlag
Definition symbolgraphicsitem.h:57
void syncTexts() noexcept
Definition symbolgraphicsitem.cpp:328
void setSelectionRect(const QRectF rect) noexcept
Definition symbolgraphicsitem.cpp:229
QMap< std::shared_ptr< Image >, std::shared_ptr< ImageGraphicsItem > > mImageGraphicsItems
Definition symbolgraphicsitem.h:147
std::shared_ptr< PolygonGraphicsItem > getGraphicsItem(std::shared_ptr< Polygon > polygon) noexcept
Definition symbolgraphicsitem.h:90
void setRotation(const Angle &rot) noexcept
Definition symbolgraphicsitem.cpp:216
QList< std::shared_ptr< TextGraphicsItem > > getSelectedTexts() noexcept
Definition symbolgraphicsitem.cpp:113
QMap< std::shared_ptr< SymbolPin >, std::shared_ptr< SymbolPinGraphicsItem > > mPinGraphicsItems
Definition symbolgraphicsitem.h:139
void syncPolygons() noexcept
Definition symbolgraphicsitem.cpp:304
Symbol::OnEditedSlot mOnEditedSlot
Definition symbolgraphicsitem.h:150
void substituteText(TextGraphicsItem &text) noexcept
Definition symbolgraphicsitem.cpp:400
const bool mHideUnusedPins
Definition symbolgraphicsitem.h:137
const QStringList mLocaleOrder
Definition symbolgraphicsitem.h:136
void setPosition(const Point &pos) noexcept
Definition symbolgraphicsitem.cpp:212
QMap< std::shared_ptr< Text >, std::shared_ptr< TextGraphicsItem > > mTextGraphicsItems
Definition symbolgraphicsitem.h:145
QList< std::shared_ptr< SymbolPinGraphicsItem > > getSelectedPins() noexcept
Definition symbolgraphicsitem.cpp:80
The SymbolPinGraphicsItem class.
Definition symbolpingraphicsitem.h:50
The TextGraphicsItem class is the graphical representation of a librepcb::Text.
Definition textgraphicsitem.h:49
Definition occmodel.cpp:77
Definition uuid.h:186