Engauge Digitizer  2
Public Member Functions | Static Public Member Functions | List of all members
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. More...
 
 PointStyle (PointShape pointShape, unsigned int radius, int lineWidth, ColorPalette paletteColor)
 Normal constructor. The style type and radius are determined by the currently selected Curve. More...
 
 PointStyle (const PointStyle &other)
 Copy constructor. More...
 
PointStyleoperator= (const PointStyle &other)
 Assignment constructor. More...
 
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. More...
 
int lineWidth () const
 Get method for line width. More...
 
void loadXml (QXmlStreamReader &reader)
 Load model from serialized xml. Returns the curve name. More...
 
ColorPalette paletteColor () const
 Get method for point color. More...
 
QPolygonF polygon () const
 Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius. More...
 
void printStream (QString indentation, QTextStream &str) const
 Debugging method that supports print method of this class and printStream method of some other class(es) More...
 
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. More...
 
void saveXml (QXmlStreamWriter &writer) const
 Serialize to stream. More...
 
void setLineWidth (int width)
 Set method for line width. More...
 
void setPaletteColor (ColorPalette paletteColor)
 Set method for point color. More...
 
void setRadius (unsigned int radius)
 Set method for point radius. More...
 
void setShape (PointShape shape)
 Set method for point shape. More...
 
PointShape shape () const
 Get method for point shape. More...
 

Static Public Member Functions

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

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 29 of file PointStyle.cpp.

29  :
30  // Defaults that prevent address sanitizer warnings. Overwritten immediately
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)
35 {
36 }
const PointShape DEFAULT_POINT_SHAPE_AXIS
Definition: PointStyle.cpp:25
const ColorPalette DEFAULT_POINT_COLOR_GRAPH
Definition: PointStyle.cpp:22
const int DEFAULT_POINT_RADIUS
Definition: PointStyle.cpp:24
const int DEFAULT_POINT_LINE_WIDTH
Definition: PointStyle.cpp:23

◆ 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 38 of file PointStyle.cpp.

41  :
42  m_shape (shape),
43  m_radius (radius),
44  m_lineWidth (lineWidth),
45  m_paletteColor (paletteColor)
46 {
47 }
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315
ColorPalette paletteColor() const
Get method for point color.
Definition: PointStyle.cpp:155
int lineWidth() const
Get method for line width.
Definition: PointStyle.cpp:124
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.
Definition: PointStyle.cpp:276

◆ PointStyle() [3/3]

PointStyle::PointStyle ( const PointStyle other)

Copy constructor.

Definition at line 49 of file PointStyle.cpp.

49  :
50  m_shape (other.shape()),
51  m_radius (other.radius ()),
52  m_lineWidth (other.lineWidth ()),
53  m_paletteColor (other.paletteColor ())
54 {
55 }
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315
ColorPalette paletteColor() const
Get method for point color.
Definition: PointStyle.cpp:155
int lineWidth() const
Get method for line width.
Definition: PointStyle.cpp:124
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.
Definition: PointStyle.cpp:276

Member Function Documentation

◆ defaultAxesCurve()

PointStyle PointStyle::defaultAxesCurve ( )
static

Initial default for axes curve.

Definition at line 67 of file PointStyle.cpp.

68 {
69  // Get settings if available, otherwise use defaults
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());
80  settings.endGroup ();
81 
82  return PointStyle (shape,
83  radius,
84  pointLineWidth,
85  pointColor);
86 }
const QString SETTINGS_GROUP_CURVE_AXES
const QString SETTINGS_CURVE_POINT_SHAPE
PointStyle()
Default constructor only for use when this class is being stored by a container that requires the def...
Definition: PointStyle.cpp:29
const QString SETTINGS_CURVE_POINT_RADIUS
const QString SETTINGS_DIGITIZER
const PointShape DEFAULT_POINT_SHAPE_AXIS
Definition: PointStyle.cpp:25
const QString SETTINGS_CURVE_POINT_COLOR
PointShape
Definition: PointShape.h:12
const ColorPalette DEFAULT_POINT_COLOR_AXES
Definition: PointStyle.cpp:21
const QString SETTINGS_ENGAUGE
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315
const QString SETTINGS_CURVE_POINT_LINE_WIDTH
const int DEFAULT_POINT_RADIUS
Definition: PointStyle.cpp:24
const int DEFAULT_POINT_LINE_WIDTH
Definition: PointStyle.cpp:23
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.
Definition: PointStyle.cpp:276
ColorPalette
Definition: ColorPalette.h:12

◆ defaultGraphCurve()

PointStyle PointStyle::defaultGraphCurve ( int  index)
static

Initial default for index'th graph curve.

Definition at line 88 of file PointStyle.cpp.

89 {
90  // Shape is always computed on the fly
92  static PointShape pointShapes [] = {POINT_SHAPE_CROSS,
96  shape = pointShapes [index % 4];
97 
98  SettingsForGraph settingsForGraph;
99  int indexOneBased = index + 1;
100  QString groupName = settingsForGraph.groupNameForNthCurve (indexOneBased);
101 
102  // Get settings if available, otherwise use defaults
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 ();
112 
113  return PointStyle (shape,
114  radius,
115  pointLineWidth,
116  pointColor);
117 }
Manage storage and retrieval of the settings for the curves.
PointStyle()
Default constructor only for use when this class is being stored by a container that requires the def...
Definition: PointStyle.cpp:29
const QString SETTINGS_CURVE_POINT_RADIUS
const QString SETTINGS_DIGITIZER
const ColorPalette DEFAULT_POINT_COLOR_GRAPH
Definition: PointStyle.cpp:22
const QString SETTINGS_CURVE_POINT_COLOR
PointShape
Definition: PointShape.h:12
const QString SETTINGS_ENGAUGE
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315
QString groupNameForNthCurve(int indexOneBased) const
Return the group name, that appears in the settings file/registry, for the specified curve index...
const QString SETTINGS_CURVE_POINT_LINE_WIDTH
const int DEFAULT_POINT_RADIUS
Definition: PointStyle.cpp:24
const int DEFAULT_POINT_LINE_WIDTH
Definition: PointStyle.cpp:23
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.
Definition: PointStyle.cpp:276
ColorPalette
Definition: ColorPalette.h:12

◆ 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 119 of file PointStyle.cpp.

120 {
121  return m_shape == POINT_SHAPE_CIRCLE;
122 }

◆ lineWidth()

int PointStyle::lineWidth ( ) const

Get method for line width.

Definition at line 124 of file PointStyle.cpp.

125 {
126  return m_lineWidth;
127 }

◆ loadXml()

void PointStyle::loadXml ( QXmlStreamReader &  reader)

Load model from serialized xml. Returns the curve name.

Definition at line 129 of file PointStyle.cpp.

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

◆ operator=()

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

Assignment constructor.

Definition at line 57 of file PointStyle.cpp.

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 }
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315
ColorPalette paletteColor() const
Get method for point color.
Definition: PointStyle.cpp:155
int lineWidth() const
Get method for line width.
Definition: PointStyle.cpp:124
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.
Definition: PointStyle.cpp:276

◆ paletteColor()

ColorPalette PointStyle::paletteColor ( ) const

Get method for point color.

Definition at line 155 of file PointStyle.cpp.

156 {
157  return m_paletteColor;
158 }

◆ polygon()

QPolygonF PointStyle::polygon ( ) const

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

Definition at line 160 of file PointStyle.cpp.

161 {
162  const int NUM_XY = 60;
163  QVector<QPointF> points;
164 
165  switch (m_shape) {
166 
167  case POINT_SHAPE_CIRCLE:
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 
179  case POINT_SHAPE_CROSS:
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 
192  case POINT_SHAPE_DIAMOND:
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 
214  case POINT_SHAPE_SQUARE:
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 }
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
Definition: PointStyle.cpp:160
const double TWO_PI
Definition: PointStyle.cpp:27

◆ 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 263 of file PointStyle.cpp.

265 {
266  str << indentation << "PointStyle\n";
267 
268  indentation += INDENTATION_DELTA;
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 }
QString colorPaletteToString(ColorPalette colorPalette)
Definition: ColorPalette.cpp:9
const QString INDENTATION_DELTA
QString pointShapeToString(PointShape pointShape)
Definition: PointShape.cpp:10

◆ 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 276 of file PointStyle.cpp.

277 {
278  return m_radius;
279 }

◆ saveXml()

void PointStyle::saveXml ( QXmlStreamWriter &  writer) const

Serialize to stream.

Definition at line 281 of file PointStyle.cpp.

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));
289  writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING, colorPaletteToString (m_paletteColor));
290  writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE, QString::number (m_shape));
291  writer.writeAttribute (DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING, pointShapeToString (m_shape));
292  writer.writeEndElement();
293 }
QString colorPaletteToString(ColorPalette colorPalette)
Definition: ColorPalette.cpp:9
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const QString DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE
const QString DOCUMENT_SERIALIZE_POINT_STYLE
const QString DOCUMENT_SERIALIZE_POINT_STYLE_RADIUS
const QString DOCUMENT_SERIALIZE_POINT_STYLE_LINE_WIDTH
QString pointShapeToString(PointShape pointShape)
Definition: PointShape.cpp:10
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString DOCUMENT_SERIALIZE_POINT_STYLE_COLOR_STRING
const QString DOCUMENT_SERIALIZE_POINT_STYLE_SHAPE_STRING
const QString DOCUMENT_SERIALIZE_POINT_STYLE_COLOR

◆ setLineWidth()

void PointStyle::setLineWidth ( int  width)

Set method for line width.

Definition at line 295 of file PointStyle.cpp.

296 {
297  m_lineWidth = width;
298 }

◆ setPaletteColor()

void PointStyle::setPaletteColor ( ColorPalette  paletteColor)

Set method for point color.

Definition at line 300 of file PointStyle.cpp.

301 {
302  m_paletteColor = paletteColor;
303 }
ColorPalette paletteColor() const
Get method for point color.
Definition: PointStyle.cpp:155

◆ setRadius()

void PointStyle::setRadius ( unsigned int  radius)

Set method for point radius.

Definition at line 305 of file PointStyle.cpp.

306 {
307  m_radius = radius;
308 }
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.
Definition: PointStyle.cpp:276

◆ setShape()

void PointStyle::setShape ( PointShape  shape)

Set method for point shape.

Definition at line 310 of file PointStyle.cpp.

311 {
312  m_shape = shape;
313 }
PointShape shape() const
Get method for point shape.
Definition: PointStyle.cpp:315

◆ shape()

PointShape PointStyle::shape ( ) const

Get method for point shape.

Definition at line 315 of file PointStyle.cpp.

316 {
317  return m_shape;
318 }

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