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);
void setPassive()
Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work proper...
QString dataKeyToString(DataKey dataKey)
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
const QString INDENTATION_DELTA
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
PointStyle pointStyle() const
Get method for PointStyle.
const double DEFAULT_HIGHLIGHT_OPACITY
Base class for adding identifiers to graphics items that represent Points.
Window that displays the geometry information, as a table, for the current curve. ...
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPos(const QPointF pos)
Update the position.
Unique identifier for QGraphicsItem object
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
DataKey
Index values for storing item details in QGraphicsItem using setData/data.
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
GraphicsPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, unsigned int radius, double lineWidth, GeometryWindow *geometryWindow)
Constructor of circular point.
QString QPointFToString(const QPointF &pos)
This class add event handling to QGraphicsEllipseItem.
Details for a specific Point.
QColor ColorPaletteToQColor(ColorPalette color)
QRectF boundingRect() const
Proxy method for QGraphicsItem::boundingRect.
double highlightOpacity() const
Get method for highlight opacity.
~GraphicsPoint()
Destructor. This remove the graphics item from the scene.
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(...
Container for LineStyle and PointStyle for one Curve.
PointShape shape() const
Get method for point shape.
bool wanted() const
Identify point as wanted//unwanted.
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
This class add event handling to QGraphicsPolygonItem.
log4cpp::Category * mainCat
ColorPalette paletteColor() const
Get method for point color.
int lineWidth() const
Get method for line width.
unsigned int radius() const
Radius of point. For a circle this is all that is needed to draw a circle. For a polygon, the radius determines the size of the polygon.
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.
#define LOG4CPP_DEBUG_S(logger)
void setRadius(int radius)
Update the radius.
void reset()
Mark point as unwanted, and unbind any bound lines.