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

Add point and line handling to generic QGraphicsScene. More...

#include <GraphicsScene.h>

Inheritance diagram for GraphicsScene:
Inheritance graph
Collaboration diagram for GraphicsScene:
Collaboration graph

Public Member Functions

 GraphicsScene (MainWindow *mainWindow)
 Single constructor. More...
 
virtual ~GraphicsScene ()
 Virtual destructor needed since using Q_OBJECT. More...
 
void addTemporaryPoint (const QString &identifier, GraphicsPoint *point)
 Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLineMembership functions. More...
 
void addTemporaryScaleBar (GraphicsPoint *point0, GraphicsPoint *point1, const QString &pointIdentifier0, const QString &pointIdentifier1)
 Add temporary scale bar to scene. More...
 
GraphicsPointcreatePoint (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_graphicsLinesForCurves (see addPoint) More...
 
void hideAllItemsExceptImage ()
 Hide all graphics items, except background image, in preparation for preview during IMPORT_TYPE_ADVANCED. More...
 
QStringList positionHasChangedPointIdentifiers () const
 Return a list of identifiers for the points that have moved since the last call to resetPositionHasChanged. More...
 
void printStream (QString indentation, QTextStream &str)
 Debugging method that supports print method of this class and printStream method of some other class(es) More...
 
void removePoint (const QString &identifier)
 Remove specified point. This aborts if the point does not exist. More...
 
void removeTemporaryPointIfExists ()
 Remove temporary point if it exists. More...
 
void removeTemporaryScaleBarIfExists ()
 Remove temporary scale bar, composed of two points and the line between them. More...
 
void resetOnLoad ()
 Reset, when loading a document after the first, to same state that first document was at when loaded. More...
 
void resetPositionHasChangedFlags ()
 Reset positionHasChanged flag for all items. Typically this is done as part of mousePressEvent. More...
 
void showCurves (bool show, bool showAll=false, const QString &curveName="")
 Show or hide all Curves (if showAll is true) or just the selected Curve (if showAll is false);. More...
 
void updateAfterCommand (CmdMediator &cmdMediator, double highlightOpacity, GeometryWindow *geometryWindow, const Transformation &transformation)
 Update the Points and their Curves after executing a command. More...
 
void updateCurveStyles (const CurveStyles &modelCurveStyles)
 Update curve styles after settings changed. More...
 
void updateGraphicsLinesToMatchGraphicsPoints (const CurveStyles &modelCurveStyles, const Transformation &transformation)
 A mouse move has just occurred so move the selected points, since they were dragged. More...
 

Detailed Description

Add point and line handling to generic QGraphicsScene.

The primary tasks are:

  1. update the graphics items to stay in sync with the explicit Points in the Document
  2. update the graphics items to stay in sync with the implicit lines between the Points, according to Document settings

This class stores points and lines as QGraphicsItems, but also maintains identifier-to-QGraphicsItems mappings to the points and lines are accessible for updates (like when dragging points around and we need to update the attached lines).

Definition at line 36 of file GraphicsScene.h.

Constructor & Destructor Documentation

◆ GraphicsScene()

GraphicsScene::GraphicsScene ( MainWindow mainWindow)

Single constructor.

Definition at line 29 of file GraphicsScene.cpp.

29  :
30  QGraphicsScene(mainWindow),
31  m_pathItemMultiValued (nullptr)
32 {
33 }

◆ ~GraphicsScene()

GraphicsScene::~GraphicsScene ( )
virtual

Virtual destructor needed since using Q_OBJECT.

Definition at line 35 of file GraphicsScene.cpp.

36 {
37 }

Member Function Documentation

◆ addTemporaryPoint()

void GraphicsScene::addTemporaryPoint ( const QString &  identifier,
GraphicsPoint point 
)

Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLineMembership functions.

Definition at line 39 of file GraphicsScene.cpp.

41 {
42  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::addTemporaryPoint"
43  << " identifer=" << identifier.toLatin1().data();
44 
45  m_graphicsLinesForCurves.addPoint (AXIS_CURVE_NAME,
46  identifier,
48  *point);
49 }
void addPoint(const QString &curveName, const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new point.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
static double UNDEFINED_ORDINAL()
Get method for undefined ordinal constant.
Definition: Point.h:134
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString AXIS_CURVE_NAME

◆ addTemporaryScaleBar()

void GraphicsScene::addTemporaryScaleBar ( GraphicsPoint point0,
GraphicsPoint point1,
const QString &  pointIdentifier0,
const QString &  pointIdentifier1 
)

Add temporary scale bar to scene.

The scale bar is different from points and lines (always a complete set of 2 points and one line, and drawn using different point and line styles) that it is handled outside m_graphisLinesForCurves

Definition at line 51 of file GraphicsScene.cpp.

55 {
56  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::addTemporaryScaleBar";
57 
58  const double ORDINAL_0 = 0, ORDINAL_1 = 1;
59 
60  m_graphicsLinesForCurves.addPoint (AXIS_CURVE_NAME,
61  pointIdentifier0,
62  ORDINAL_0,
63  *point0);
64  m_graphicsLinesForCurves.addPoint (AXIS_CURVE_NAME,
65  pointIdentifier1,
66  ORDINAL_1,
67  *point1);
68 }
void addPoint(const QString &curveName, const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new point.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString AXIS_CURVE_NAME

◆ createPoint()

GraphicsPoint * GraphicsScene::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_graphicsLinesForCurves (see addPoint)

Definition at line 70 of file GraphicsScene.cpp.

74 {
75  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::createPoint"
76  << " identifier=" << identifier.toLatin1().data();
77 
78  // Ordinal value is initially computed as one plus the max ordinal seen so far. This initial ordinal value will be overridden if the
79  // cordinates determine the ordinal values.
80  //
81  // This is an N-squared algorithm and may be worth replacing later
82  GraphicsPointFactory pointFactory;
83  GraphicsPoint *point = pointFactory.createPoint (*this,
84  identifier,
85  posScreen,
86  pointStyle,
87  geometryWindow);
88 
90 
91  return point;
92 }
Factor for generating GraphicsPointAbstractBase class objects.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
GraphicsPoint * createPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const PointStyle &pointStyle, GeometryWindow *geometryWindow)
Create circle or polygon point according to the PointStyle.
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ hideAllItemsExceptImage()

void GraphicsScene::hideAllItemsExceptImage ( )

Hide all graphics items, except background image, in preparation for preview during IMPORT_TYPE_ADVANCED.

Definition at line 108 of file GraphicsScene.cpp.

109 {
110  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::hideAllItemsExceptImage";
111 
112  for (int index = 0; index < QGraphicsScene::items().count(); index++) {
113  QGraphicsItem *item = QGraphicsScene::items().at(index);
114 
115  if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt() == GRAPHICS_ITEM_TYPE_IMAGE) {
116 
117  item->show();
118 
119  } else {
120 
121  item->hide();
122 
123  }
124  }
125 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ positionHasChangedPointIdentifiers()

QStringList GraphicsScene::positionHasChangedPointIdentifiers ( ) const

Return a list of identifiers for the points that have moved since the last call to resetPositionHasChanged.

Definition at line 144 of file GraphicsScene.cpp.

145 {
146  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::positionHasChangedPointIdentifiers";
147 
148  QStringList movedIds;
149 
150  const QList<QGraphicsItem*> &items = QGraphicsScene::items();
151  QList<QGraphicsItem*>::const_iterator itr;
152  for (itr = items.begin(); itr != items.end(); itr++) {
153 
154  const QGraphicsItem *item = *itr;
155 
156  // Skip the image and only keep the Points
157  bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
158  if (isPoint) {
159 
160  QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
161  bool positionHasChanged = item->data (DATA_KEY_POSITION_HAS_CHANGED).toBool ();
162 
163  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsScene::positionHasChangedPointIdentifiers"
164  << " identifier=" << identifier.toLatin1().data()
165  << " positionHasChanged=" << (positionHasChanged ? "yes" : "no");
166 
167  if (isPoint && positionHasChanged) {
168 
169  // Add Point to the list
170  movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
171 
172  }
173  }
174  }
175 
176  return movedIds;
177 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
Item type (i.e. image versus point)
Definition: DataKey.h:16
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20

◆ printStream()

void GraphicsScene::printStream ( QString  indentation,
QTextStream &  str 
)

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

Definition at line 179 of file GraphicsScene.cpp.

181 {
182  m_graphicsLinesForCurves.printStream (indentation,
183  str);
184 }
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...

◆ removePoint()

void GraphicsScene::removePoint ( const QString &  identifier)

Remove specified point. This aborts if the point does not exist.

Definition at line 186 of file GraphicsScene.cpp.

187 {
188  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::removePoint identifier=" << identifier.toLatin1().data();
189 
190  m_graphicsLinesForCurves.removePoint (identifier);
191 }
void removePoint(const QString &identifier)
Remove the specified point. The act of deleting it will automatically remove it from the GraphicsScen...
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ removeTemporaryPointIfExists()

void GraphicsScene::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 193 of file GraphicsScene.cpp.

194 {
195  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::removeTemporaryPointIfExists";
196 
197  m_graphicsLinesForCurves.removeTemporaryPointIfExists ();
198 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void removeTemporaryPointIfExists()
Remove temporary point if it exists.
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ removeTemporaryScaleBarIfExists()

void GraphicsScene::removeTemporaryScaleBarIfExists ( )

Remove temporary scale bar, composed of two points and the line between them.

Definition at line 200 of file GraphicsScene.cpp.

201 {
202  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::removeTemporaryScaleBarIfExists";
203 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ resetOnLoad()

void GraphicsScene::resetOnLoad ( )

Reset, when loading a document after the first, to same state that first document was at when loaded.

Definition at line 205 of file GraphicsScene.cpp.

206 {
207  // LOG4CPP_INFO_S is below
208 
209  int itemsBefore = items().count();
210 
211  m_graphicsLinesForCurves.resetOnLoad();
212 
213  int itemsAfter = items().count();
214 
215  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::resetOnLoad"
216  << " itemsBefore=" << itemsBefore
217  << " itemsAfter=" << itemsAfter;
218 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void resetOnLoad()
Reset, when loading a document after the first, to same state that first document was at when loaded...

◆ resetPositionHasChangedFlags()

void GraphicsScene::resetPositionHasChangedFlags ( )

Reset positionHasChanged flag for all items. Typically this is done as part of mousePressEvent.

Definition at line 220 of file GraphicsScene.cpp.

221 {
222  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::resetPositionHasChangedFlags";
223 
224  QList<QGraphicsItem*> itms = items ();
225  QList<QGraphicsItem*>::const_iterator itr;
226  for (itr = itms.begin (); itr != itms.end (); itr++) {
227 
228  QGraphicsItem *item = *itr;
229  item->setData (DATA_KEY_POSITION_HAS_CHANGED, false);
230  }
231 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Item type (i.e. image versus point)
Definition: DataKey.h:16
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ showCurves()

void GraphicsScene::showCurves ( bool  show,
bool  showAll = false,
const QString &  curveName = "" 
)

Show or hide all Curves (if showAll is true) or just the selected Curve (if showAll is false);.

Definition at line 233 of file GraphicsScene.cpp.

236 {
237  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::showCurves"
238  << " show=" << (show ? "true" : "false")
239  << " showAll=" << (showAll ? "true" : "false")
240  << " curve=" << curveNameWanted.toLatin1().data();
241 
242  const QList<QGraphicsItem*> &items = QGraphicsScene::items();
243  QList<QGraphicsItem*>::const_iterator itr;
244  for (itr = items.begin(); itr != items.end(); itr++) {
245 
246  QGraphicsItem* item = *itr;
247 
248  // Skip the image and only process the Points
249  bool isPoint = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT);
250  bool isCurve = (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_LINE);
251 
252  if (isPoint || isCurve) {
253 
254  bool showThis = show;
255  if (show && !showAll) {
256  QString identifier = item->data (DATA_KEY_IDENTIFIER).toString ();
257 
258  if (isPoint) {
259 
260  QString curveNameGot = Point::curveNameFromPointIdentifier (identifier);
261  showThis = (curveNameWanted == curveNameGot);
262 
263  } else {
264 
265  showThis = (curveNameWanted == identifier);
266 
267  }
268  }
269 
270  item->setVisible (showThis);
271 
272  }
273  }
274 }
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
Definition: Point.cpp:227
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateAfterCommand()

void GraphicsScene::updateAfterCommand ( CmdMediator cmdMediator,
double  highlightOpacity,
GeometryWindow geometryWindow,
const Transformation transformation 
)

Update the Points and their Curves after executing a command.

After a mouse drag, the lines are already updated and updating would be done on out of date information (since that would be brought up to date by the NEXT command)

Definition at line 276 of file GraphicsScene.cpp.

280 {
281  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::updateAfterCommand";
282 
283  m_graphicsLinesForCurves.updateHighlightOpacity (highlightOpacity);
284 
285  updateCurves (cmdMediator);
286 
287  // Update the points
288  updatePointMembership (cmdMediator,
289  geometryWindow,
290  transformation);
291 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void updateHighlightOpacity(double highlightOpacity)
Update the highlight opacity value. This may or may not affect the current display immediately depend...

◆ updateCurveStyles()

void GraphicsScene::updateCurveStyles ( const CurveStyles modelCurveStyles)

Update curve styles after settings changed.

Definition at line 306 of file GraphicsScene.cpp.

307 {
308  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::updateCurveStyles";
309 
310  m_graphicsLinesForCurves.updateCurveStyles (modelCurveStyles);
311 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void updateCurveStyles(const CurveStyles &modelCurveStyles)
Update the curve style for every curve.

◆ updateGraphicsLinesToMatchGraphicsPoints()

void GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints ( const CurveStyles modelCurveStyles,
const Transformation transformation 
)

A mouse move has just occurred so move the selected points, since they were dragged.

The transformation is needed so the screen coordinates can be converted to graph coordinates when updating point ordinals

Definition at line 313 of file GraphicsScene.cpp.

315 {
316  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::updateGraphicsLinesToMatchGraphicsPoints";
317 
318  if (transformation.transformIsDefined()) {
319 
320  // Ordinals must be updated to reflect reordering that may have resulted from dragging points
321  m_graphicsLinesForCurves.updatePointOrdinalsAfterDrag (curveStyles,
322  transformation);
323 
324  // Recompute the lines one time for efficiency
325  SplineDrawer splineDrawer (transformation);
326  QPainterPath pathMultiValued;
327  LineStyle lineMultiValued;
328  m_graphicsLinesForCurves.updateGraphicsLinesToMatchGraphicsPoints (curveStyles,
329  splineDrawer,
330  pathMultiValued,
331  lineMultiValued);
332 
333  updatePathItemMultiValued (pathMultiValued,
334  lineMultiValued);
335  }
336 }
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &curveStyles, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void updatePointOrdinalsAfterDrag(const CurveStyles &curveStyles, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag.
Details for a specific Line.
Definition: LineStyle.h:19
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
This class takes the output from Spline and uses that to draw the curve in the graphics window...
Definition: SplineDrawer.h:35

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