Engauge Digitizer  2
Public Member Functions | List of all members
GraphicsLinesForCurve Class Reference

This class stores the GraphicsLine objects for one Curve. More...

#include <GraphicsLinesForCurve.h>

Inheritance diagram for GraphicsLinesForCurve:
Inheritance graph
Collaboration diagram for GraphicsLinesForCurve:
Collaboration graph

Public Member Functions

 GraphicsLinesForCurve (const QString &curveName)
 Single constructor. More...
 
 ~GraphicsLinesForCurve ()
 
void addPoint (const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
 Add new line. More...
 
double identifierToOrdinal (const QString &identifier) const
 Get ordinal for specified identifier. More...
 
void lineMembershipPurge (const LineStyle &lineStyle, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
 Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines. More...
 
void lineMembershipReset ()
 Mark points as unwanted. Afterwards, lineMembershipPurge gets called. 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...
 
void removePoint (double ordinal)
 Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScene. More...
 
void removeTemporaryPointIfExists ()
 Remove temporary point if it exists. More...
 
void updateAfterCommand (GraphicsScene &scene, const PointStyle &pointStyle, const Point &point, GeometryWindow *geometryWindow)
 Update the GraphicsScene with the specified Point from the Document. If it does not exist yet in the scene, we add it. More...
 
void updateCurveStyle (const CurveStyle &curveStyle)
 Update the curve style for this curve. More...
 
void updateGraphicsLinesToMatchGraphicsPoints (const LineStyle &lineStyle, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
 Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly. More...
 
void updateHighlightOpacity (double highlightOpacity)
 Update the highlight opacity value. This may or may not affect the current display immediately depending on the state. More...
 
void updatePointOrdinalsAfterDrag (const LineStyle &lineStyle, const Transformation &transformation)
 See GraphicsScene::updateOrdinalsAfterDrag. Pretty much the same steps as Curve::updatePointOrdinals. More...
 

Detailed Description

This class stores the GraphicsLine objects for one Curve.

The container is a QMap since that container maintains order by key

Definition at line 27 of file GraphicsLinesForCurve.h.

Constructor & Destructor Documentation

◆ GraphicsLinesForCurve()

GraphicsLinesForCurve::GraphicsLinesForCurve ( const QString &  curveName)

Single constructor.

Definition at line 34 of file GraphicsLinesForCurve.cpp.

34  :
35  m_curveName (curveName)
36 {
37  setZValue (Z_VALUE_CURVE);
40  setData (DATA_KEY_IDENTIFIER,
41  QVariant (m_curveName));
42 }
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
const int Z_VALUE_CURVE
Definition: ZValues.cpp:10

◆ ~GraphicsLinesForCurve()

GraphicsLinesForCurve::~GraphicsLinesForCurve ( )

Definition at line 44 of file GraphicsLinesForCurve.cpp.

45 {
46  OrdinalToGraphicsPoint::iterator itr;
47  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
48  GraphicsPoint *point = itr.value();
49  delete point;
50  }
51 
52  m_graphicsPoints.clear();
53 }
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43

Member Function Documentation

◆ addPoint()

void GraphicsLinesForCurve::addPoint ( const QString &  pointIdentifier,
double  ordinal,
GraphicsPoint point 
)

Add new line.

The GraphicsPoint arguments are not const since this line binds to the points, so dragging points also drags the lines. The ordinal is already in the GraphicsPoint as DATA_KEY_ORDINAL

Definition at line 55 of file GraphicsLinesForCurve.cpp.

58 {
59  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::addPoint"
60  << " curve=" << m_curveName.toLatin1().data()
61  << " identifier=" << pointIdentifier.toLatin1().data()
62  << " ordinal=" << ordinal
63  << " pos=" << QPointFToString (graphicsPoint.pos()).toLatin1().data()
64  << " newPointCount=" << (m_graphicsPoints.count() + 1);
65 
66  m_graphicsPoints [ordinal] = &graphicsPoint;
67 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
QString QPointFToString(const QPointF &pos)
Definition: QtToString.cpp:17
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ identifierToOrdinal()

double GraphicsLinesForCurve::identifierToOrdinal ( const QString &  identifier) const

Get ordinal for specified identifier.

Definition at line 186 of file GraphicsLinesForCurve.cpp.

187 {
188  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::identifierToOrdinal"
189  << " identifier=" << identifier.toLatin1().data();
190 
191  OrdinalToGraphicsPoint::const_iterator itr;
192  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
193 
194  const GraphicsPoint *point = itr.value();
195 
196  if (point->data (DATA_KEY_IDENTIFIER) == identifier) {
197  return itr.key();
198  }
199  }
200 
201  ENGAUGE_ASSERT (false);
202 
203  return 0;
204 }
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20

◆ lineMembershipPurge()

void GraphicsLinesForCurve::lineMembershipPurge ( const LineStyle lineStyle,
SplineDrawer splineDrawer,
QPainterPath &  pathMultiValued,
LineStyle lineMultiValued 
)

Mark the end of addPoint calls. Remove stale lines, insert missing lines, and draw the graphics lines.

Definition at line 206 of file GraphicsLinesForCurve.cpp.

210 {
211  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::lineMembershipPurge"
212  << " curve=" << m_curveName.toLatin1().data();
213 
214  OrdinalToGraphicsPoint::iterator itr, itrNext;
215  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr = itrNext) {
216 
217  itrNext = itr;
218  ++itrNext;
219 
220  GraphicsPoint *point = *itr;
221 
222  if (!point->wanted ()) {
223 
224  double ordinal = itr.key ();
225 
226  delete point;
227  m_graphicsPoints.remove (ordinal);
228  }
229  }
230 
231  // Apply line style
232  QPen pen;
233  if (lineStyle.paletteColor() == COLOR_PALETTE_TRANSPARENT) {
234 
235  pen = QPen (Qt::NoPen);
236 
237  } else {
238 
239  pen = QPen (QBrush (ColorPaletteToQColor (lineStyle.paletteColor())),
240  lineStyle.width());
241 
242  }
243 
244  setPen (pen);
245 
247  splineDrawer,
248  pathMultiValued,
249  lineMultiValued);
250 }
unsigned int width() const
Width of line.
Definition: LineStyle.cpp:173
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
ColorPalette paletteColor() const
Line color.
Definition: LineStyle.cpp:128
QColor ColorPaletteToQColor(ColorPalette color)
Definition: EnumsToQt.cpp:15
bool wanted() const
Identify point as wanted//unwanted.
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void updateGraphicsLinesToMatchGraphicsPoints(const LineStyle &lineStyle, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.

◆ lineMembershipReset()

void GraphicsLinesForCurve::lineMembershipReset ( )

Mark points as unwanted. Afterwards, lineMembershipPurge gets called.

Definition at line 252 of file GraphicsLinesForCurve.cpp.

253 {
254  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::lineMembershipReset"
255  << " curve=" << m_curveName.toLatin1().data();
256 
257  OrdinalToGraphicsPoint::iterator itr;
258  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
259 
260  GraphicsPoint *point = itr.value();
261 
262  point->reset ();
263  }
264 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void reset()
Mark point as unwanted, and unbind any bound lines.

◆ printStream()

void GraphicsLinesForCurve::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 286 of file GraphicsLinesForCurve.cpp.

288 {
289  DataKey type = static_cast<DataKey> (data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt());
290 
291  str << indentation << "GraphicsLinesForCurve=" << m_curveName
292  << " dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
293  << " dataType=" << dataKeyToString (type).toLatin1().data() << "\n";
294 
295  indentation += INDENTATION_DELTA;
296 
297  OrdinalToGraphicsPoint::const_iterator itr;
298  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
299 
300  double ordinalKey = itr.key();
301  const GraphicsPoint *point = itr.value();
302 
303  point->printStream (indentation,
304  str,
305  ordinalKey);
306  }
307 }
QString dataKeyToString(DataKey dataKey)
Definition: DataKey.cpp:9
const QString INDENTATION_DELTA
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
DataKey
Index values for storing item details in QGraphicsItem using setData/data.
Definition: DataKey.h:13
void printStream(QString indentation, QTextStream &str, double ordinalKey) const
Debugging method that supports print method of this class and printStream method of some other class(...
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43

◆ removePoint()

void GraphicsLinesForCurve::removePoint ( double  ordinal)

Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScene.

Definition at line 309 of file GraphicsLinesForCurve.cpp.

310 {
311  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::removePoint"
312  << " point=" << ordinal
313  << " pointCount=" << m_graphicsPoints.count();
314 
315  ENGAUGE_ASSERT (m_graphicsPoints.contains (ordinal));
316  GraphicsPoint *graphicsPoint = m_graphicsPoints [ordinal];
317 
318  m_graphicsPoints.remove (ordinal);
319 
320  delete graphicsPoint;
321 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20

◆ removeTemporaryPointIfExists()

void GraphicsLinesForCurve::removeTemporaryPointIfExists ( )

Remove temporary point if it exists.

Temporary point handling is so complicated that this method quietly allows redundant calls to this method, without complaining that the point has already been removed when called again

Definition at line 323 of file GraphicsLinesForCurve.cpp.

324 {
325  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::removeTemporaryPointIfExists";
326 
327  // Compiler warning about this loop only iterating once is not an issue since there
328  // is never more than one temporary point
329  OrdinalToGraphicsPoint::iterator itr;
330  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
331 
332  GraphicsPoint *graphicsPoint = itr.value();
333 
334  m_graphicsPoints.remove (itr.key());
335 
336  delete graphicsPoint;
337 
338  break;
339  }
340 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateAfterCommand()

void GraphicsLinesForCurve::updateAfterCommand ( GraphicsScene scene,
const PointStyle pointStyle,
const Point point,
GeometryWindow geometryWindow 
)

Update the GraphicsScene with the specified Point from the Document. If it does not exist yet in the scene, we add it.

Definition at line 366 of file GraphicsLinesForCurve.cpp.

370 {
371  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsLinesForCurve::updateAfterCommand"
372  << " curve=" << m_curveName.toLatin1().data()
373  << " pointCount=" << m_graphicsPoints.count();
374 
375  GraphicsPoint *graphicsPoint = nullptr;
376  if (m_graphicsPoints.contains (point.ordinal())) {
377 
378  graphicsPoint = m_graphicsPoints [point.ordinal()];
379 
380  // Due to ordinal renumbering, the coordinates may belong to some other point so we override
381  // them for consistent ordinal-position mapping. Updating the identifier also was added for
382  // better logging (i.e. consistency between Document and GraphicsScene dumps), but happened
383  // to fix a bug with the wrong set of points getting deleted from Cut and Delete
384  graphicsPoint->setPos (point.posScreen());
385  graphicsPoint->setData (DATA_KEY_IDENTIFIER, point.identifier());
386 
387  } else {
388 
389  // Point does not exist in scene so create it
390  graphicsPoint = scene.createPoint (point.identifier (),
391  pointStyle,
392  point.posScreen(),
393  geometryWindow);
394  m_graphicsPoints [point.ordinal ()] = graphicsPoint;
395 
396  }
397 
398  // Mark point as wanted
399  ENGAUGE_CHECK_PTR (graphicsPoint);
400  graphicsPoint->setWanted ();
401 }
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPos(const QPointF pos)
Update the position.
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:404
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition: Point.cpp:386
#define ENGAUGE_CHECK_PTR(ptr)
#endif
Definition: EngaugeAssert.h:27
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen, GeometryWindow *geometryWindow)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
QString identifier() const
Unique identifier for a specific Point.
Definition: Point.cpp:268
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20

◆ updateCurveStyle()

void GraphicsLinesForCurve::updateCurveStyle ( const CurveStyle curveStyle)

Update the curve style for this curve.

Definition at line 403 of file GraphicsLinesForCurve.cpp.

404 {
405  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::updateCurveStyle";
406 
407  OrdinalToGraphicsPoint::const_iterator itr;
408  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
409 
410  GraphicsPoint *point = itr.value();
411  point->updateCurveStyle (curveStyle);
412  }
413 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateGraphicsLinesToMatchGraphicsPoints()

void GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints ( const LineStyle lineStyle,
SplineDrawer splineDrawer,
QPainterPath &  pathMultiValued,
LineStyle lineMultiValued 
)

Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.

Definition at line 429 of file GraphicsLinesForCurve.cpp.

433 {
434  // LOG4CPP_INFO_S is below
435 
436  bool needRenumbering = needOrdinalRenumbering ();
437  if (needRenumbering) {
438 
439  renumberOrdinals();
440 
441  }
442 
443  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::updateGraphicsLinesToMatchGraphicsPoints"
444  << " numberPoints=" << m_graphicsPoints.count()
445  << " ordinalRenumbering=" << (needRenumbering ? "true" : "false");
446 
447  if (lineStyle.curveConnectAs() != CONNECT_SKIP_FOR_AXIS_CURVE) {
448 
449  // Draw as either straight or smoothed. The function/relation differences were handled already with ordinals. The
450  // Spline algorithm will crash with fewer than three points so it is only called when there are enough points
451  QPainterPath path;
452  if (lineStyle.curveConnectAs() == CONNECT_AS_FUNCTION_STRAIGHT ||
454  m_graphicsPoints.count () < 3) {
455 
456  path = drawLinesStraight (pathMultiValued);
457  } else {
458  path = drawLinesSmooth (lineStyle,
459  splineDrawer,
460  pathMultiValued,
461  lineMultiValued);
462  }
463 
464  setPath (path);
465  }
466 }
CurveConnectAs curveConnectAs() const
Get method for connect type.
Definition: LineStyle.cpp:63
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateHighlightOpacity()

void GraphicsLinesForCurve::updateHighlightOpacity ( double  highlightOpacity)

Update the highlight opacity value. This may or may not affect the current display immediately depending on the state.

Definition at line 415 of file GraphicsLinesForCurve.cpp.

416 {
417  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurve::updateCurveStyle"
418  << " curve=" << m_curveName.toLatin1().data()
419  << " highlightOpacity=" << highlightOpacity;
420 
421  OrdinalToGraphicsPoint::const_iterator itr;
422  for (itr = m_graphicsPoints.begin(); itr != m_graphicsPoints.end(); itr++) {
423 
424  GraphicsPoint *point = itr.value();
425  point->setHighlightOpacity (highlightOpacity);
426  }
427 }
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updatePointOrdinalsAfterDrag()

void GraphicsLinesForCurve::updatePointOrdinalsAfterDrag ( const LineStyle lineStyle,
const Transformation transformation 
)

See GraphicsScene::updateOrdinalsAfterDrag. Pretty much the same steps as Curve::updatePointOrdinals.

Definition at line 468 of file GraphicsLinesForCurve.cpp.

470 {
471  CurveConnectAs curveConnectAs = lineStyle.curveConnectAs();
472 
473  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsLinesForCurve::updatePointOrdinalsAfterDrag"
474  << " curve=" << m_curveName.toLatin1().data()
475  << " curveConnectAs=" << curveConnectAsToString(curveConnectAs).toLatin1().data();
476 
477  if (curveConnectAs == CONNECT_AS_FUNCTION_SMOOTH ||
478  curveConnectAs == CONNECT_AS_FUNCTION_STRAIGHT) {
479 
480  // Make sure ordinals are properly ordered
481 
482  // Get a map of x/theta values as keys with point identifiers as the values
483  XOrThetaToOrdinal xOrThetaToOrdinal;
484  OrdinalToGraphicsPoint::iterator itrP;
485  for (itrP = m_graphicsPoints.begin(); itrP != m_graphicsPoints.end(); itrP++) {
486 
487  double ordinal = itrP.key();
488  const GraphicsPoint *point = itrP.value();
489 
490  // Convert screen coordinate to graph coordinates, which gives us x/theta
491  QPointF pointGraph;
492  transformation.transformScreenToRawGraph(point->pos (),
493  pointGraph);
494 
495  xOrThetaToOrdinal [pointGraph.x()] = ordinal;
496  }
497 
498  // Loop through the sorted x/theta values. Since QMap is used, the x/theta keys are sorted
499  OrdinalToGraphicsPoint temporaryList;
500  int ordinalNew = 0;
501  XOrThetaToOrdinal::const_iterator itrX;
502  for (itrX = xOrThetaToOrdinal.begin(); itrX != xOrThetaToOrdinal.end(); itrX++) {
503 
504  double ordinalOld = *itrX;
505  GraphicsPoint *point = m_graphicsPoints [ordinalOld];
506 
507  temporaryList [ordinalNew++] = point;
508  }
509 
510  // Copy from temporary back to original map
511  m_graphicsPoints.clear();
512  for (itrP = temporaryList.begin(); itrP != temporaryList.end(); itrP++) {
513 
514  double ordinal = itrP.key();
515  GraphicsPoint *point = itrP.value();
516 
517  m_graphicsPoints [ordinal] = point;
518  }
519  }
520 }
CurveConnectAs curveConnectAs() const
Get method for connect type.
Definition: LineStyle.cpp:63
QMap< double, double > XOrThetaToOrdinal
QPointF pos() const
Proxy method for QGraphicsItem::pos.
QMap< double, GraphicsPoint * > OrdinalToGraphicsPoint
CurveConnectAs
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
QString curveConnectAsToString(CurveConnectAs curveConnectAs)
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20

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