Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Slots | Public Member Functions | List of all members
GuidelineStateContext Class Reference

Context class for state machine that belongs to the Guideline class. More...

#include <GuidelineStateContext.h>

Inheritance diagram for GuidelineStateContext:
Inheritance graph
Collaboration diagram for GuidelineStateContext:
Collaboration graph

Public Slots

void slotTimeout ()
 

Public Member Functions

 GuidelineStateContext (GuidelineAbstract &guideline, Guidelines &guidelines, GuidelineState guidelineStateInitial)
 Single constructor.
 
virtual ~GuidelineStateContext ()
 
bool cartesian () const
 True/false if coordinates are cartesian/polar.
 
ColorPalette color () const
 Color to be used for guidelines.
 
QPointF convertGraphCoordinateToScreenPoint (double valueGraph) const
 Convert single graph coordinate into screen point pair.
 
double convertScreenPointToGraphCoordinate (const QPointF &posScreen) const
 Convert screen point pair into single graph coordinate.
 
GuidelineAbstractcreateGuideline (const QString &identifier, GuidelineState stateInitial) const
 Factory method for creating a new Guideline.
 
bool doPaint () const
 Allow/skip painting of the owner Guideline.
 
void draggedOffScreen ()
 Guideline has been dragged off screen so remove it.
 
GuidelineAbstractguideline ()
 Guideline that owns this context class.
 
void handleActiveChange (bool active)
 DigitizeState change so active status may (or may not) be toggled.
 
void handleGuidelineMode (bool visibile, bool locked)
 User toggled Guideline visibility and/or locked mode.
 
void handleHoverEnterEvent ()
 If transparent then make visible when hover starts.
 
void handleHoverLeaveEvent ()
 If previously transparent before hover enter then make transparent again.
 
void handleMousePress (const QPointF &posScene)
 At the start of dragging, convert the original Guideline into an invisible handle and visible slaved deployed Guideline.
 
void handleMouseRelease (const QPointF &posScene)
 At the end of dragging, clone the Guideline that owns the state machine where these states live.
 
EllipseParameters pointToEllipse (const QPointF &posScreen) const
 Return ellipse representing constant range, that passes through the specified point.
 
QLineF pointToLine (const QPointF &posScreen) const
 Return line parallel to an axis line, that passes through the specified point.
 
QPointF posCursorGraph () const
 Get method for current cursor coordinate when object was last created/dragged.
 
void requestStateTransition (GuidelineState guidelineState)
 Request a state transition.
 
void setPosCursorGraph (const QPointF &posGraph)
 Pass the current cursor coordinate to the state so it can save the relevant coordinate for later adjustement when the transformation changes.
 
QString stateDump () const
 Dump state for debugging only.
 
QString stateName () const
 State as a string for debugging only.
 
Transformation transformation () const
 Return copy of transformation owned by MainWindow.
 
void updateWithLatestTransformation ()
 Update given Transformation in GuidelineStateContext.
 

Detailed Description

Context class for state machine that belongs to the Guideline class.

The GuidelineAbstract class owns an instance of this class. The base class for all guideline states is GuidelineStateAbstractBase.

While dragging, the Guideline appears to follow a constant-coordinate isocontour during the dragging. The isocontour is along X or Y for cartesian coordinates, or T or R for polar coordinates. This effect is achieved using three GuidelineAbstract instances:

The state machine graph for dragging a Guideline is below:

dot_inline_dotgraph_1.png

This class derives from QObject so it can receive timeouts from the Appearing state, and then perform a state transition after each timeout. If the states received those timeouts then they would not be able to (singlehandedly) take themselves off the stack

Definition at line 129 of file GuidelineStateContext.h.

Constructor & Destructor Documentation

◆ GuidelineStateContext()

GuidelineStateContext::GuidelineStateContext ( GuidelineAbstract & guideline,
Guidelines & guidelines,
GuidelineState guidelineStateInitial )

Single constructor.

Definition at line 52 of file GuidelineStateContext.cpp.

54 :
55 m_guideline (guideline),
56 m_guidelines (guidelines)
57{
90 m_states.insert (GUIDELINE_STATE_DISCARDED , new GuidelineStateDiscarded (*this));
91 m_states.insert (GUIDELINE_STATE_HANDLE_R , new GuidelineStateHandleR (*this));
92 m_states.insert (GUIDELINE_STATE_HANDLE_T , new GuidelineStateHandleT (*this));
93 m_states.insert (GUIDELINE_STATE_HANDLE_X , new GuidelineStateHandleX (*this));
94 m_states.insert (GUIDELINE_STATE_HANDLE_Y , new GuidelineStateHandleY (*this));
95 ENGAUGE_ASSERT (m_states.size () == NUM_GUIDELINE_STATES);
96
97 m_currentState = NUM_GUIDELINE_STATES; // Value that forces a transition right away
98 m_nextState = guidelineStateInitial;
99
100 transitionIfRequested ();
101}
const int INNER_RADIUS_MIN
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
@ GUIDELINE_STATE_HANDLE_Y
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_HOVER
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_LOCK
@ GUIDELINE_STATE_DISCARDED
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_APPEARING
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_EDIT
@ GUIDELINE_STATE_HANDLE_R
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_APPEARING
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_APPEARING
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_HIDE
@ GUIDELINE_STATE_HANDLE_X
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT
@ NUM_GUIDELINE_STATES
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_HOVER
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_APPEARING
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_LOCK
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_HOVER
@ GUIDELINE_STATE_HANDLE_T
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_HIDE
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_HOVER
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT
@ GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_HIDE
GuidelineAbstract & guideline()
Guideline that owns this context class.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_APPEARING.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_HOVER.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_APPEARING.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_HOVER.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDITAPPEARING.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_HOVER.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_APPEARING.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_HOVER.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_EDIT.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_HIDE.
Implements guideline behavior for GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_LOCK.
Implements guideline behavior for GUIDELINE_STATE_DISCARDED.

◆ ~GuidelineStateContext()

GuidelineStateContext::~GuidelineStateContext ( )
virtual

Definition at line 103 of file GuidelineStateContext.cpp.

104{
105}

Member Function Documentation

◆ cartesian()

bool GuidelineStateContext::cartesian ( ) const

True/false if coordinates are cartesian/polar.

Definition at line 107 of file GuidelineStateContext.cpp.

108{
109 return m_guidelines.coordsType () == COORDS_TYPE_CARTESIAN;
110}
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13
CoordsType coordsType() const
Return cartesian or polar.

◆ color()

ColorPalette GuidelineStateContext::color ( ) const

Color to be used for guidelines.

Definition at line 112 of file GuidelineStateContext.cpp.

113{
114 return m_guidelines.color ();
115}
ColorPalette color() const
Color to be used for guidelines.

◆ convertGraphCoordinateToScreenPoint()

QPointF GuidelineStateContext::convertGraphCoordinateToScreenPoint ( double valueGraph) const

Convert single graph coordinate into screen point pair.

Definition at line 117 of file GuidelineStateContext.cpp.

118{
119 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
120
121 return m_states[m_currentState]->convertGraphCoordinateToScreenPoint (valueGraph);
122}

◆ convertScreenPointToGraphCoordinate()

double GuidelineStateContext::convertScreenPointToGraphCoordinate ( const QPointF & posScreen) const

Convert screen point pair into single graph coordinate.

Definition at line 124 of file GuidelineStateContext.cpp.

125{
126 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
127
128 return m_states[m_currentState]->convertScreenPointToGraphCoordinate (posScreen);
129}

◆ createGuideline()

GuidelineAbstract * GuidelineStateContext::createGuideline ( const QString & identifier,
GuidelineState stateInitial ) const

Factory method for creating a new Guideline.

Definition at line 131 of file GuidelineStateContext.cpp.

133{
134 return m_guidelines.createGuideline (identifier,
136}
GuidelineAbstract * createGuideline(const QString &identifier, GuidelineState stateInitial)
Factory method for creating a new Guideline.

◆ doPaint()

bool GuidelineStateContext::doPaint ( ) const

Allow/skip painting of the owner Guideline.

This prevents display of selection markings on otherwise-invisible handle Guideline

Definition at line 138 of file GuidelineStateContext.cpp.

139{
140 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
141
142 return m_states[m_currentState]->doPaint ();
143}

◆ draggedOffScreen()

void GuidelineStateContext::draggedOffScreen ( )

Guideline has been dragged off screen so remove it.

Definition at line 145 of file GuidelineStateContext.cpp.

146{
148 transitionIfRequested ();
149}
void requestStateTransition(GuidelineState guidelineState)
Request a state transition.

◆ guideline()

GuidelineAbstract & GuidelineStateContext::guideline ( )

Guideline that owns this context class.

Definition at line 151 of file GuidelineStateContext.cpp.

152{
153 return m_guideline;
154}

◆ handleActiveChange()

void GuidelineStateContext::handleActiveChange ( bool active)

DigitizeState change so active status may (or may not) be toggled.

Definition at line 156 of file GuidelineStateContext.cpp.

157{
158 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
159
160 m_states[m_currentState]->handleActiveChange (active);
161 transitionIfRequested ();
162}

◆ handleGuidelineMode()

void GuidelineStateContext::handleGuidelineMode ( bool visibile,
bool locked )

User toggled Guideline visibility and/or locked mode.

Definition at line 195 of file GuidelineStateContext.cpp.

197{
198 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
199
200 m_states[m_currentState]->handleGuidelineMode (visible,
201 locked);
202 transitionIfRequested ();
203}

◆ handleHoverEnterEvent()

void GuidelineStateContext::handleHoverEnterEvent ( )

If transparent then make visible when hover starts.

Definition at line 163 of file GuidelineStateContext.cpp.

164{
165 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
166
167 m_states[m_currentState]->handleHoverEnterEvent ();
168 transitionIfRequested ();
169}

◆ handleHoverLeaveEvent()

void GuidelineStateContext::handleHoverLeaveEvent ( )

If previously transparent before hover enter then make transparent again.

Definition at line 171 of file GuidelineStateContext.cpp.

172{
173 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
174
175 m_states[m_currentState]->handleHoverLeaveEvent ();
176 transitionIfRequested ();
177}

◆ handleMousePress()

void GuidelineStateContext::handleMousePress ( const QPointF & posScene)

At the start of dragging, convert the original Guideline into an invisible handle and visible slaved deployed Guideline.

Definition at line 179 of file GuidelineStateContext.cpp.

180{
181 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
182
183 m_states[m_currentState]->handleMousePress (posScene);
184 transitionIfRequested ();
185}

◆ handleMouseRelease()

void GuidelineStateContext::handleMouseRelease ( const QPointF & posScene)

At the end of dragging, clone the Guideline that owns the state machine where these states live.

Definition at line 187 of file GuidelineStateContext.cpp.

188{
189 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
190
191 m_states[m_currentState]->handleMouseRelease (posScene);
192 transitionIfRequested ();
193}

◆ pointToEllipse()

EllipseParameters GuidelineStateContext::pointToEllipse ( const QPointF & posScreen) const

Return ellipse representing constant range, that passes through the specified point.

Definition at line 205 of file GuidelineStateContext.cpp.

206{
207 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
208
209 return m_states[m_currentState]->pointToEllipse (posScreen);
210}

◆ pointToLine()

QLineF GuidelineStateContext::pointToLine ( const QPointF & posScreen) const

Return line parallel to an axis line, that passes through the specified point.

Definition at line 212 of file GuidelineStateContext.cpp.

213{
214 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
215
216 return m_states[m_currentState]->pointToLine (posScreen);
217}

◆ posCursorGraph()

QPointF GuidelineStateContext::posCursorGraph ( ) const

Get method for current cursor coordinate when object was last created/dragged.

Definition at line 219 of file GuidelineStateContext.cpp.

220{
221 return m_posCursorGraph;
222}

◆ requestStateTransition()

void GuidelineStateContext::requestStateTransition ( GuidelineState guidelineState)

Request a state transition.

Definition at line 224 of file GuidelineStateContext.cpp.

225{
227
228 m_nextState = guidelineState;
229}

◆ setPosCursorGraph()

void GuidelineStateContext::setPosCursorGraph ( const QPointF & posGraph)

Pass the current cursor coordinate to the state so it can save the relevant coordinate for later adjustement when the transformation changes.

Definition at line 231 of file GuidelineStateContext.cpp.

232{
233 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
234
235 m_posCursorGraph = posGraph;
236}

◆ slotTimeout

void GuidelineStateContext::slotTimeout ( )
slot

Definition at line 238 of file GuidelineStateContext.cpp.

239{
240 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
241
242 m_states[m_currentState]->handleTimeout ();
243 transitionIfRequested ();
244}

◆ stateDump()

QString GuidelineStateContext::stateDump ( ) const

Dump state for debugging only.

Definition at line 246 of file GuidelineStateContext.cpp.

247{
248 return m_guidelines.stateDump ();
249}
QString stateDump() const
States listed as a string for debugging only.

◆ stateName()

QString GuidelineStateContext::stateName ( ) const

State as a string for debugging only.

Definition at line 251 of file GuidelineStateContext.cpp.

252{
253 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
254
255 return m_states[m_currentState]->stateName();
256}

◆ transformation()

Transformation GuidelineStateContext::transformation ( ) const

Return copy of transformation owned by MainWindow.

Definition at line 258 of file GuidelineStateContext.cpp.

259{
260 return m_guidelines.transformation ();
261}
Transformation transformation() const
Return copy of transformation owned by MainWindow.

◆ updateWithLatestTransformation()

void GuidelineStateContext::updateWithLatestTransformation ( )

Update given Transformation in GuidelineStateContext.

Definition at line 279 of file GuidelineStateContext.cpp.

280{
281 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
282
283 m_states[m_currentState]->updateWithLatestTransformation();
284 transitionIfRequested ();
285}

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