Engauge Digitizer 2
Loading...
Searching...
No Matches
PointStyle.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "DocumentSerialize.h"
8#include "EngaugeAssert.h"
9#include "Logger.h"
10#include "PointStyle.h"
11#include <qmath.h>
12#include <QObject>
13#include <QSettings>
14#include <QTextStream>
15#include <QtToString.h>
16#include <QXmlStreamWriter>
17#include "Settings.h"
18#include "SettingsForGraph.h"
19#include "Xml.h"
20
24const int DEFAULT_POINT_RADIUS = 10;
26const double PI = 3.1415926535;
27const double TWO_PI = 2.0 * PI;
28
30 // Defaults that prevent address sanitizer warnings. Overwritten immediately
32 m_radius (DEFAULT_POINT_RADIUS),
33 m_lineWidth (DEFAULT_POINT_LINE_WIDTH),
34 m_paletteColor (DEFAULT_POINT_COLOR_GRAPH)
35{
36}
37
39 unsigned int radius,
40 int lineWidth,
41 ColorPalette paletteColor) :
42 m_shape (shape),
43 m_radius (radius),
44 m_lineWidth (lineWidth),
45 m_paletteColor (paletteColor)
46{
47}
48
50 m_shape (other.shape()),
51 m_radius (other.radius ()),
52 m_lineWidth (other.lineWidth ()),
53 m_paletteColor (other.paletteColor ())
54{
55}
56
58{
59 m_shape = other.shape ();
60 m_radius = other.radius ();
61 m_lineWidth = other.lineWidth ();
62 m_paletteColor = other.paletteColor ();
63
64 return *this;
65}
66
68{
69 // Get settings if available, otherwise use defaults
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,
78 ColorPalette pointColor = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_POINT_COLOR,
80 settings.endGroup ();
81
82 return PointStyle (shape,
83 radius,
84 pointLineWidth,
85 pointColor);
86}
87
89{
90 // Shape is always computed on the fly
96 shape = pointShapes [index % 4];
97
99 int indexOneBased = index + 1;
101
102 // Get settings if available, otherwise use defaults
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,
109 ColorPalette pointColor = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_POINT_COLOR,
111 settings.endGroup ();
112
113 return PointStyle (shape,
114 radius,
115 pointLineWidth,
116 pointColor);
117}
118
120{
121 return m_shape == POINT_SHAPE_CIRCLE;
122}
123
125{
126 return m_lineWidth;
127}
128
130{
131 LOG4CPP_INFO_S ((*mainCat)) << "PointStyle::loadXml";
132
134
139
144
145 // Read until end of this subtree
146 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
149 }
150 } else {
151 reader.raiseError (QObject::tr ("Cannot read point style data"));
152 }
153}
154
156{
157 return m_paletteColor;
158}
159
161{
162 const int NUM_XY = 60;
163 QVector<QPointF> points;
164
165 switch (m_shape) {
166
168 {
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));
175 }
176 }
177 break;
178
180 {
181 int xyWidth = signed (m_radius);
182
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));
189 }
190 break;
191
193 {
194 int xyWidth = signed (m_radius);
195
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));
200 }
201 break;
202
204 {
205 int xyWidth = signed (m_radius);
206
207 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
208 points.append (QPointF (xyWidth, -1 * xyWidth));
209 points.append (QPointF (-1 * xyWidth, xyWidth));
210 points.append (QPointF (xyWidth, xyWidth));
211 }
212 break;
213
215 {
216 int xyWidth = signed (m_radius);
217
218 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
219 points.append (QPointF (-1 * xyWidth, xyWidth));
220 points.append (QPointF (xyWidth, xyWidth));
221 points.append (QPointF (xyWidth, -1 * xyWidth));
222 }
223 break;
224
226 {
227 int xyWidth = signed (m_radius);
228
229 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
230 points.append (QPointF (0, xyWidth));
231 points.append (QPointF (xyWidth, -1 * xyWidth));
232 }
233 break;
234
236 {
237 int xyWidth = signed (m_radius);
238
239 points.append (QPointF (-1 * xyWidth, xyWidth));
240 points.append (QPointF (0, -1 * xyWidth));
241 points.append (QPointF (xyWidth, xyWidth));
242 }
243 break;
244
245 case POINT_SHAPE_X:
246 {
247 int xyWidth = qFloor (m_radius * qSqrt (0.5));
248
249 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
250 points.append (QPointF (xyWidth, xyWidth));
251 points.append (QPointF (0, 0));
252 points.append (QPointF (-1 * xyWidth, xyWidth));
253 points.append (QPointF (xyWidth, -1 * xyWidth));
254 points.append (QPointF (0, 0));
255 }
256 break;
257 }
258
259 QPolygonF polygon (points);
260 return polygon;
261}
262
264 QTextStream &str) const
265{
266 str << indentation << "PointStyle\n";
267
269
270 str << indentation << pointShapeToString (m_shape) << "\n";
271 str << indentation << "radius=" << m_radius << "\n";
272 str << indentation << "lineWidth=" << m_lineWidth << "\n";
273 str << indentation << "color=" << colorPaletteToString (m_paletteColor) << "\n";
274}
275
276unsigned int PointStyle::radius () const
277{
278 return m_radius;
279}
280
282{
283 LOG4CPP_INFO_S ((*mainCat)) << "PointStyle::saveXml";
284
285 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
286 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
287 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
288 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
290 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
292 writer.writeEndElement();
293}
294
296{
297 m_lineWidth = width;
298}
299
301{
302 m_paletteColor = paletteColor;
303}
304
305void PointStyle::setRadius (unsigned int radius)
306{
307 m_radius = radius;
308}
309
311{
312 m_shape = shape;
313}
314
316{
317 return m_shape;
318}
QString colorPaletteToString(ColorPalette colorPalette)
ColorPalette
@ COLOR_PALETTE_RED
@ COLOR_PALETTE_BLUE
const int INNER_RADIUS_MIN
const double TWO_PI
const QString DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS
const QString DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING
const QString DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH
const QString DOCUMENT_SERIALIZE_POINT_STYLE_COLOR
const QString DOCUMENT_SERIALIZE_POINT_STYLE
const QString DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING
const QString DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString INDENTATION_DELTA
QString pointShapeToString(PointShape pointShape)
PointShape
Definition PointShape.h:12
@ POINT_SHAPE_X
Definition PointShape.h:18
@ POINT_SHAPE_DIAMOND
Definition PointShape.h:15
@ POINT_SHAPE_CIRCLE
Definition PointShape.h:13
@ POINT_SHAPE_TRIANGLE
Definition PointShape.h:17
@ POINT_SHAPE_TRIANGLE2
Definition PointShape.h:20
@ POINT_SHAPE_HOURGLASS
Definition PointShape.h:19
@ POINT_SHAPE_CROSS
Definition PointShape.h:14
@ POINT_SHAPE_SQUARE
Definition PointShape.h:16
const int DEFAULT_POINT_LINE_WIDTH
const PointShape DEFAULT_POINT_SHAPE_AXIS
const int DEFAULT_POINT_RADIUS
const double TWO_PI
const double PI
const ColorPalette DEFAULT_POINT_COLOR_AXES
const ColorPalette DEFAULT_POINT_COLOR_GRAPH
const QString SETTINGS_ENGAUGE
const QString SETTINGS_GROUP_CURVE_AXES
const QString SETTINGS_CURVE_POINT_COLOR
const QString SETTINGS_CURVE_POINT_LINE_WIDTH
const QString SETTINGS_CURVE_POINT_SHAPE
const QString SETTINGS_CURVE_POINT_RADIUS
const QString SETTINGS_DIGITIZER
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
Details for a specific Point.
Definition PointStyle.h:21
unsigned int radius() const
Radius of point. For a circle this is all that is needed to draw a circle. For a polygon,...
PointStyle & operator=(const PointStyle &other)
Assignment constructor.
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.
void loadXml(QXmlStreamReader &reader)
Load model from serialized xml. Returns the curve name.
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...
void setShape(PointShape shape)
Set method for point shape.
PointShape shape() const
Get method for point shape.
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
void setLineWidth(int width)
Set 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(...
static PointStyle defaultAxesCurve()
Initial default for axes curve.
ColorPalette paletteColor() const
Get method for point color.
void setRadius(unsigned int radius)
Set method for point radius.
void saveXml(QXmlStreamWriter &writer) const
Serialize to stream.
int lineWidth() const
Get method for line width.
PointStyle()
Default constructor only for use when this class is being stored by a container that requires the def...
Manage storage and retrieval of the settings for the curves.
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18