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";
106 m_scene.addItem (m_graphicsItemEllipse);
108 m_graphicsItemEllipse->setZValue (Z_VALUE);
109 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
110 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
111 m_graphicsItemEllipse->setPos (m_posScreen.x (),
113 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
114 m_graphicsItemEllipse->setEnabled (
true);
115 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
116 QGraphicsItem::ItemIsMovable |
117 QGraphicsItem::ItemSendsGeometryChanges);
119 m_graphicsItemEllipse->setToolTip (m_identifier);
120 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
129 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
131 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
132 m_shadowZeroWidthEllipse->setEnabled (
true);
135 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
137 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::createPointPolygon";
141 m_scene.addItem (m_graphicsItemPolygon);
143 m_graphicsItemPolygon->setZValue (Z_VALUE);
144 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
145 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
146 m_graphicsItemPolygon->setPos (m_posScreen.x (),
148 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
149 m_graphicsItemPolygon->setEnabled (
true);
150 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
151 QGraphicsItem::ItemIsMovable |
152 QGraphicsItem::ItemSendsGeometryChanges);
154 m_graphicsItemPolygon->setToolTip (m_identifier);
155 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
161 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
163 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
164 m_shadowZeroWidthPolygon->setEnabled (
true);
169 if (m_graphicsItemEllipse == 0) {
170 return m_graphicsItemPolygon->data (key);
172 return m_graphicsItemEllipse->data (key);
178 if (m_graphicsItemEllipse == 0) {
179 return m_graphicsItemPolygon->pos ();
181 return m_graphicsItemEllipse->pos ();
187 double ordinalKey)
const
189 str << indentation <<
"GraphicsPoint\n";
191 indentation += INDENTATION_DELTA;
196 if (m_graphicsItemEllipse == 0) {
197 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
198 pointType =
"polygon";
199 pos = m_graphicsItemPolygon->pos();
201 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
202 pointType =
"ellipse";
203 pos = m_graphicsItemEllipse->pos();
206 DataKey type = (DataKey)
data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
208 str << indentation << identifier
209 <<
" ordinalKey=" << ordinalKey
210 <<
" dataIdentifier=" <<
data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
211 <<
" dataType=" << dataKeyToString (type).toLatin1().data()
212 <<
" " << pointType <<
"Pos=" << QPointFToString (pos) <<
"\n";
222 LOG4CPP_INFO_S ((*mainCat)) <<
"GraphicsPoint::setData"
223 <<
" key=" << dataKeyToString ((DataKey) key).toLatin1().data()
224 <<
" data=" << data.toString().toLatin1().data();
226 if (m_graphicsItemEllipse == 0) {
227 m_graphicsItemPolygon->setData (key, data);
229 m_graphicsItemEllipse->setData (key, data);
237 if (m_graphicsItemEllipse == 0) {
238 if (pointStyle.
shape() == POINT_SHAPE_CIRCLE) {
241 delete m_graphicsItemPolygon;
242 m_graphicsItemPolygon = 0;
243 m_shadowZeroWidthPolygon = 0;
245 createPointEllipse (pointStyle.
radius());
250 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
252 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
254 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
255 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
259 if (pointStyle.
shape() != POINT_SHAPE_CIRCLE) {
262 delete m_graphicsItemEllipse;
263 m_graphicsItemEllipse = 0;
264 m_shadowZeroWidthEllipse = 0;
266 createPointPolygon (pointStyle.
polygon());
271 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
273 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
283 if (m_graphicsItemEllipse == 0) {
284 return m_graphicsItemPolygon->setPos (pos);
286 return m_graphicsItemEllipse->setPos (pos);
292 if (m_graphicsItemEllipse == 0) {
293 m_graphicsItemPolygon->setToolTip (toolTip);
295 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.