17 #include <QGraphicsEllipseItem>
18 #include <QGraphicsPolygonItem>
19 #include <QGraphicsScene>
20 #include <QGraphicsSceneContextMenuEvent>
23 #include <QTextStream>
32 const QString &identifier,
33 const QPointF &posScreen,
40 m_graphicsItemEllipse (nullptr),
41 m_shadowZeroWidthEllipse (nullptr),
42 m_graphicsItemPolygon (nullptr),
43 m_shadowZeroWidthPolygon (nullptr),
44 m_identifier (identifier),
45 m_posScreen (posScreen),
47 m_lineWidth (lineWidth),
50 m_geometryWindow (geometryWindow)
53 <<
" identifier=" << identifier.toLatin1 ().data ();
55 createPointEllipse (radius);
59 const QString &identifier,
60 const QPointF &posScreen,
62 const QPolygonF &polygon,
67 m_graphicsItemEllipse (nullptr),
68 m_shadowZeroWidthEllipse (nullptr),
69 m_graphicsItemPolygon (nullptr),
70 m_shadowZeroWidthPolygon (nullptr),
71 m_identifier (identifier),
72 m_posScreen (posScreen),
74 m_lineWidth (lineWidth),
77 m_geometryWindow (geometryWindow)
80 <<
" identifier=" << identifier.toLatin1 ().data ();
82 createPointPolygon (polygon);
89 if (m_graphicsItemEllipse ==
nullptr) {
91 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
94 scene->removeItem (m_graphicsItemPolygon);
95 delete m_graphicsItemPolygon;
96 m_graphicsItemPolygon =
nullptr;
97 m_shadowZeroWidthPolygon =
nullptr;
102 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
105 scene->removeItem (m_graphicsItemEllipse);
106 delete m_graphicsItemEllipse;
107 m_graphicsItemEllipse =
nullptr;
108 m_shadowZeroWidthEllipse =
nullptr;
115 if (m_graphicsItemEllipse ==
nullptr) {
116 return m_graphicsItemPolygon->boundingRect ();
118 return m_graphicsItemEllipse->boundingRect ();
122 void GraphicsPoint::createPointEllipse (
unsigned int radius)
126 const int radiusSigned = signed (radius);
128 QRect (- radiusSigned,
130 2 * radiusSigned + 1,
131 2 * radiusSigned + 1));
132 m_scene.addItem (m_graphicsItemEllipse);
137 m_graphicsItemEllipse->setPos (m_posScreen.x (),
139 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
140 m_graphicsItemEllipse->setEnabled (
true);
141 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
142 QGraphicsItem::ItemIsMovable |
143 QGraphicsItem::ItemSendsGeometryChanges);
145 if (m_geometryWindow !=
nullptr) {
146 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
147 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
153 QRect (- radiusSigned,
155 2 * radiusSigned + 1,
156 2 * radiusSigned + 1));
157 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
159 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color),
ZERO_WIDTH));
160 m_shadowZeroWidthEllipse->setEnabled (
true);
162 m_graphicsItemEllipse->
setShadow (m_shadowZeroWidthEllipse);
165 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
171 m_scene.addItem (m_graphicsItemPolygon);
176 m_graphicsItemPolygon->setPos (m_posScreen.x (),
178 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
179 m_graphicsItemPolygon->setEnabled (
true);
180 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
181 QGraphicsItem::ItemIsMovable |
182 QGraphicsItem::ItemSendsGeometryChanges);
184 if (m_geometryWindow !=
nullptr) {
185 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
186 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
193 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
195 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color),
ZERO_WIDTH));
196 m_shadowZeroWidthPolygon->setEnabled (
true);
198 m_graphicsItemPolygon->
setShadow (m_shadowZeroWidthPolygon);
203 if (m_graphicsItemEllipse ==
nullptr) {
204 return m_graphicsItemPolygon->data (key);
206 return m_graphicsItemEllipse->data (key);
212 return m_highlightOpacity;
217 if (m_graphicsItemEllipse ==
nullptr) {
218 return m_graphicsItemPolygon->pos ();
220 return m_graphicsItemEllipse->pos ();
226 double ordinalKey)
const
228 str << indentation <<
"GraphicsPoint\n";
235 if (m_graphicsItemEllipse ==
nullptr) {
237 pointType =
"polygon";
238 pos = m_graphicsItemPolygon->pos();
241 pointType =
"ellipse";
242 pos = m_graphicsItemEllipse->pos();
247 str << indentation << identifier
248 <<
" ordinalKey=" << ordinalKey
262 <<
" key=" <<
dataKeyToString (static_cast<DataKey> (key)).toLatin1().data()
263 <<
" data=" <<
data.toString().toLatin1().data();
265 if (m_graphicsItemEllipse ==
nullptr) {
266 m_graphicsItemPolygon->setData (key,
data);
268 m_graphicsItemEllipse->setData (key,
data);
275 <<
" identifier=" << m_identifier.toLatin1().data()
283 if (m_graphicsItemEllipse ==
nullptr) {
284 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsFocusable,
false);
285 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsMovable,
false);
286 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsSelectable,
false);
288 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsFocusable,
false);
289 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsMovable,
false);
290 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsSelectable,
false);
298 if (m_graphicsItemEllipse ==
nullptr) {
302 delete m_graphicsItemPolygon;
303 m_graphicsItemPolygon =
nullptr;
304 m_shadowZeroWidthPolygon =
nullptr;
306 createPointEllipse (
unsigned (pointStyle.
radius()));
315 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
316 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
323 delete m_graphicsItemEllipse;
324 m_graphicsItemEllipse =
nullptr;
325 m_shadowZeroWidthEllipse =
nullptr;
327 createPointPolygon (pointStyle.
polygon());
344 if (m_graphicsItemEllipse ==
nullptr) {
345 m_graphicsItemPolygon->setPos (
pos);
347 m_graphicsItemEllipse->setPos (
pos);