Engauge Digitizer 2
Loading...
Searching...
No Matches
GraphicsPoint Class Reference

Graphics item for drawing a circular or polygonal Point. More...

#include <GraphicsPoint.h>

Inheritance diagram for GraphicsPoint:
Inheritance graph
Collaboration diagram for GraphicsPoint:
Collaboration graph

Public Member Functions

 GraphicsPoint (QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, unsigned int radius, double lineWidth, GeometryWindow *geometryWindow)
 Constructor of circular point.
 GraphicsPoint (QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, const QPolygonF &polygon, double lineWidth, GeometryWindow *geometryWindow)
 Constructor of polygon point.
 ~GraphicsPoint ()
 Destructor. This remove the graphics item from the scene.
QRectF boundingRect () const
 Proxy method for QGraphicsItem::boundingRect.
QVariant data (int key) const
 Proxy method for QGraphicsItem::data.
double highlightOpacity () const
 Get method for highlight opacity.
QPointF pos () const
 Proxy method for QGraphicsItem::pos.
void printStream (QString indentation, QTextStream &str, double ordinalKey) const
 Debugging method that supports print method of this class and printStream method of some other class(es)
void reset ()
 Mark point as unwanted, and unbind any bound lines.
void setData (int key, const QVariant &data)
 Proxy method for QGraphicsItem::setData.
void setHighlightOpacity (double highlightOpacity)
 Set method for highlight opacity.
void setPointStyle (const PointStyle &pointStyle)
 Update the point style.
void setPos (const QPointF pos)
 Update the position.
void setPassive ()
 Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work properly.
void setWanted ()
 Mark point as wanted. Marking as unwanted is done by the reset function.
void updateCurveStyle (const CurveStyle &curveStyle)
 Update point and line styles that comprise the curve style.
bool wanted () const
 Identify point as wanted//unwanted.
Public Member Functions inherited from GraphicsPointAbstractBase
 GraphicsPointAbstractBase ()
 Single constructor.
virtual ~GraphicsPointAbstractBase ()

Detailed Description

Graphics item for drawing a circular or polygonal Point.

In this class, lines are drawn twice: 1) As nonzero-width lines so user can have thick, and highly visible, points 2) As a 'shadow' with zero-width lines since these always appear even when zooming results in some pixel rows/columns disappearing This dual-line approach is better than using QGraphicsItem::ItemIgnoresTransformations to prevent horrible aliasing problems, since that approach involves complicated transformation matrix manipulations

Layering is used for the single graphics item contained by this class. External code only has to deal with this single class, and there is no multiple inheritance involved. If inheritance was used, we would have one class based on QGraphicsEllipseItem and another on QGraphicsPolygonItem, so having a single class (for the convenience of the external code) would involve multiple inheritance (of those two classes). With the inheritance approach, using just the methods supplied by QGraphicsItem would be inadequate.

Definition at line 43 of file GraphicsPoint.h.

Constructor & Destructor Documentation

◆ GraphicsPoint() [1/2]

GraphicsPoint::GraphicsPoint ( QGraphicsScene & scene,
const QString & identifier,
const QPointF & posScreen,
const QColor & color,
unsigned int radius,
double lineWidth,
GeometryWindow * geometryWindow )

Constructor of circular point.

Definition at line 31 of file GraphicsPoint.cpp.

37 :
39 m_scene (scene),
40 m_graphicsItemEllipse (nullptr),
41 m_shadowZeroWidthEllipse (nullptr),
42 m_graphicsItemPolygon (nullptr),
43 m_shadowZeroWidthPolygon (nullptr),
44 m_identifier (identifier),
45 m_posScreen (posScreen),
46 m_color (color),
47 m_lineWidth (lineWidth),
48 m_wanted (true),
49 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
50 m_geometryWindow (geometryWindow)
51{
52 createPointEllipse (radius);
53}
const double DEFAULT_HIGHLIGHT_OPACITY
GraphicsPointAbstractBase()
Single constructor.

◆ GraphicsPoint() [2/2]

GraphicsPoint::GraphicsPoint ( QGraphicsScene & scene,
const QString & identifier,
const QPointF & posScreen,
const QColor & color,
const QPolygonF & polygon,
double lineWidth,
GeometryWindow * geometryWindow )

Constructor of polygon point.

Definition at line 55 of file GraphicsPoint.cpp.

61 :
63 m_scene (scene),
64 m_graphicsItemEllipse (nullptr),
65 m_shadowZeroWidthEllipse (nullptr),
66 m_graphicsItemPolygon (nullptr),
67 m_shadowZeroWidthPolygon (nullptr),
68 m_identifier (identifier),
69 m_posScreen (posScreen),
70 m_color (color),
71 m_lineWidth (lineWidth),
72 m_wanted (true),
73 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
74 m_geometryWindow (geometryWindow)
75{
76 createPointPolygon (polygon);
77}

◆ ~GraphicsPoint()

GraphicsPoint::~GraphicsPoint ( )

Destructor. This remove the graphics item from the scene.

Definition at line 79 of file GraphicsPoint.cpp.

80{
81 if (m_graphicsItemEllipse == nullptr) {
82
83 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
84
85 // Since m_shadowZeroWidthPolygon is a child of m_graphicsItemPolygon, removing the parent removes both
86 scene->removeItem (m_graphicsItemPolygon);
87 delete m_graphicsItemPolygon;
88 m_graphicsItemPolygon = nullptr;
89 m_shadowZeroWidthPolygon = nullptr;
90
91
92 } else {
93
94 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
95
96 // Since m_shadowZeroWidthEllipse is a child of m_graphicsItemEllipse, removing the parent removes both
97 scene->removeItem (m_graphicsItemEllipse);
98 delete m_graphicsItemEllipse;
99 m_graphicsItemEllipse = nullptr;
100 m_shadowZeroWidthEllipse = nullptr;
101
102 }
103}

Member Function Documentation

◆ boundingRect()

QRectF GraphicsPoint::boundingRect ( ) const

Proxy method for QGraphicsItem::boundingRect.

Definition at line 105 of file GraphicsPoint.cpp.

106{
107 if (m_graphicsItemEllipse == nullptr) {
108 return m_graphicsItemPolygon->boundingRect ();
109 } else {
110 return m_graphicsItemEllipse->boundingRect ();
111 }
112}

◆ data()

QVariant GraphicsPoint::data ( int key) const

Proxy method for QGraphicsItem::data.

Definition at line 193 of file GraphicsPoint.cpp.

194{
195 if (m_graphicsItemEllipse == nullptr) {
196 return m_graphicsItemPolygon->data (key);
197 } else {
198 return m_graphicsItemEllipse->data (key);
199 }
200}

◆ highlightOpacity()

double GraphicsPoint::highlightOpacity ( ) const

Get method for highlight opacity.

Definition at line 202 of file GraphicsPoint.cpp.

203{
204 return m_highlightOpacity;
205}

◆ pos()

QPointF GraphicsPoint::pos ( ) const

Proxy method for QGraphicsItem::pos.

Definition at line 207 of file GraphicsPoint.cpp.

208{
209 if (m_graphicsItemEllipse == nullptr) {
210 return m_graphicsItemPolygon->pos ();
211 } else {
212 return m_graphicsItemEllipse->pos ();
213 }
214}

◆ printStream()

void GraphicsPoint::printStream ( QString indentation,
QTextStream & str,
double ordinalKey ) const

Debugging method that supports print method of this class and printStream method of some other class(es)

Definition at line 216 of file GraphicsPoint.cpp.

219{
220 str << indentation << "GraphicsPoint\n";
221
222 indentation += INDENTATION_DELTA;
223
224 QString identifier;
225 QString pointType;
226 QPointF pos;
227 if (m_graphicsItemEllipse == nullptr) {
228 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
229 pointType = "polygon";
230 pos = m_graphicsItemPolygon->pos();
231 } else {
232 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
233 pointType = "ellipse";
234 pos = m_graphicsItemEllipse->pos();
235 }
236
237 DataKey type = static_cast<DataKey> (data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt());
238
239 str << indentation << identifier
240 << " ordinalKey=" << ordinalKey
241 << " dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
242 << " dataType=" << dataKeyToString (type).toLatin1().data()
243 << " " << pointType << "Pos=" << QPointFToString (pos) << "\n";
244}
QString dataKeyToString(DataKey dataKey)
Definition DataKey.cpp:9
DataKey
Index values for storing item details in QGraphicsItem using setData/data.
Definition DataKey.h:13
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
const QString INDENTATION_DELTA
QString QPointFToString(const QPointF &pos)
QPointF pos() const
Proxy method for QGraphicsItem::pos.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.

◆ reset()

void GraphicsPoint::reset ( )

Mark point as unwanted, and unbind any bound lines.

Definition at line 246 of file GraphicsPoint.cpp.

247{
248 m_wanted = false;
249}

◆ setData()

void GraphicsPoint::setData ( int key,
const QVariant & data )

Proxy method for QGraphicsItem::setData.

Definition at line 251 of file GraphicsPoint.cpp.

252{
253 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setData"
254 << " key=" << dataKeyToString (static_cast<DataKey> (key)).toLatin1().data()
255 << " data=" << data.toString().toLatin1().data();
256
257 if (m_graphicsItemEllipse == nullptr) {
258 m_graphicsItemPolygon->setData (key, data);
259 } else {
260 m_graphicsItemEllipse->setData (key, data);
261 }
262}
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ setHighlightOpacity()

void GraphicsPoint::setHighlightOpacity ( double highlightOpacity)

Set method for highlight opacity.

Definition at line 264 of file GraphicsPoint.cpp.

265{
266 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setHighlightOpacity"
267 << " identifier=" << m_identifier.toLatin1().data()
268 << " highlightOpacity=" << highlightOpacity;
269
270 m_highlightOpacity = highlightOpacity;
271}
double highlightOpacity() const
Get method for highlight opacity.

◆ setPassive()

void GraphicsPoint::setPassive ( )

Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work properly.

Definition at line 273 of file GraphicsPoint.cpp.

274{
275 if (m_graphicsItemEllipse == nullptr) {
276 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsFocusable, false);
277 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsMovable, false);
278 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsSelectable, false);
279 } else {
280 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsFocusable, false);
281 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsMovable, false);
282 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsSelectable, false);
283 }
284}

◆ setPointStyle()

void GraphicsPoint::setPointStyle ( const PointStyle & pointStyle)

Update the point style.

Definition at line 286 of file GraphicsPoint.cpp.

287{
288 // Setting pen and radius of parent graphics items below also affects the child shadows
289 // (m_shadowItemPolygon and m_shadowItemEllipse)
290 if (m_graphicsItemEllipse == nullptr) {
291 if (pointStyle.shape() == POINT_SHAPE_CIRCLE) {
292
293 // Transition from non-circle to circle. Deleting parent also deletes child shadow
294 delete m_graphicsItemPolygon;
295 m_graphicsItemPolygon = nullptr;
296 m_shadowZeroWidthPolygon = nullptr;
297
298 createPointEllipse (unsigned (pointStyle.radius()));
299
300 } else {
301
302 // Update polygon
303 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
304 pointStyle.lineWidth()));
305 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
306 pointStyle.lineWidth()));
307 m_graphicsItemPolygon->setPolygon (pointStyle.polygon());
308 m_shadowZeroWidthPolygon->setPolygon (pointStyle.polygon());
309
310 }
311 } else {
312 if (pointStyle.shape() != POINT_SHAPE_CIRCLE) {
313
314 // Transition from circle to non-circlee. Deleting parent also deletes child shadow
315 delete m_graphicsItemEllipse;
316 m_graphicsItemEllipse = nullptr;
317 m_shadowZeroWidthEllipse = nullptr;
318
319 createPointPolygon (pointStyle.polygon());
320
321 } else {
322
323 // Update circle
324 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
325 pointStyle.lineWidth()));
326 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
327 pointStyle.lineWidth()));
328 m_graphicsItemEllipse->setRadius (pointStyle.radius());
329 m_shadowZeroWidthEllipse->setRadius (pointStyle.radius());
330 }
331 }
332}
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
@ POINT_SHAPE_CIRCLE
Definition PointShape.h:13
unsigned int radius() const
Radius of point. For a circle this is all that is needed to draw a circle. For a polygon,...
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.
PointShape shape() const
Get method for point shape.
ColorPalette paletteColor() const
Get method for point color.
int lineWidth() const
Get method for line width.

◆ setPos()

void GraphicsPoint::setPos ( const QPointF pos)

Update the position.

Definition at line 334 of file GraphicsPoint.cpp.

335{
336 if (m_graphicsItemEllipse == nullptr) {
337 m_graphicsItemPolygon->setPos (pos);
338 } else {
339 m_graphicsItemEllipse->setPos (pos);
340 }
341}

◆ setWanted()

void GraphicsPoint::setWanted ( )

Mark point as wanted. Marking as unwanted is done by the reset function.

Definition at line 343 of file GraphicsPoint.cpp.

344{
345 m_wanted = true;
346}

◆ updateCurveStyle()

void GraphicsPoint::updateCurveStyle ( const CurveStyle & curveStyle)

Update point and line styles that comprise the curve style.

Definition at line 348 of file GraphicsPoint.cpp.

349{
350 setPointStyle (curveStyle.pointStyle()); // This point
351}
PointStyle pointStyle() const
Get method for PointStyle.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.

◆ wanted()

bool GraphicsPoint::wanted ( ) const

Identify point as wanted//unwanted.

Definition at line 353 of file GraphicsPoint.cpp.

354{
355 return m_wanted;
356}

The documentation for this class was generated from the following files: