1 #include "CurveStyle.h"
4 #include "GraphicsItemType.h"
5 #include "GraphicsPoint.h"
6 #include "GraphicsPointEllipse.h"
7 #include "GraphicsPointPolygon.h"
9 #include "PointStyle.h"
10 #include <QGraphicsEllipseItem>
11 #include <QGraphicsPolygonItem>
12 #include <QGraphicsScene>
13 #include <QGraphicsSceneContextMenuEvent>
15 #include <QTextStream>
16 #include "QtToString.h"
18 const double ZERO_WIDTH = 0.0;
19 const double Z_VALUE = 100.0;
22 const QString &identifier,
23 const QPointF &posScreen,
29 m_graphicsItemEllipse (0),
30 m_shadowZeroWidthEllipse (0),
31 m_graphicsItemPolygon (0),
32 m_shadowZeroWidthPolygon (0),
33 m_identifier (identifier),
34 m_posScreen (posScreen),
36 m_lineWidth (lineWidth),
39 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint"
40 <<
" identifier=" << identifier.toLatin1 ().data ();
42 createPointEllipse (radius);
46 const QString &identifier,
47 const QPointF &posScreen,
49 const QPolygonF &polygon,
53 m_graphicsItemEllipse (0),
54 m_shadowZeroWidthEllipse (0),
55 m_graphicsItemPolygon (0),
56 m_shadowZeroWidthPolygon (0),
57 m_identifier (identifier),
58 m_posScreen (posScreen),
60 m_lineWidth (lineWidth),
63 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint "
64 <<
" identifier=" << identifier.toLatin1 ().data ();
66 createPointPolygon (polygon);
71 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::~GraphicsPoint";
73 if (m_graphicsItemEllipse == 0) {
75 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
78 scene->removeItem (m_graphicsItemPolygon);
79 delete m_graphicsItemPolygon;
80 m_graphicsItemPolygon = 0;
81 m_shadowZeroWidthPolygon = 0;
86 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
89 scene->removeItem (m_graphicsItemEllipse);
90 delete m_graphicsItemEllipse;
91 m_graphicsItemEllipse = 0;
92 m_shadowZeroWidthEllipse = 0;
97 void GraphicsPoint::createPointEllipse (
unsigned int radius)
99 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::createPointEllipse";
101 const int radiusSigned = radius;
103 QRect (- radiusSigned,
105 2 * radiusSigned + 1,
106 2 * radiusSigned + 1));
107 m_scene.addItem (m_graphicsItemEllipse);
109 m_graphicsItemEllipse->setZValue (Z_VALUE);
110 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
111 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
112 m_graphicsItemEllipse->setPos (m_posScreen.x (),
114 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
115 m_graphicsItemEllipse->setEnabled (
true);
116 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
117 QGraphicsItem::ItemIsMovable |
118 QGraphicsItem::ItemSendsGeometryChanges);
120 m_graphicsItemEllipse->setToolTip (m_identifier);
121 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
126 QRect (- radiusSigned,
128 2 * radiusSigned + 1,
129 2 * radiusSigned + 1));
130 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
132 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
133 m_shadowZeroWidthEllipse->setEnabled (
true);
136 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
138 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::createPointPolygon";
142 m_scene.addItem (m_graphicsItemPolygon);
144 m_graphicsItemPolygon->setZValue (Z_VALUE);
145 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
146 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
147 m_graphicsItemPolygon->setPos (m_posScreen.x (),
149 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
150 m_graphicsItemPolygon->setEnabled (
true);
151 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
152 QGraphicsItem::ItemIsMovable |
153 QGraphicsItem::ItemSendsGeometryChanges);
155 m_graphicsItemPolygon->setToolTip (m_identifier);
156 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
162 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
164 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
165 m_shadowZeroWidthPolygon->setEnabled (
true);
170 if (m_graphicsItemEllipse == 0) {
171 return m_graphicsItemPolygon->data (key);
173 return m_graphicsItemEllipse->data (key);
179 if (m_graphicsItemEllipse == 0) {
180 return m_graphicsItemPolygon->pos ();
182 return m_graphicsItemEllipse->pos ();
188 double ordinalKey)
const
190 str << indentation <<
"GraphicsPoint\n";
192 indentation += INDENTATION_DELTA;
197 if (m_graphicsItemEllipse == 0) {
198 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
199 pointType =
"polygon";
200 pos = m_graphicsItemPolygon->pos();
202 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
203 pointType =
"ellipse";
204 pos = m_graphicsItemEllipse->pos();
207 DataKey type = (DataKey)
data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
209 str << indentation << identifier
210 <<
" ordinalKey=" << ordinalKey
211 <<
" dataIdentifier=" <<
data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
212 <<
" dataType=" << dataKeyToString (type).toLatin1().data()
213 <<
" " << pointType <<
"Pos=" << QPointFToString (pos) <<
"\n";
223 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::setData"
224 <<
" key=" << dataKeyToString ((DataKey) key).toLatin1().data()
225 <<
" data=" << data.toString().toLatin1().data();
227 if (m_graphicsItemEllipse == 0) {
228 m_graphicsItemPolygon->setData (key, data);
230 m_graphicsItemEllipse->setData (key, data);
238 if (m_graphicsItemEllipse == 0) {
239 if (pointStyle.
shape() == POINT_SHAPE_CIRCLE) {
242 delete m_graphicsItemPolygon;
243 m_graphicsItemPolygon = 0;
244 m_shadowZeroWidthPolygon = 0;
246 createPointEllipse (pointStyle.
radius());
251 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
253 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
255 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
256 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
260 if (pointStyle.
shape() != POINT_SHAPE_CIRCLE) {
263 delete m_graphicsItemEllipse;
264 m_graphicsItemEllipse = 0;
265 m_shadowZeroWidthEllipse = 0;
267 createPointPolygon (pointStyle.
polygon());
272 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
274 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
284 if (m_graphicsItemEllipse == 0) {
285 return m_graphicsItemPolygon->setPos (pos);
287 return m_graphicsItemEllipse->setPos (pos);
293 if (m_graphicsItemEllipse == 0) {
294 m_graphicsItemPolygon->setToolTip (toolTip);
296 m_graphicsItemEllipse->setToolTip (toolTip);
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
int lineWidth() const
Get method for line width.
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(...
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
Base class for adding identifiers to graphics items that represent Points.
PointStyle pointStyle() const
Get method for PointStyle.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPos(const QPointF pos)
Update the position.
bool wanted() const
Identify point as wanted//unwanted.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
This class add event handling to QGraphicsEllipseItem.
Details for a specific Point.
~GraphicsPoint()
Destructor. This remove the graphics item from the scene.
ColorPalette paletteColor() const
Get method for point color.
Container for LineStyle and PointStyle for one Curve.
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.
This class add event handling to QGraphicsPolygonItem.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
GraphicsPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, unsigned int radius, double lineWidth)
Constructor of circular point.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
void setToolTip(const QString &toolTip)
Proxy method for QGraphicsItem::setToolTip.
PointShape shape() const
Get method for point shape.
void setRadius(int radius)
Update the radius.
void reset()
Mark point as unwanted, and unbind any bound lines.