17#include <QGraphicsEllipseItem>
18#include <QGraphicsPolygonItem>
19#include <QGraphicsScene>
20#include <QGraphicsSceneContextMenuEvent>
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)
52 createPointEllipse (radius);
56 const QString &identifier,
57 const QPointF &posScreen,
59 const QPolygonF &polygon,
64 m_graphicsItemEllipse (nullptr),
65 m_shadowZeroWidthEllipse (nullptr),
66 m_graphicsItemPolygon (nullptr),
67 m_shadowZeroWidthPolygon (nullptr),
68 m_identifier (identifier),
69 m_posScreen (posScreen),
71 m_lineWidth (lineWidth),
74 m_geometryWindow (geometryWindow)
76 createPointPolygon (polygon);
81 if (m_graphicsItemEllipse ==
nullptr) {
83 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
86 scene->removeItem (m_graphicsItemPolygon);
87 delete m_graphicsItemPolygon;
88 m_graphicsItemPolygon =
nullptr;
89 m_shadowZeroWidthPolygon =
nullptr;
94 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
97 scene->removeItem (m_graphicsItemEllipse);
98 delete m_graphicsItemEllipse;
99 m_graphicsItemEllipse =
nullptr;
100 m_shadowZeroWidthEllipse =
nullptr;
107 if (m_graphicsItemEllipse ==
nullptr) {
108 return m_graphicsItemPolygon->boundingRect ();
110 return m_graphicsItemEllipse->boundingRect ();
114void GraphicsPoint::createPointEllipse (
unsigned int radius)
118 const int radiusSigned = signed (radius);
120 QRect (- radiusSigned,
122 2 * radiusSigned + 1,
123 2 * radiusSigned + 1));
124 m_scene.addItem (m_graphicsItemEllipse);
129 m_graphicsItemEllipse->setPos (m_posScreen.x (),
131 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
132 m_graphicsItemEllipse->setEnabled (
true);
133 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
134 QGraphicsItem::ItemIsMovable |
135 QGraphicsItem::ItemSendsGeometryChanges);
137 if (m_geometryWindow !=
nullptr) {
138 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
139 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
144 m_shadowZeroWidthEllipse =
new GraphicsPointEllipse (*
this,
145 QRect (- radiusSigned,
147 2 * radiusSigned + 1,
148 2 * radiusSigned + 1));
149 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
151 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color),
ZERO_WIDTH));
152 m_shadowZeroWidthEllipse->setEnabled (
true);
154 m_graphicsItemEllipse->setShadow (m_shadowZeroWidthEllipse);
157void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
161 m_graphicsItemPolygon =
new GraphicsPointPolygon (*
this,
163 m_scene.addItem (m_graphicsItemPolygon);
168 m_graphicsItemPolygon->setPos (m_posScreen.x (),
170 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
171 m_graphicsItemPolygon->setEnabled (
true);
172 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
173 QGraphicsItem::ItemIsMovable |
174 QGraphicsItem::ItemSendsGeometryChanges);
176 if (m_geometryWindow !=
nullptr) {
177 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
178 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
183 m_shadowZeroWidthPolygon =
new GraphicsPointPolygon (*
this,
185 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
187 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color),
ZERO_WIDTH));
188 m_shadowZeroWidthPolygon->setEnabled (
true);
190 m_graphicsItemPolygon->setShadow (m_shadowZeroWidthPolygon);
195 if (m_graphicsItemEllipse ==
nullptr) {
196 return m_graphicsItemPolygon->data (key);
198 return m_graphicsItemEllipse->data (key);
204 return m_highlightOpacity;
209 if (m_graphicsItemEllipse ==
nullptr) {
210 return m_graphicsItemPolygon->pos ();
212 return m_graphicsItemEllipse->pos ();
218 double ordinalKey)
const
220 str << indentation <<
"GraphicsPoint\n";
227 if (m_graphicsItemEllipse ==
nullptr) {
229 pointType =
"polygon";
230 pos = m_graphicsItemPolygon->pos();
233 pointType =
"ellipse";
234 pos = m_graphicsItemEllipse->pos();
239 str << indentation << identifier
240 <<
" ordinalKey=" << ordinalKey
255 <<
" data=" <<
data.toString().toLatin1().data();
257 if (m_graphicsItemEllipse ==
nullptr) {
258 m_graphicsItemPolygon->setData (key,
data);
260 m_graphicsItemEllipse->setData (key,
data);
267 <<
" identifier=" << m_identifier.toLatin1().data()
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);
280 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsFocusable,
false);
281 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsMovable,
false);
282 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsSelectable,
false);
290 if (m_graphicsItemEllipse ==
nullptr) {
294 delete m_graphicsItemPolygon;
295 m_graphicsItemPolygon =
nullptr;
296 m_shadowZeroWidthPolygon =
nullptr;
298 createPointEllipse (
unsigned (pointStyle.
radius()));
307 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
308 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
315 delete m_graphicsItemEllipse;
316 m_graphicsItemEllipse =
nullptr;
317 m_shadowZeroWidthEllipse =
nullptr;
319 createPointPolygon (pointStyle.
polygon());
328 m_graphicsItemEllipse->setRadius (pointStyle.
radius());
329 m_shadowZeroWidthEllipse->setRadius (pointStyle.
radius());
336 if (m_graphicsItemEllipse ==
nullptr) {
337 m_graphicsItemPolygon->setPos (
pos);
339 m_graphicsItemEllipse->setPos (
pos);
QString dataKeyToString(DataKey dataKey)
DataKey
Index values for storing item details in QGraphicsItem using setData/data.
@ DATA_KEY_GRAPHICS_ITEM_TYPE
QColor ColorPaletteToQColor(ColorPalette color)
@ GRAPHICS_ITEM_TYPE_POINT
const double DEFAULT_HIGHLIGHT_OPACITY
const double DEFAULT_HIGHLIGHT_OPACITY
log4cpp::Category * mainCat
const QString INDENTATION_DELTA
QString QPointFToString(const QPointF &pos)
Container for LineStyle and PointStyle for one Curve.
PointStyle pointStyle() const
Get method for PointStyle.
Window that displays the geometry information, as a table, for the current curve.
GraphicsPointAbstractBase()
Single constructor.
This class add event handling to QGraphicsEllipseItem.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
void setPassive()
Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work proper...
void reset()
Mark point as unwanted, and unbind any bound lines.
bool wanted() const
Identify point as wanted//unwanted.
GraphicsPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, unsigned int radius, double lineWidth, GeometryWindow *geometryWindow)
Constructor of circular point.
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(...
~GraphicsPoint()
Destructor. This remove the graphics item from the scene.
QRectF boundingRect() const
Proxy method for QGraphicsItem::boundingRect.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
double highlightOpacity() const
Get method for highlight opacity.
void setPos(const QPointF pos)
Update the position.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
Details for a specific Point.
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.
#define LOG4CPP_DEBUG_S(logger)