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

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}
const QString AXIS_CURVE_NAME
log4cpp::Category * mainCat
Definition Logger.cpp:14
void addPoint(const QString &curveName, const QString &pointIdentifier, double ordinal, GraphicsPoint &point)
Add new point.
static double UNDEFINED_ORDINAL()
Get method for undefined ordinal constant.
Definition Point.h:134
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ 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,
63 *point0);
64 m_graphicsLinesForCurves.addPoint (AXIS_CURVE_NAME,
67 *point1);
68}
const int INNER_RADIUS_MIN

◆ 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
83 GraphicsPoint *point = pointFactory.createPoint (*this,
84 identifier,
85 posScreen,
86 pointStyle,
88
90
91 return point;
92}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
‍Unique identifier for QGraphicsItem object
Definition DataKey.h:15
@ GRAPHICS_ITEM_TYPE_POINT
Factor for generating GraphicsPointAbstractBase class objects.
Graphics item for drawing a circular or polygonal Point.
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.

◆ 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}
@ GRAPHICS_ITEM_TYPE_IMAGE

◆ 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
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
168
169 // Add Point to the list
170 movedIds << item->data(DATA_KEY_IDENTIFIER).toString ();
171
172 }
173 }
174 }
175
176 return movedIds;
177}
@ DATA_KEY_POSITION_HAS_CHANGED
‍Item type (i.e. image versus point)
Definition DataKey.h:16
@ DATA_KEY_IDENTIFIER
Definition DataKey.h: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...

◆ 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}
void removeTemporaryPointIfExists()
Remove temporary point if it exists.

◆ 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}

◆ 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}
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
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}

◆ 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
262
263 } else {
264
265 showThis = (curveNameWanted == identifier);
266
267 }
268 }
269
270 item->setVisible (showThis);
271
272 }
273 }
274}
@ GRAPHICS_ITEM_TYPE_LINE
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

◆ 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,
290 transformation);
291}
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}
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);
332
333 updatePathItemMultiValued (pathMultiValued,
335 }
336}
void updatePointOrdinalsAfterDrag(const CurveStyles &curveStyles, const Transformation &transformation)
See GraphicsScene::updateOrdinalsAfterDrag.
void updateGraphicsLinesToMatchGraphicsPoints(const CurveStyles &curveStyles, SplineDrawer &splineDrawer, QPainterPath &pathMultiValued, LineStyle &lineMultiValued)
Calls to moveLinesWithDraggedPoint have finished so update the lines correspondingly.
Details for a specific Line.
Definition LineStyle.h:20
This class takes the output from Spline and uses that to draw the curve in the graphics window,...
bool transformIsDefined() const
Transform is defined when at least three axis points have been digitized.

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