1 #include "DocumentSerialize.h"
2 #include "EngaugeAssert.h"
4 #include "PointStyle.h"
7 #include <QtToString.h>
8 #include <QXmlStreamWriter>
11 const int DEFAULT_POINT_RADIUS = 10;
12 const int DEFAULT_LINE_WIDTH = 1;
13 const double PI = 3.1415926535;
14 const double TWO_PI = 2.0 * PI;
23 ColorPalette paletteColor) :
26 m_lineWidth (lineWidth),
27 m_paletteColor (paletteColor)
32 m_shape (other.shape()),
33 m_radius (other.radius ()),
34 m_lineWidth (other.lineWidth ()),
35 m_paletteColor (other.paletteColor ())
41 m_shape = other.
shape ();
42 m_radius = other.
radius ();
59 PointShape
shape = POINT_SHAPE_CROSS;
60 static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
64 shape = pointShapes [index % 4];
74 return m_shape == POINT_SHAPE_CIRCLE;
84 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::loadXml";
86 QXmlStreamAttributes attributes = reader.attributes();
88 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
89 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
90 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
91 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {
93 setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toInt());
94 setLineWidth (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH).toInt());
95 setPaletteColor ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt());
96 setShape ((PointShape) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt());
99 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
100 (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
101 loadNextFromReader(reader);
104 reader.raiseError (
"Cannot read point style data");
110 return m_paletteColor;
115 const int NUM_XY = 60;
116 QVector<QPointF> points;
120 case POINT_SHAPE_CIRCLE:
122 int xyWidth = m_radius;
123 for (
int i = 0; i <= NUM_XY; i++) {
124 double angle = TWO_PI * (double) i / (
double) NUM_XY;
125 double x = xyWidth * cos (angle);
126 double y = xyWidth * sin (angle);
127 points.append (QPointF (x, y));
132 case POINT_SHAPE_CROSS:
134 int xyWidth = m_radius;
136 points.append (QPointF (-1 * xyWidth, 0));
137 points.append (QPointF (xyWidth, 0));
138 points.append (QPointF (0, 0));
139 points.append (QPointF (0, xyWidth));
140 points.append (QPointF (0, -1 * xyWidth));
141 points.append (QPointF (0, 0));
145 case POINT_SHAPE_DIAMOND:
147 int xyWidth = m_radius;
149 points.append (QPointF (0, -1 * xyWidth));
150 points.append (QPointF (-1 * xyWidth, 0));
151 points.append (QPointF (0, xyWidth));
152 points.append (QPointF (xyWidth, 0));
156 case POINT_SHAPE_SQUARE:
158 int xyWidth = m_radius;
160 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
161 points.append (QPointF (-1 * xyWidth, xyWidth));
162 points.append (QPointF (xyWidth, xyWidth));
163 points.append (QPointF (xyWidth, -1 * xyWidth));
167 case POINT_SHAPE_TRIANGLE:
169 int xyWidth = m_radius;
171 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
172 points.append (QPointF (0, xyWidth));
173 points.append (QPointF (xyWidth, -1 * xyWidth));
179 int xyWidth = m_radius * qSqrt (0.5);
181 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
182 points.append (QPointF (xyWidth, xyWidth));
183 points.append (QPointF (0, 0));
184 points.append (QPointF (-1 * xyWidth, xyWidth));
185 points.append (QPointF (xyWidth, -1 * xyWidth));
186 points.append (QPointF (0, 0));
191 ENGAUGE_ASSERT (
false);
199 QTextStream &str)
const
201 str << indentation <<
"PointStyle\n";
203 indentation += INDENTATION_DELTA;
205 str << indentation << pointShapeToString (m_shape) <<
"\n";
206 str << indentation <<
"radius=" << m_radius <<
"\n";
207 str << indentation <<
"lineWidth=" << m_lineWidth <<
"\n";
208 str << indentation <<
"color=" << colorPaletteToString (m_paletteColor) <<
"\n";
218 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::saveXml";
220 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
221 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
222 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
223 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
224 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
225 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
226 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
227 writer.writeEndElement();
static PointStyle defaultAxesCurve()
Initial default for axes curve.
PointStyle()
Default constructor only for use when this class is being stored by a container that requires the def...
int lineWidth() const
Get method for line width.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void loadXml(QXmlStreamReader &reader)
Load model from serialized xml. Returns the curve name.
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
void setShape(PointShape shape)
Set method for point shape.
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
Details for a specific Point.
ColorPalette paletteColor() const
Get method for point color.
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 setPaletteColor(ColorPalette paletteColor)
Set method for point color.
bool isCircle() const
Return true if point is a circle, otherwise it is a polygon. For a circle, the radius is important an...
PointStyle & operator=(const PointStyle &other)
Assignment constructor.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
void setLineWidth(int width)
Set method for line width.
PointShape shape() const
Get method for point shape.
void setRadius(int radius)
Set method for point radius.