1 #include "DocumentSerialize.h"
2 #include "EngaugeAssert.h"
4 #include "PointStyle.h"
8 #include <QtToString.h>
9 #include <QXmlStreamWriter>
11 #include "SettingsForGraph.h"
14 const ColorPalette DEFAULT_POINT_COLOR_AXES = COLOR_PALETTE_RED;
15 const ColorPalette DEFAULT_POINT_COLOR_GRAPH = COLOR_PALETTE_BLUE;
16 const int DEFAULT_POINT_LINE_WIDTH = 1;
17 const int DEFAULT_POINT_RADIUS = 10;
18 const PointShape DEFAULT_POINT_SHAPE_AXIS = POINT_SHAPE_CROSS;
19 const double PI = 3.1415926535;
20 const double TWO_PI = 2.0 * PI;
29 ColorPalette paletteColor) :
32 m_lineWidth (lineWidth),
33 m_paletteColor (paletteColor)
38 m_shape (other.shape()),
39 m_radius (other.radius ()),
40 m_lineWidth (other.lineWidth ()),
41 m_paletteColor (other.paletteColor ())
47 m_shape = other.
shape ();
48 m_radius = other.
radius ();
58 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
59 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
60 PointShape
shape = (PointShape) settings.value (SETTINGS_CURVE_POINT_SHAPE,
61 DEFAULT_POINT_SHAPE_AXIS).toInt();
62 int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
63 DEFAULT_POINT_RADIUS).toInt();
64 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
65 DEFAULT_POINT_LINE_WIDTH).toInt();
66 ColorPalette pointColor = (ColorPalette) settings.value (SETTINGS_CURVE_POINT_COLOR,
67 DEFAULT_POINT_COLOR_AXES).toInt();
79 PointShape
shape = POINT_SHAPE_CROSS;
80 static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
84 shape = pointShapes [index % 4];
87 int indexOneBased = index + 1;
91 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
92 settings.beginGroup (groupName);
93 int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
94 DEFAULT_POINT_RADIUS).toInt();
95 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
96 DEFAULT_POINT_LINE_WIDTH).toInt();
97 ColorPalette pointColor = (ColorPalette) settings.value (SETTINGS_CURVE_POINT_COLOR,
98 DEFAULT_POINT_COLOR_GRAPH).toInt();
109 return m_shape == POINT_SHAPE_CIRCLE;
119 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::loadXml";
121 QXmlStreamAttributes attributes = reader.attributes();
123 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
124 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
125 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
126 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {
128 setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toInt());
129 setLineWidth (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH).toInt());
130 setPaletteColor ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt());
131 setShape ((PointShape) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt());
134 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
135 (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
136 loadNextFromReader(reader);
139 reader.raiseError (
"Cannot read point style data");
145 return m_paletteColor;
150 const int NUM_XY = 60;
151 QVector<QPointF> points;
155 case POINT_SHAPE_CIRCLE:
157 int xyWidth = m_radius;
158 for (
int i = 0; i <= NUM_XY; i++) {
159 double angle = TWO_PI * (double) i / (
double) NUM_XY;
160 double x = xyWidth * cos (angle);
161 double y = xyWidth * sin (angle);
162 points.append (QPointF (x, y));
167 case POINT_SHAPE_CROSS:
169 int xyWidth = m_radius;
171 points.append (QPointF (-1 * xyWidth, 0));
172 points.append (QPointF (xyWidth, 0));
173 points.append (QPointF (0, 0));
174 points.append (QPointF (0, xyWidth));
175 points.append (QPointF (0, -1 * xyWidth));
176 points.append (QPointF (0, 0));
180 case POINT_SHAPE_DIAMOND:
182 int xyWidth = m_radius;
184 points.append (QPointF (0, -1 * xyWidth));
185 points.append (QPointF (-1 * xyWidth, 0));
186 points.append (QPointF (0, xyWidth));
187 points.append (QPointF (xyWidth, 0));
191 case POINT_SHAPE_SQUARE:
193 int xyWidth = m_radius;
195 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
196 points.append (QPointF (-1 * xyWidth, xyWidth));
197 points.append (QPointF (xyWidth, xyWidth));
198 points.append (QPointF (xyWidth, -1 * xyWidth));
202 case POINT_SHAPE_TRIANGLE:
204 int xyWidth = m_radius;
206 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
207 points.append (QPointF (0, xyWidth));
208 points.append (QPointF (xyWidth, -1 * xyWidth));
214 int xyWidth = m_radius * qSqrt (0.5);
216 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
217 points.append (QPointF (xyWidth, xyWidth));
218 points.append (QPointF (0, 0));
219 points.append (QPointF (-1 * xyWidth, xyWidth));
220 points.append (QPointF (xyWidth, -1 * xyWidth));
221 points.append (QPointF (0, 0));
226 ENGAUGE_ASSERT (
false);
234 QTextStream &str)
const
236 str << indentation <<
"PointStyle\n";
238 indentation += INDENTATION_DELTA;
240 str << indentation << pointShapeToString (m_shape) <<
"\n";
241 str << indentation <<
"radius=" << m_radius <<
"\n";
242 str << indentation <<
"lineWidth=" << m_lineWidth <<
"\n";
243 str << indentation <<
"color=" << colorPaletteToString (m_paletteColor) <<
"\n";
253 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::saveXml";
255 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
256 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
257 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
258 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
259 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
260 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
261 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
262 writer.writeEndElement();
Manage storage and retrieval of the settings for the curves.
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...
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index...
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.