Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::GraphicsPoint"
53 << " identifier=" << identifier.toLatin1 ().data ();
54
55 createPointEllipse (radius);
56}
const int INNER_RADIUS_MIN
const double DEFAULT_HIGHLIGHT_OPACITY
log4cpp::Category * mainCat
Definition Logger.cpp:14
GraphicsPointAbstractBase()
Single constructor.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ 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 58 of file GraphicsPoint.cpp.

64 :
66 m_scene (scene),
67 m_graphicsItemEllipse (nullptr),
68 m_shadowZeroWidthEllipse (nullptr),
69 m_graphicsItemPolygon (nullptr),
70 m_shadowZeroWidthPolygon (nullptr),
71 m_identifier (identifier),
72 m_posScreen (posScreen),
73 m_color (color),
74 m_lineWidth (lineWidth),
75 m_wanted (true),
76 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
77 m_geometryWindow (geometryWindow)
78{
79 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::GraphicsPoint "
80 << " identifier=" << identifier.toLatin1 ().data ();
81
82 createPointPolygon (polygon);
83}

◆ ~GraphicsPoint()

GraphicsPoint::~GraphicsPoint ( )

Destructor. This remove the graphics item from the scene.

Definition at line 85 of file GraphicsPoint.cpp.

86{
87 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::~GraphicsPoint";
88
89 if (m_graphicsItemEllipse == nullptr) {
90
91 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
92
93 // Since m_shadowZeroWidthPolygon is a child of m_graphicsItemPolygon, removing the parent removes both
94 scene->removeItem (m_graphicsItemPolygon);
95 delete m_graphicsItemPolygon;
96 m_graphicsItemPolygon = nullptr;
97 m_shadowZeroWidthPolygon = nullptr;
98
99
100 } else {
101
102 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
103
104 // Since m_shadowZeroWidthEllipse is a child of m_graphicsItemEllipse, removing the parent removes both
105 scene->removeItem (m_graphicsItemEllipse);
106 delete m_graphicsItemEllipse;
107 m_graphicsItemEllipse = nullptr;
108 m_shadowZeroWidthEllipse = nullptr;
109
110 }
111}

Member Function Documentation

◆ boundingRect()

QRectF GraphicsPoint::boundingRect ( ) const

Proxy method for QGraphicsItem::boundingRect.

Definition at line 113 of file GraphicsPoint.cpp.

114{
115 if (m_graphicsItemEllipse == nullptr) {
116 return m_graphicsItemPolygon->boundingRect ();
117 } else {
118 return m_graphicsItemEllipse->boundingRect ();
119 }
120}

◆ data()

QVariant GraphicsPoint::data ( int key) const

Proxy method for QGraphicsItem::data.

Definition at line 201 of file GraphicsPoint.cpp.

202{
203 if (m_graphicsItemEllipse == nullptr) {
204 return m_graphicsItemPolygon->data (key);
205 } else {
206 return m_graphicsItemEllipse->data (key);
207 }
208}

◆ highlightOpacity()

double GraphicsPoint::highlightOpacity ( ) const

Get method for highlight opacity.

Definition at line 210 of file GraphicsPoint.cpp.

211{
212 return m_highlightOpacity;
213}

◆ pos()

QPointF GraphicsPoint::pos ( ) const

Proxy method for QGraphicsItem::pos.

Definition at line 215 of file GraphicsPoint.cpp.

216{
217 if (m_graphicsItemEllipse == nullptr) {
218 return m_graphicsItemPolygon->pos ();
219 } else {
220 return m_graphicsItemEllipse->pos ();
221 }
222}

◆ 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 224 of file GraphicsPoint.cpp.

227{
228 str << indentation << "GraphicsPoint\n";
229
231
232 QString identifier;
234 QPointF pos;
235 if (m_graphicsItemEllipse == nullptr) {
236 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
237 pointType = "polygon";
238 pos = m_graphicsItemPolygon->pos();
239 } else {
240 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
241 pointType = "ellipse";
242 pos = m_graphicsItemEllipse->pos();
243 }
244
245 DataKey type = static_cast<DataKey> (data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt());
246
247 str << indentation << identifier
248 << " ordinalKey=" << ordinalKey
249 << " dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
250 << " dataType=" << dataKeyToString (type).toLatin1().data()
251 << " " << pointType << "Pos=" << QPointFToString (pos) << "\n";
252}
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
‍Unique identifier for QGraphicsItem object
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 254 of file GraphicsPoint.cpp.

255{
256 m_wanted = false;
257}

◆ setData()

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

Proxy method for QGraphicsItem::setData.

Definition at line 259 of file GraphicsPoint.cpp.

260{
261 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setData"
262 << " key=" << dataKeyToString (static_cast<DataKey> (key)).toLatin1().data()
263 << " data=" << data.toString().toLatin1().data();
264
265 if (m_graphicsItemEllipse == nullptr) {
266 m_graphicsItemPolygon->setData (key, data);
267 } else {
268 m_graphicsItemEllipse->setData (key, data);
269 }
270}

◆ setHighlightOpacity()

void GraphicsPoint::setHighlightOpacity ( double highlightOpacity)

Set method for highlight opacity.

Definition at line 272 of file GraphicsPoint.cpp.

273{
274 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setHighlightOpacity"
275 << " identifier=" << m_identifier.toLatin1().data()
276 << " highlightOpacity=" << highlightOpacity;
277
278 m_highlightOpacity = highlightOpacity;
279}
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 281 of file GraphicsPoint.cpp.

282{
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);
287 } else {
288 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsFocusable, false);
289 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsMovable, false);
290 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsSelectable, false);
291 }
292}

◆ setPointStyle()

void GraphicsPoint::setPointStyle ( const PointStyle & pointStyle)

Update the point style.

Definition at line 294 of file GraphicsPoint.cpp.

295{
296 // Setting pen and radius of parent graphics items below also affects the child shadows
297 // (m_shadowItemPolygon and m_shadowItemEllipse)
298 if (m_graphicsItemEllipse == nullptr) {
299 if (pointStyle.shape() == POINT_SHAPE_CIRCLE) {
300
301 // Transition from non-circle to circle. Deleting parent also deletes child shadow
302 delete m_graphicsItemPolygon;
303 m_graphicsItemPolygon = nullptr;
304 m_shadowZeroWidthPolygon = nullptr;
305
306 createPointEllipse (unsigned (pointStyle.radius()));
307
308 } else {
309
310 // Update polygon
311 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
312 pointStyle.lineWidth()));
313 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
314 pointStyle.lineWidth()));
315 m_graphicsItemPolygon->setPolygon (pointStyle.polygon());
316 m_shadowZeroWidthPolygon->setPolygon (pointStyle.polygon());
317
318 }
319 } else {
320 if (pointStyle.shape() != POINT_SHAPE_CIRCLE) {
321
322 // Transition from circle to non-circlee. Deleting parent also deletes child shadow
323 delete m_graphicsItemEllipse;
324 m_graphicsItemEllipse = nullptr;
325 m_shadowZeroWidthEllipse = nullptr;
326
327 createPointPolygon (pointStyle.polygon());
328
329 } else {
330
331 // Update circle
332 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
333 pointStyle.lineWidth()));
334 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
335 pointStyle.lineWidth()));
336 m_graphicsItemEllipse->setRadius (pointStyle.radius());
337 m_shadowZeroWidthEllipse->setRadius (pointStyle.radius());
338 }
339 }
340}
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:15
@ POINT_SHAPE_CIRCLE
Definition PointShape.h:13
void setRadius(int radius)
Update the radius.
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 342 of file GraphicsPoint.cpp.

343{
344 if (m_graphicsItemEllipse == nullptr) {
345 m_graphicsItemPolygon->setPos (pos);
346 } else {
347 m_graphicsItemEllipse->setPos (pos);
348 }
349}

◆ setWanted()

void GraphicsPoint::setWanted ( )

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

Definition at line 351 of file GraphicsPoint.cpp.

352{
353 m_wanted = true;
354}

◆ updateCurveStyle()

void GraphicsPoint::updateCurveStyle ( const CurveStyle & curveStyle)

Update point and line styles that comprise the curve style.

Definition at line 356 of file GraphicsPoint.cpp.

357{
358 setPointStyle (curveStyle.pointStyle()); // This point
359}
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 361 of file GraphicsPoint.cpp.

362{
363 return m_wanted;
364}

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