LibrePCB Developers Documentation
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 ******************************************************************************/
28
29#include <QtCore>
30#include <QtWidgets>
31
32#include <memory>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39class Component;
40
41namespace editor {
42
43class CircleGraphicsItem;
44class IF_GraphicsLayerProvider;
45class PolygonGraphicsItem;
46class SymbolPinGraphicsItem;
47class TextGraphicsItem;
48
49/*******************************************************************************
50 * Class SymbolGraphicsItem
51 ******************************************************************************/
52
56class SymbolGraphicsItem final : public QGraphicsItemGroup {
57public:
58 enum class FindFlag {
59 // Item types
60 Pins = (1 << 0),
61 Circles = (1 << 1),
62 Polygons = (1 << 2),
63 Texts = (1 << 3),
64 All = Pins | Circles | Polygons | Texts,
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;
75 Symbol& symbol, const IF_GraphicsLayerProvider& lp,
76 std::shared_ptr<const Component> cmp = nullptr,
77 std::shared_ptr<const ComponentSymbolVariantItem> cmpItem = nullptr,
78 const QStringList& localeOrder = {}) 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 QList<std::shared_ptr<SymbolPinGraphicsItem>> getSelectedPins() noexcept;
99 QList<std::shared_ptr<CircleGraphicsItem>> getSelectedCircles() noexcept;
100 QList<std::shared_ptr<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
101 QList<std::shared_ptr<TextGraphicsItem>> getSelectedTexts() noexcept;
102 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
103 const QPainterPath& posAreaSmall, const QPainterPath& posAreaLarge,
104 FindFlags flags) noexcept;
105
106 // Setters
107 void setPosition(const Point& pos) noexcept;
108 void setRotation(const Angle& rot) noexcept;
109
110 // General Methods
111 void updateAllTexts() noexcept;
112 void setSelectionRect(const QRectF rect) noexcept;
113
114 // Operator Overloadings
115 SymbolGraphicsItem& operator=(const SymbolGraphicsItem& rhs) = delete;
116
117private: // Methods
118 void syncPins() noexcept;
119 void syncCircles() noexcept;
120 void syncPolygons() noexcept;
121 void syncTexts() noexcept;
122 void symbolEdited(const Symbol& symbol, Symbol::Event event) noexcept;
123 void substituteText(TextGraphicsItem& text) noexcept;
124
125private: // Data
128 std::shared_ptr<const Component> mComponent; // Can be nullptr.
129 std::shared_ptr<const ComponentSymbolVariantItem> mItem; // Can be nullptr.
130 QStringList mLocaleOrder;
131 QMap<std::shared_ptr<SymbolPin>, std::shared_ptr<SymbolPinGraphicsItem>>
133 QMap<std::shared_ptr<Circle>, std::shared_ptr<CircleGraphicsItem>>
135 QMap<std::shared_ptr<Polygon>, std::shared_ptr<PolygonGraphicsItem>>
137 QMap<std::shared_ptr<Text>, std::shared_ptr<TextGraphicsItem>>
139
140 // Slots
141 Symbol::OnEditedSlot mOnEditedSlot;
142};
143
144} // namespace editor
145} // namespace librepcb
146
147Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::SymbolGraphicsItem::FindFlags)
148
149/*******************************************************************************
150 * End of File
151 ******************************************************************************/
152
153#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
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 Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The Polygon class.
Definition: polygon.h:45
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
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 IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition: graphicslayer.h:111
The PolygonGraphicsItem class.
Definition: polygongraphicsitem.h:48
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:56
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:136
std::shared_ptr< const ComponentSymbolVariantItem > mItem
Definition: symbolgraphicsitem.h:129
void syncCircles() noexcept
Definition: symbolgraphicsitem.cpp:257
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const QPainterPath &posAreaSmall, const QPainterPath &posAreaLarge, FindFlags flags) noexcept
Definition: symbolgraphicsitem.cpp:121
std::shared_ptr< const Component > mComponent
Definition: symbolgraphicsitem.h:128
QList< std::shared_ptr< CircleGraphicsItem > > getSelectedCircles() noexcept
Definition: symbolgraphicsitem.cpp:89
Symbol & mSymbol
Definition: symbolgraphicsitem.h:126
std::shared_ptr< SymbolPinGraphicsItem > getGraphicsItem(std::shared_ptr< SymbolPin > pin) noexcept
Definition: symbolgraphicsitem.h:82
QList< std::shared_ptr< PolygonGraphicsItem > > getSelectedPolygons() noexcept
Definition: symbolgraphicsitem.cpp:100
void symbolEdited(const Symbol &symbol, Symbol::Event event) noexcept
Definition: symbolgraphicsitem.cpp:328
void updateAllTexts() noexcept
Definition: symbolgraphicsitem.cpp:200
const IF_GraphicsLayerProvider & mLayerProvider
Definition: symbolgraphicsitem.h:127
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:134
void syncPins() noexcept
Definition: symbolgraphicsitem.cpp:234
FindFlag
Definition: symbolgraphicsitem.h:58
void syncTexts() noexcept
Definition: symbolgraphicsitem.cpp:305
void setSelectionRect(const QRectF rect) noexcept
Definition: symbolgraphicsitem.cpp:209
std::shared_ptr< PolygonGraphicsItem > getGraphicsItem(std::shared_ptr< Polygon > polygon) noexcept
Definition: symbolgraphicsitem.h:90
void setRotation(const Angle &rot) noexcept
Definition: symbolgraphicsitem.cpp:196
QList< std::shared_ptr< TextGraphicsItem > > getSelectedTexts() noexcept
Definition: symbolgraphicsitem.cpp:111
QMap< std::shared_ptr< SymbolPin >, std::shared_ptr< SymbolPinGraphicsItem > > mPinGraphicsItems
Definition: symbolgraphicsitem.h:132
void syncPolygons() noexcept
Definition: symbolgraphicsitem.cpp:280
Symbol::OnEditedSlot mOnEditedSlot
Definition: symbolgraphicsitem.h:141
~SymbolGraphicsItem() noexcept
Definition: symbolgraphicsitem.cpp:70
void substituteText(TextGraphicsItem &text) noexcept
Definition: symbolgraphicsitem.cpp:349
QStringList mLocaleOrder
Definition: symbolgraphicsitem.h:130
void setPosition(const Point &pos) noexcept
Definition: symbolgraphicsitem.cpp:192
QMap< std::shared_ptr< Text >, std::shared_ptr< TextGraphicsItem > > mTextGraphicsItems
Definition: symbolgraphicsitem.h:138
QList< std::shared_ptr< SymbolPinGraphicsItem > > getSelectedPins() noexcept
Definition: symbolgraphicsitem.cpp:78
The SymbolPinGraphicsItem class.
Definition: symbolpingraphicsitem.h:53
The TextGraphicsItem class is the graphical representation of a librepcb::Text.
Definition: textgraphicsitem.h:49
Definition: occmodel.cpp:77