7 #include "DocumentSerialize.h"
8 #include "EngaugeAssert.h"
10 #include "PointStyle.h"
14 #include <QTextStream>
15 #include <QtToString.h>
16 #include <QXmlStreamWriter>
18 #include "SettingsForGraph.h"
21 const ColorPalette DEFAULT_POINT_COLOR_AXES = COLOR_PALETTE_RED;
22 const ColorPalette DEFAULT_POINT_COLOR_GRAPH = COLOR_PALETTE_BLUE;
23 const int DEFAULT_POINT_LINE_WIDTH = 1;
24 const int DEFAULT_POINT_RADIUS = 10;
25 const PointShape DEFAULT_POINT_SHAPE_AXIS = POINT_SHAPE_CROSS;
26 const double PI = 3.1415926535;
27 const double TWO_PI = 2.0 * PI;
31 m_shape (DEFAULT_POINT_SHAPE_AXIS),
32 m_radius (DEFAULT_POINT_RADIUS),
33 m_lineWidth (DEFAULT_POINT_LINE_WIDTH),
34 m_paletteColor (DEFAULT_POINT_COLOR_GRAPH)
41 ColorPalette paletteColor) :
44 m_lineWidth (lineWidth),
45 m_paletteColor (paletteColor)
50 m_shape (other.shape()),
51 m_radius (other.radius ()),
52 m_lineWidth (other.lineWidth ()),
53 m_paletteColor (other.paletteColor ())
59 m_shape = other.
shape ();
60 m_radius = other.
radius ();
70 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
71 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
72 PointShape
shape =
static_cast<PointShape
> (settings.value (SETTINGS_CURVE_POINT_SHAPE,
73 DEFAULT_POINT_SHAPE_AXIS).toInt());
74 unsigned int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
75 DEFAULT_POINT_RADIUS).toUInt();
76 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
77 DEFAULT_POINT_LINE_WIDTH).toInt();
78 ColorPalette pointColor =
static_cast<ColorPalette
> (settings.value (SETTINGS_CURVE_POINT_COLOR,
79 DEFAULT_POINT_COLOR_AXES).toInt());
91 PointShape
shape = POINT_SHAPE_CROSS;
92 static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
96 shape = pointShapes [index % 4];
99 int indexOneBased = index + 1;
103 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
104 settings.beginGroup (groupName);
105 unsigned int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
106 DEFAULT_POINT_RADIUS).toUInt();
107 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
108 DEFAULT_POINT_LINE_WIDTH).toInt();
109 ColorPalette pointColor =
static_cast<ColorPalette
> (settings.value (SETTINGS_CURVE_POINT_COLOR,
110 DEFAULT_POINT_COLOR_GRAPH).toInt());
111 settings.endGroup ();
121 return m_shape == POINT_SHAPE_CIRCLE;
131 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::loadXml";
133 QXmlStreamAttributes attributes = reader.attributes();
135 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
137 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
138 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {
140 setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toUInt());
141 setLineWidth (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH).toInt());
142 setPaletteColor (static_cast<ColorPalette> (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt()));
143 setShape (static_cast<PointShape> (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt()));
146 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
147 (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
148 loadNextFromReader(reader);
151 reader.raiseError (QObject::tr (
"Cannot read point style data"));
157 return m_paletteColor;
162 const int NUM_XY = 60;
163 QVector<QPointF> points;
167 case POINT_SHAPE_CIRCLE:
169 int xyWidth = signed (m_radius);
170 for (
int i = 0; i <= NUM_XY; i++) {
171 double angle = TWO_PI * double (i) / double (NUM_XY);
172 double x = xyWidth * cos (angle);
173 double y = xyWidth * sin (angle);
174 points.append (QPointF (x, y));
179 case POINT_SHAPE_CROSS:
181 int xyWidth = signed (m_radius);
183 points.append (QPointF (-1 * xyWidth, 0));
184 points.append (QPointF (xyWidth, 0));
185 points.append (QPointF (0, 0));
186 points.append (QPointF (0, xyWidth));
187 points.append (QPointF (0, -1 * xyWidth));
188 points.append (QPointF (0, 0));
192 case POINT_SHAPE_DIAMOND:
194 int xyWidth = signed (m_radius);
196 points.append (QPointF (0, -1 * xyWidth));
197 points.append (QPointF (-1 * xyWidth, 0));
198 points.append (QPointF (0, xyWidth));
199 points.append (QPointF (xyWidth, 0));
203 case POINT_SHAPE_SQUARE:
205 int xyWidth = signed (m_radius);
207 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
208 points.append (QPointF (-1 * xyWidth, xyWidth));
209 points.append (QPointF (xyWidth, xyWidth));
210 points.append (QPointF (xyWidth, -1 * xyWidth));
214 case POINT_SHAPE_TRIANGLE:
216 int xyWidth = signed (m_radius);
218 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
219 points.append (QPointF (0, xyWidth));
220 points.append (QPointF (xyWidth, -1 * xyWidth));
226 int xyWidth = qFloor (m_radius * qSqrt (0.5));
228 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
229 points.append (QPointF (xyWidth, xyWidth));
230 points.append (QPointF (0, 0));
231 points.append (QPointF (-1 * xyWidth, xyWidth));
232 points.append (QPointF (xyWidth, -1 * xyWidth));
233 points.append (QPointF (0, 0));
243 QTextStream &str)
const
245 str << indentation <<
"PointStyle\n";
247 indentation += INDENTATION_DELTA;
249 str << indentation << pointShapeToString (m_shape) <<
"\n";
250 str << indentation <<
"radius=" << m_radius <<
"\n";
251 str << indentation <<
"lineWidth=" << m_lineWidth <<
"\n";
252 str << indentation <<
"color=" << colorPaletteToString (m_paletteColor) <<
"\n";
262 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::saveXml";
264 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
265 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
266 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
267 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
268 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
269 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
270 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
271 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.
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...
unsigned 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.
PointStyle & operator=(const PointStyle &other)
Assignment constructor.
void setRadius(unsigned int radius)
Set method for point radius.
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.