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;
39 m_lineWidth (lineWidth),
40 m_paletteColor (paletteColor)
45 m_shape (other.
shape()),
46 m_radius (other.
radius ()),
54 m_shape = other.
shape ();
55 m_radius = other.
radius ();
65 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
66 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
67 PointShape
shape = (PointShape) settings.value (SETTINGS_CURVE_POINT_SHAPE,
68 DEFAULT_POINT_SHAPE_AXIS).toInt();
69 int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
70 DEFAULT_POINT_RADIUS).toInt();
71 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
72 DEFAULT_POINT_LINE_WIDTH).toInt();
73 ColorPalette pointColor = (ColorPalette) settings.value (SETTINGS_CURVE_POINT_COLOR,
74 DEFAULT_POINT_COLOR_AXES).toInt();
86 PointShape
shape = POINT_SHAPE_CROSS;
87 static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
91 shape = pointShapes [index % 4];
94 int indexOneBased = index + 1;
98 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
99 settings.beginGroup (groupName);
100 int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
101 DEFAULT_POINT_RADIUS).toInt();
102 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
103 DEFAULT_POINT_LINE_WIDTH).toInt();
104 ColorPalette pointColor = (ColorPalette) settings.value (SETTINGS_CURVE_POINT_COLOR,
105 DEFAULT_POINT_COLOR_GRAPH).toInt();
106 settings.endGroup ();
116 return m_shape == POINT_SHAPE_CIRCLE;
126 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::loadXml";
128 QXmlStreamAttributes attributes = reader.attributes();
130 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
131 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
132 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
133 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {
135 setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toInt());
136 setLineWidth (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH).toInt());
137 setPaletteColor ((ColorPalette) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt());
138 setShape ((PointShape) attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt());
141 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
142 (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
143 loadNextFromReader(reader);
146 reader.raiseError (QObject::tr (
"Cannot read point style data"));
152 return m_paletteColor;
157 const int NUM_XY = 60;
158 QVector<QPointF> points;
162 case POINT_SHAPE_CIRCLE:
164 int xyWidth = m_radius;
165 for (
int i = 0; i <= NUM_XY; i++) {
166 double angle = TWO_PI * (double) i / (
double) NUM_XY;
167 double x = xyWidth * cos (angle);
168 double y = xyWidth * sin (angle);
169 points.append (QPointF (x, y));
174 case POINT_SHAPE_CROSS:
176 int xyWidth = m_radius;
178 points.append (QPointF (-1 * xyWidth, 0));
179 points.append (QPointF (xyWidth, 0));
180 points.append (QPointF (0, 0));
181 points.append (QPointF (0, xyWidth));
182 points.append (QPointF (0, -1 * xyWidth));
183 points.append (QPointF (0, 0));
187 case POINT_SHAPE_DIAMOND:
189 int xyWidth = m_radius;
191 points.append (QPointF (0, -1 * xyWidth));
192 points.append (QPointF (-1 * xyWidth, 0));
193 points.append (QPointF (0, xyWidth));
194 points.append (QPointF (xyWidth, 0));
198 case POINT_SHAPE_SQUARE:
200 int xyWidth = m_radius;
202 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
203 points.append (QPointF (-1 * xyWidth, xyWidth));
204 points.append (QPointF (xyWidth, xyWidth));
205 points.append (QPointF (xyWidth, -1 * xyWidth));
209 case POINT_SHAPE_TRIANGLE:
211 int xyWidth = m_radius;
213 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
214 points.append (QPointF (0, xyWidth));
215 points.append (QPointF (xyWidth, -1 * xyWidth));
221 int xyWidth = m_radius * qSqrt (0.5);
223 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
224 points.append (QPointF (xyWidth, xyWidth));
225 points.append (QPointF (0, 0));
226 points.append (QPointF (-1 * xyWidth, xyWidth));
227 points.append (QPointF (xyWidth, -1 * xyWidth));
228 points.append (QPointF (0, 0));
233 ENGAUGE_ASSERT (
false);
241 QTextStream &str)
const 243 str << indentation <<
"PointStyle\n";
245 indentation += INDENTATION_DELTA;
247 str << indentation << pointShapeToString (m_shape) <<
"\n";
248 str << indentation <<
"radius=" << m_radius <<
"\n";
249 str << indentation <<
"lineWidth=" << m_lineWidth <<
"\n";
250 str << indentation <<
"color=" << colorPaletteToString (m_paletteColor) <<
"\n";
260 LOG4CPP_INFO_S ((*mainCat)) <<
"PointStyle::saveXml";
262 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
263 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
264 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
265 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
266 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
267 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
268 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
269 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...
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 saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
void setShape(PointShape shape)
Set method for point shape.
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.
Details for a specific Point.
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
PointShape shape() const
Get method for point shape.
PointStyle & operator=(const PointStyle &other)
Assignment constructor.
ColorPalette paletteColor() const
Get method for point color.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index...
bool isCircle() const
Return true if point is a circle, otherwise it is a polygon. For a circle, the radius is important an...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
int lineWidth() const
Get method for line width.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
void setLineWidth(int width)
Set method for line width.
void setRadius(int radius)
Set method for point radius.