Engauge Digitizer 2
Loading...
Searching...
No Matches
PointStyle Class Reference

Details for a specific Point. More...

#include <PointStyle.h>

Collaboration diagram for PointStyle:
Collaboration graph

Public Member Functions

 PointStyle ()
 Default constructor only for use when this class is being stored by a container that requires the default constructor.
 PointStyle (PointShape pointShape, unsigned int radius, int lineWidth, ColorPalette paletteColor)
 Normal constructor. The style type and radius are determined by the currently selected Curve.
 PointStyle (const PointStyle &other)
 Copy constructor.
PointStyleoperator= (const PointStyle &other)
 Assignment constructor.
bool isCircle () const
 Return true if point is a circle, otherwise it is a polygon. For a circle, the radius is important and no polygon is needed from this class.
int lineWidth () const
 Get method for line width.
void loadXml (QXmlStreamReader &reader)
 Load model from serialized xml. Returns the curve name.
ColorPalette paletteColor () const
 Get method for point color.
QPolygonF polygon () const
 Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.
void printStream (QString indentation, QTextStream &str) const
 Debugging method that supports print method of this class and printStream method of some other class(es)
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.
void saveXml (QXmlStreamWriter &writer) const
 Serialize to stream.
void setLineWidth (int width)
 Set method for line width.
void setPaletteColor (ColorPalette paletteColor)
 Set method for point color.
void setRadius (unsigned int radius)
 Set method for point radius.
void setShape (PointShape shape)
 Set method for point shape.
PointShape shape () const
 Get method for point shape.

Static Public Member Functions

static PointStyle defaultAxesCurve ()
 Initial default for axes curve.
static PointStyle defaultGraphCurve (int index)
 Initial default for index'th graph curve.

Detailed Description

Details for a specific Point.

Definition at line 20 of file PointStyle.h.

Constructor & Destructor Documentation

◆ PointStyle() [1/3]

PointStyle::PointStyle ( )

Default constructor only for use when this class is being stored by a container that requires the default constructor.

Definition at line 27 of file PointStyle.cpp.

27 :
28 // Defaults that prevent address sanitizer warnings. Overwritten immediately
30 m_radius (DEFAULT_POINT_RADIUS),
31 m_lineWidth (DEFAULT_POINT_LINE_WIDTH),
32 m_paletteColor (DEFAULT_POINT_COLOR_GRAPH)
33{
34}
const int DEFAULT_POINT_LINE_WIDTH
const PointShape DEFAULT_POINT_SHAPE_AXIS
const int DEFAULT_POINT_RADIUS
const ColorPalette DEFAULT_POINT_COLOR_GRAPH

◆ PointStyle() [2/3]

PointStyle::PointStyle ( PointShape pointShape,
unsigned int radius,
int lineWidth,
ColorPalette paletteColor )

Normal constructor. The style type and radius are determined by the currently selected Curve.

Definition at line 36 of file PointStyle.cpp.

39 :
40 m_shape (shape),
41 m_radius (radius),
42 m_lineWidth (lineWidth),
43 m_paletteColor (paletteColor)
44{
45}
unsigned int radius() const
Radius of point. For a circle this is all that is needed to draw a circle. For a polygon,...
PointShape shape() const
Get method for point shape.
ColorPalette paletteColor() const
Get method for point color.
int lineWidth() const
Get method for line width.

◆ PointStyle() [3/3]

PointStyle::PointStyle ( const PointStyle & other)

Copy constructor.

Definition at line 47 of file PointStyle.cpp.

47 :
48 m_shape (other.shape()),
49 m_radius (other.radius ()),
50 m_lineWidth (other.lineWidth ()),
51 m_paletteColor (other.paletteColor ())
52{
53}

Member Function Documentation

◆ defaultAxesCurve()

PointStyle PointStyle::defaultAxesCurve ( )
static

Initial default for axes curve.

Definition at line 65 of file PointStyle.cpp.

66{
67 // Get settings if available, otherwise use defaults
68 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
69 settings.beginGroup (SETTINGS_GROUP_CURVE_AXES);
70 PointShape shape = static_cast<PointShape> (settings.value (SETTINGS_CURVE_POINT_SHAPE,
72 unsigned int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
73 DEFAULT_POINT_RADIUS).toUInt();
74 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
76 ColorPalette pointColor = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_POINT_COLOR,
78 settings.endGroup ();
79
80 return PointStyle (shape,
81 radius,
82 pointLineWidth,
83 pointColor);
84}
ColorPalette
PointShape
Definition PointShape.h:12
const ColorPalette DEFAULT_POINT_COLOR_AXES
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
PointStyle()
Default constructor only for use when this class is being stored by a container that requires the def...

◆ defaultGraphCurve()

PointStyle PointStyle::defaultGraphCurve ( int index)
static

Initial default for index'th graph curve.

Definition at line 86 of file PointStyle.cpp.

87{
88 // Shape is always computed on the fly
90 static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
94 shape = pointShapes [index % 4];
95
96 SettingsForGraph settingsForGraph;
97 int indexOneBased = index + 1;
98 QString groupName = settingsForGraph.groupNameForNthCurve (indexOneBased);
99
100 // Get settings if available, otherwise use defaults
101 QSettings settings (SETTINGS_ENGAUGE, SETTINGS_DIGITIZER);
102 settings.beginGroup (groupName);
103 unsigned int radius = settings.value (SETTINGS_CURVE_POINT_RADIUS,
104 DEFAULT_POINT_RADIUS).toUInt();
105 int pointLineWidth = settings.value (SETTINGS_CURVE_POINT_LINE_WIDTH,
107 ColorPalette pointColor = static_cast<ColorPalette> (settings.value (SETTINGS_CURVE_POINT_COLOR,
109 settings.endGroup ();
110
111 return PointStyle (shape,
112 radius,
113 pointLineWidth,
114 pointColor);
115}
@ POINT_SHAPE_X
Definition PointShape.h:18
@ POINT_SHAPE_DIAMOND
Definition PointShape.h:15
@ POINT_SHAPE_CROSS
Definition PointShape.h:14
@ POINT_SHAPE_SQUARE
Definition PointShape.h:16
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index.

◆ isCircle()

bool PointStyle::isCircle ( ) const

Return true if point is a circle, otherwise it is a polygon. For a circle, the radius is important and no polygon is needed from this class.

Definition at line 117 of file PointStyle.cpp.

118{
119 return m_shape == POINT_SHAPE_CIRCLE;
120}
@ POINT_SHAPE_CIRCLE
Definition PointShape.h:13

◆ lineWidth()

int PointStyle::lineWidth ( ) const

Get method for line width.

Definition at line 122 of file PointStyle.cpp.

123{
124 return m_lineWidth;
125}

◆ loadXml()

void PointStyle::loadXml ( QXmlStreamReader & reader)

Load model from serialized xml. Returns the curve name.

Definition at line 127 of file PointStyle.cpp.

128{
129 LOG4CPP_INFO_S ((*mainCat)) << "PointStyle::loadXml";
130
131 QXmlStreamAttributes attributes = reader.attributes();
132
133 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS) &&
134 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH) &&
135 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE)) {
137
138 setRadius (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS).toUInt());
140 setPaletteColor (static_cast<ColorPalette> (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_COLOR).toInt()));
141 setShape (static_cast<PointShape> (attributes.value(DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE).toInt()));
142
143 // Read until end of this subtree
144 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
145 (reader.name() != DOCUMENT_SERIALIZE_POINT_STYLE)){
146 loadNextFromReader(reader);
147 }
148 } else {
149 reader.raiseError (QObject::tr ("Cannot read point style data"));
150 }
151}
const QString DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS
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_SHAPE
log4cpp::Category * mainCat
Definition Logger.cpp:14
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
void setShape(PointShape shape)
Set method for point shape.
void setLineWidth(int width)
Set method for line width.
void setRadius(unsigned int radius)
Set method for point radius.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ operator=()

PointStyle & PointStyle::operator= ( const PointStyle & other)

Assignment constructor.

Definition at line 55 of file PointStyle.cpp.

56{
57 m_shape = other.shape ();
58 m_radius = other.radius ();
59 m_lineWidth = other.lineWidth ();
60 m_paletteColor = other.paletteColor ();
61
62 return *this;
63}

◆ paletteColor()

ColorPalette PointStyle::paletteColor ( ) const

Get method for point color.

Definition at line 153 of file PointStyle.cpp.

154{
155 return m_paletteColor;
156}

◆ polygon()

QPolygonF PointStyle::polygon ( ) const

Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.

Definition at line 158 of file PointStyle.cpp.

159{
160 const int NUM_XY = 60;
161 QVector<QPointF> points;
162
163 switch (m_shape) {
164
166 {
167 int xyWidth = signed (m_radius);
168 for (int i = 0; i <= NUM_XY; i++) {
169 double angle = 2.0 * M_PI * double (i) / double (NUM_XY);
170 double x = xyWidth * cos (angle);
171 double y = xyWidth * sin (angle);
172 points.append (QPointF (x, y));
173 }
174 }
175 break;
176
178 {
179 int xyWidth = signed (m_radius);
180
181 points.append (QPointF (-1 * xyWidth, 0));
182 points.append (QPointF (xyWidth, 0));
183 points.append (QPointF (0, 0));
184 points.append (QPointF (0, xyWidth));
185 points.append (QPointF (0, -1 * xyWidth));
186 points.append (QPointF (0, 0));
187 }
188 break;
189
191 {
192 int xyWidth = signed (m_radius);
193
194 points.append (QPointF (0, -1 * xyWidth));
195 points.append (QPointF (-1 * xyWidth, 0));
196 points.append (QPointF (0, xyWidth));
197 points.append (QPointF (xyWidth, 0));
198 }
199 break;
200
202 {
203 int xyWidth = signed (m_radius);
204
205 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
206 points.append (QPointF (xyWidth, -1 * xyWidth));
207 points.append (QPointF (-1 * xyWidth, xyWidth));
208 points.append (QPointF (xyWidth, xyWidth));
209 }
210 break;
211
213 {
214 int xyWidth = signed (m_radius);
215
216 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
217 points.append (QPointF (-1 * xyWidth, xyWidth));
218 points.append (QPointF (xyWidth, xyWidth));
219 points.append (QPointF (xyWidth, -1 * xyWidth));
220 }
221 break;
222
224 {
225 int xyWidth = signed (m_radius);
226
227 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
228 points.append (QPointF (0, xyWidth));
229 points.append (QPointF (xyWidth, -1 * xyWidth));
230 }
231 break;
232
234 {
235 int xyWidth = signed (m_radius);
236
237 points.append (QPointF (-1 * xyWidth, xyWidth));
238 points.append (QPointF (0, -1 * xyWidth));
239 points.append (QPointF (xyWidth, xyWidth));
240 }
241 break;
242
243 case POINT_SHAPE_X:
244 {
245 int xyWidth = qFloor (m_radius * qSqrt (0.5));
246
247 points.append (QPointF (-1 * xyWidth, -1 * xyWidth));
248 points.append (QPointF (xyWidth, xyWidth));
249 points.append (QPointF (0, 0));
250 points.append (QPointF (-1 * xyWidth, xyWidth));
251 points.append (QPointF (xyWidth, -1 * xyWidth));
252 points.append (QPointF (0, 0));
253 }
254 break;
255 }
256
257 QPolygonF polygon (points);
258 return polygon;
259}
@ POINT_SHAPE_TRIANGLE
Definition PointShape.h:17
@ POINT_SHAPE_TRIANGLE2
Definition PointShape.h:20
@ POINT_SHAPE_HOURGLASS
Definition PointShape.h:19
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius.

◆ printStream()

void PointStyle::printStream ( QString indentation,
QTextStream & str ) const

Debugging method that supports print method of this class and printStream method of some other class(es)

Definition at line 261 of file PointStyle.cpp.

263{
264 str << indentation << "PointStyle\n";
265
266 indentation += INDENTATION_DELTA;
267
268 str << indentation << pointShapeToString (m_shape) << "\n";
269 str << indentation << "radius=" << m_radius << "\n";
270 str << indentation << "lineWidth=" << m_lineWidth << "\n";
271 str << indentation << "color=" << colorPaletteToString (m_paletteColor) << "\n";
272}
QString colorPaletteToString(ColorPalette colorPalette)
const QString INDENTATION_DELTA
QString pointShapeToString(PointShape pointShape)

◆ radius()

unsigned int PointStyle::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.

Definition at line 274 of file PointStyle.cpp.

275{
276 return m_radius;
277}

◆ saveXml()

void PointStyle::saveXml ( QXmlStreamWriter & writer) const

Serialize to stream.

Definition at line 279 of file PointStyle.cpp.

280{
281 LOG4CPP_INFO_S ((*mainCat)) << "PointStyle::saveXml";
282
283 writer.writeStartElement(DOCUMENT_SERIALIZE_POINT_STYLE);
284 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS, QString::number (m_radius));
285 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH, QString::number (m_lineWidth));
286 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR, QString::number (m_paletteColor));
287 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
288 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
289 writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
290 writer.writeEndElement();
291}
const QString DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING
const QString DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING

◆ setLineWidth()

void PointStyle::setLineWidth ( int width)

Set method for line width.

Definition at line 293 of file PointStyle.cpp.

294{
295 m_lineWidth = width;
296}

◆ setPaletteColor()

void PointStyle::setPaletteColor ( ColorPalette paletteColor)

Set method for point color.

Definition at line 298 of file PointStyle.cpp.

299{
300 m_paletteColor = paletteColor;
301}

◆ setRadius()

void PointStyle::setRadius ( unsigned int radius)

Set method for point radius.

Definition at line 303 of file PointStyle.cpp.

304{
305 m_radius = radius;
306}

◆ setShape()

void PointStyle::setShape ( PointShape shape)

Set method for point shape.

Definition at line 308 of file PointStyle.cpp.

309{
310 m_shape = shape;
311}

◆ shape()

PointShape PointStyle::shape ( ) const

Get method for point shape.

Definition at line 313 of file PointStyle.cpp.

314{
315 return m_shape;
316}

The documentation for this class was generated from the following files: