7 #include "CurveStyle.h" 10 #include "GraphicsItemType.h" 11 #include "GraphicsPoint.h" 12 #include "GraphicsPointEllipse.h" 13 #include "GraphicsPointPolygon.h" 15 #include "PointStyle.h" 16 #include <QGraphicsEllipseItem> 17 #include <QGraphicsPolygonItem> 18 #include <QGraphicsScene> 19 #include <QGraphicsSceneContextMenuEvent> 21 #include <QTextStream> 22 #include "QtToString.h" 24 const double ZERO_WIDTH = 0.0;
25 const double Z_VALUE = 100.0;
28 const QString &identifier,
29 const QPointF &posScreen,
35 m_graphicsItemEllipse (0),
36 m_shadowZeroWidthEllipse (0),
37 m_graphicsItemPolygon (0),
38 m_shadowZeroWidthPolygon (0),
39 m_identifier (identifier),
40 m_posScreen (posScreen),
42 m_lineWidth (lineWidth),
45 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint" 46 <<
" identifier=" << identifier.toLatin1 ().data ();
48 createPointEllipse (radius);
52 const QString &identifier,
53 const QPointF &posScreen,
55 const QPolygonF &polygon,
59 m_graphicsItemEllipse (0),
60 m_shadowZeroWidthEllipse (0),
61 m_graphicsItemPolygon (0),
62 m_shadowZeroWidthPolygon (0),
63 m_identifier (identifier),
64 m_posScreen (posScreen),
66 m_lineWidth (lineWidth),
69 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint " 70 <<
" identifier=" << identifier.toLatin1 ().data ();
72 createPointPolygon (polygon);
77 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::~GraphicsPoint";
79 if (m_graphicsItemEllipse == 0) {
81 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
84 scene->removeItem (m_graphicsItemPolygon);
85 delete m_graphicsItemPolygon;
86 m_graphicsItemPolygon = 0;
87 m_shadowZeroWidthPolygon = 0;
92 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
95 scene->removeItem (m_graphicsItemEllipse);
96 delete m_graphicsItemEllipse;
97 m_graphicsItemEllipse = 0;
98 m_shadowZeroWidthEllipse = 0;
103 void GraphicsPoint::createPointEllipse (
unsigned int radius)
105 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::createPointEllipse";
107 const int radiusSigned = radius;
109 QRect (- radiusSigned,
111 2 * radiusSigned + 1,
112 2 * radiusSigned + 1));
113 m_scene.addItem (m_graphicsItemEllipse);
115 m_graphicsItemEllipse->setZValue (Z_VALUE);
116 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
117 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
118 m_graphicsItemEllipse->setPos (m_posScreen.x (),
120 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
121 m_graphicsItemEllipse->setEnabled (
true);
122 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
123 QGraphicsItem::ItemIsMovable |
124 QGraphicsItem::ItemSendsGeometryChanges);
126 m_graphicsItemEllipse->setToolTip (m_identifier);
127 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
132 QRect (- radiusSigned,
134 2 * radiusSigned + 1,
135 2 * radiusSigned + 1));
136 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
138 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
139 m_shadowZeroWidthEllipse->setEnabled (
true);
142 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
144 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::createPointPolygon";
148 m_scene.addItem (m_graphicsItemPolygon);
150 m_graphicsItemPolygon->setZValue (Z_VALUE);
151 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
152 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
153 m_graphicsItemPolygon->setPos (m_posScreen.x (),
155 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
156 m_graphicsItemPolygon->setEnabled (
true);
157 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
158 QGraphicsItem::ItemIsMovable |
159 QGraphicsItem::ItemSendsGeometryChanges);
161 m_graphicsItemPolygon->setToolTip (m_identifier);
162 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
168 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
170 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
171 m_shadowZeroWidthPolygon->setEnabled (
true);
176 if (m_graphicsItemEllipse == 0) {
177 return m_graphicsItemPolygon->data (key);
179 return m_graphicsItemEllipse->data (key);
185 if (m_graphicsItemEllipse == 0) {
186 return m_graphicsItemPolygon->pos ();
188 return m_graphicsItemEllipse->pos ();
194 double ordinalKey)
const 196 str << indentation <<
"GraphicsPoint\n";
198 indentation += INDENTATION_DELTA;
203 if (m_graphicsItemEllipse == 0) {
204 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
205 pointType =
"polygon";
206 pos = m_graphicsItemPolygon->pos();
208 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
209 pointType =
"ellipse";
210 pos = m_graphicsItemEllipse->pos();
213 DataKey type = (DataKey)
data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
215 str << indentation << identifier
216 <<
" ordinalKey=" << ordinalKey
217 <<
" dataIdentifier=" <<
data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
218 <<
" dataType=" << dataKeyToString (type).toLatin1().data()
219 <<
" " << pointType <<
"Pos=" << QPointFToString (pos) <<
"\n";
229 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::setData" 230 <<
" key=" << dataKeyToString ((DataKey) key).toLatin1().data()
231 <<
" data=" << data.toString().toLatin1().data();
233 if (m_graphicsItemEllipse == 0) {
234 m_graphicsItemPolygon->setData (key, data);
236 m_graphicsItemEllipse->setData (key, data);
244 if (m_graphicsItemEllipse == 0) {
245 if (pointStyle.
shape() == POINT_SHAPE_CIRCLE) {
248 delete m_graphicsItemPolygon;
249 m_graphicsItemPolygon = 0;
250 m_shadowZeroWidthPolygon = 0;
252 createPointEllipse (pointStyle.
radius());
257 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
259 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
261 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
262 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
266 if (pointStyle.
shape() != POINT_SHAPE_CIRCLE) {
269 delete m_graphicsItemEllipse;
270 m_graphicsItemEllipse = 0;
271 m_shadowZeroWidthEllipse = 0;
273 createPointPolygon (pointStyle.
polygon());
278 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
280 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
290 if (m_graphicsItemEllipse == 0) {
291 return m_graphicsItemPolygon->setPos (pos);
293 return m_graphicsItemEllipse->setPos (pos);
299 if (m_graphicsItemEllipse == 0) {
300 m_graphicsItemPolygon->setToolTip (toolTip);
302 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.