Engauge Digitizer 2
Loading...
Searching...
No Matches
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, MainWindow &mainWindow, 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.
DocumentModelGuideline modelGuideline () const
 Up-to-date guideline settings.
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 dragged Guideline that is initially visible and clicked on by the user. It immediately becomes invisible since it cannot be redrawn while being dragged (a constraint of the Qt framework). The state of this Guideline is Handle.
  • The visible Guideline that is created as soon as the dragged Guideline is made invisible. The visible Guideline is moved along with the cursor during the dragging. It starts out looking just like the dragged Guideline, but changes to follow the relevant isocontours during the dragging. The user will think he/she is dragging the visible Guideline directly, but this is an illusion. The state of this Guideline is Deployed.
  • The replacement Guideline that replaces both the dragged and visible Guideline instances when the mouse is released. This Guideline is off the stack when the mouse is released and therefore can be the target of a new CmdGuidelineMoveXT or CmdGuidelineMoveYR which wants to move something as soons as its redo method is called. The state of this Guideline is Deployed.

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 131 of file GuidelineStateContext.h.

Constructor & Destructor Documentation

◆ GuidelineStateContext()

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

Single constructor.

Definition at line 54 of file GuidelineStateContext.cpp.

57 :
58 m_guideline (guideline),
59 m_guidelines (guidelines),
60 m_mainWindow (mainWindow)
61{
62 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT , new GuidelineStateDeployedConstantRSelectEdit (*this));
63 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_APPEARING, new GuidelineStateDeployedConstantRSelectEditAppearing (*this));
64 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_EDIT_HOVER , new GuidelineStateDeployedConstantRSelectEditHover (*this));
65 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_HIDE , new GuidelineStateDeployedConstantRSelectHide (*this));
66 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_SELECT_LOCK , new GuidelineStateDeployedConstantRSelectLock (*this));
67 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_EDIT , new GuidelineStateDeployedConstantRUnselectEdit (*this));
68 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_HIDE , new GuidelineStateDeployedConstantRUnselectHide (*this));
69 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_R_UNSELECT_LOCK , new GuidelineStateDeployedConstantRUnselectLock (*this));
70 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT , new GuidelineStateDeployedConstantTSelectEdit (*this));
71 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_APPEARING, new GuidelineStateDeployedConstantTSelectEditAppearing (*this));
72 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_EDIT_HOVER , new GuidelineStateDeployedConstantTSelectEditHover (*this));
73 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_HIDE , new GuidelineStateDeployedConstantTSelectHide (*this));
74 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_SELECT_LOCK , new GuidelineStateDeployedConstantTSelectLock (*this));
75 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_EDIT , new GuidelineStateDeployedConstantTUnselectEdit (*this));
76 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_HIDE , new GuidelineStateDeployedConstantTUnselectHide (*this));
77 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_T_UNSELECT_LOCK , new GuidelineStateDeployedConstantTUnselectLock (*this));
78 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT , new GuidelineStateDeployedConstantXSelectEdit (*this));
79 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_APPEARING, new GuidelineStateDeployedConstantXSelectEditAppearing (*this));
80 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_EDIT_HOVER , new GuidelineStateDeployedConstantXSelectEditHover (*this));
81 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_HIDE , new GuidelineStateDeployedConstantXSelectHide (*this));
82 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_SELECT_LOCK , new GuidelineStateDeployedConstantXSelectLock (*this));
83 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_EDIT , new GuidelineStateDeployedConstantXUnselectEdit (*this));
84 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_HIDE , new GuidelineStateDeployedConstantXUnselectHide (*this));
85 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_X_UNSELECT_LOCK , new GuidelineStateDeployedConstantXUnselectLock (*this));
86 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT , new GuidelineStateDeployedConstantYSelectEdit (*this));
87 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_APPEARING, new GuidelineStateDeployedConstantYSelectEditAppearing (*this));
88 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_EDIT_HOVER , new GuidelineStateDeployedConstantYSelectEditHover (*this));
89 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_HIDE , new GuidelineStateDeployedConstantYSelectHide (*this));
90 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_SELECT_LOCK , new GuidelineStateDeployedConstantYSelectLock (*this));
91 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_EDIT , new GuidelineStateDeployedConstantYUnselectEdit (*this));
92 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_HIDE , new GuidelineStateDeployedConstantYUnselectHide (*this));
93 m_states.insert (GUIDELINE_STATE_DEPLOYED_CONSTANT_Y_UNSELECT_LOCK , new GuidelineStateDeployedConstantYUnselectLock (*this));
94 m_states.insert (GUIDELINE_STATE_DISCARDED , new GuidelineStateDiscarded (*this));
95 m_states.insert (GUIDELINE_STATE_HANDLE_R , new GuidelineStateHandleR (*this));
96 m_states.insert (GUIDELINE_STATE_HANDLE_T , new GuidelineStateHandleT (*this));
97 m_states.insert (GUIDELINE_STATE_HANDLE_X , new GuidelineStateHandleX (*this));
98 m_states.insert (GUIDELINE_STATE_HANDLE_Y , new GuidelineStateHandleY (*this));
99 ENGAUGE_ASSERT (m_states.size () == NUM_GUIDELINE_STATES);
100
101 m_currentState = NUM_GUIDELINE_STATES; // Value that forces a transition right away
102 m_nextState = guidelineStateInitial;
103
104 transitionIfRequested ();
105}
#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.

◆ ~GuidelineStateContext()

GuidelineStateContext::~GuidelineStateContext ( )
virtual

Definition at line 107 of file GuidelineStateContext.cpp.

108{
109}

Member Function Documentation

◆ cartesian()

bool GuidelineStateContext::cartesian ( ) const

True/false if coordinates are cartesian/polar.

Definition at line 111 of file GuidelineStateContext.cpp.

112{
113 return m_guidelines.coordsType () == COORDS_TYPE_CARTESIAN;
114}
@ COORDS_TYPE_CARTESIAN
Definition CoordsType.h:13

◆ color()

ColorPalette GuidelineStateContext::color ( ) const

Color to be used for guidelines.

Definition at line 116 of file GuidelineStateContext.cpp.

117{
118 return m_guidelines.color ();
119}

◆ convertGraphCoordinateToScreenPoint()

QPointF GuidelineStateContext::convertGraphCoordinateToScreenPoint ( double valueGraph) const

Convert single graph coordinate into screen point pair.

Definition at line 121 of file GuidelineStateContext.cpp.

122{
123 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
124
125 return m_states[m_currentState]->convertGraphCoordinateToScreenPoint (valueGraph);
126}

◆ convertScreenPointToGraphCoordinate()

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

Convert screen point pair into single graph coordinate.

Definition at line 128 of file GuidelineStateContext.cpp.

129{
130 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
131
132 return m_states[m_currentState]->convertScreenPointToGraphCoordinate (posScreen);
133}

◆ createGuideline()

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

Factory method for creating a new Guideline.

Definition at line 135 of file GuidelineStateContext.cpp.

137{
138 return m_guidelines.createGuideline (identifier,
139 stateInitial);
140}

◆ 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 142 of file GuidelineStateContext.cpp.

143{
144 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
145
146 return m_states[m_currentState]->doPaint ();
147}

◆ draggedOffScreen()

void GuidelineStateContext::draggedOffScreen ( )

Guideline has been dragged off screen so remove it.

Definition at line 149 of file GuidelineStateContext.cpp.

150{
152 transitionIfRequested ();
153}
void requestStateTransition(GuidelineState guidelineState)
Request a state transition.

◆ guideline()

GuidelineAbstract & GuidelineStateContext::guideline ( )

Guideline that owns this context class.

Definition at line 155 of file GuidelineStateContext.cpp.

156{
157 return m_guideline;
158}

◆ handleActiveChange()

void GuidelineStateContext::handleActiveChange ( bool active)

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

Definition at line 160 of file GuidelineStateContext.cpp.

161{
162 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
163
164 m_states[m_currentState]->handleActiveChange (active);
165 transitionIfRequested ();
166}

◆ handleGuidelineMode()

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

User toggled Guideline visibility and/or locked mode.

Definition at line 199 of file GuidelineStateContext.cpp.

201{
202 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
203
204 m_states[m_currentState]->handleGuidelineMode (visible,
205 locked);
206 transitionIfRequested ();
207}

◆ handleHoverEnterEvent()

void GuidelineStateContext::handleHoverEnterEvent ( )

If transparent then make visible when hover starts.

Definition at line 167 of file GuidelineStateContext.cpp.

168{
169 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
170
171 m_states[m_currentState]->handleHoverEnterEvent ();
172 transitionIfRequested ();
173}

◆ handleHoverLeaveEvent()

void GuidelineStateContext::handleHoverLeaveEvent ( )

If previously transparent before hover enter then make transparent again.

Definition at line 175 of file GuidelineStateContext.cpp.

176{
177 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
178
179 m_states[m_currentState]->handleHoverLeaveEvent ();
180 transitionIfRequested ();
181}

◆ 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 183 of file GuidelineStateContext.cpp.

184{
185 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
186
187 m_states[m_currentState]->handleMousePress (posScene);
188 transitionIfRequested ();
189}

◆ 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 191 of file GuidelineStateContext.cpp.

192{
193 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
194
195 m_states[m_currentState]->handleMouseRelease (posScene);
196 transitionIfRequested ();
197}

◆ modelGuideline()

DocumentModelGuideline GuidelineStateContext::modelGuideline ( ) const

Up-to-date guideline settings.

Definition at line 209 of file GuidelineStateContext.cpp.

210{
211 return m_mainWindow.cmdMediator ()->document ().modelGuideline ();
212}

◆ pointToEllipse()

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

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

Definition at line 214 of file GuidelineStateContext.cpp.

215{
216 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
217
218 return m_states[m_currentState]->pointToEllipse (posScreen);
219}

◆ pointToLine()

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

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

Definition at line 221 of file GuidelineStateContext.cpp.

222{
223 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
224
225 return m_states[m_currentState]->pointToLine (posScreen);
226}

◆ posCursorGraph()

QPointF GuidelineStateContext::posCursorGraph ( ) const

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

Definition at line 228 of file GuidelineStateContext.cpp.

229{
230 return m_posCursorGraph;
231}

◆ requestStateTransition()

void GuidelineStateContext::requestStateTransition ( GuidelineState guidelineState)

Request a state transition.

Definition at line 233 of file GuidelineStateContext.cpp.

234{
235 ENGAUGE_ASSERT (guidelineState != NUM_GUIDELINE_STATES);
236
237 m_nextState = guidelineState;
238}

◆ 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 240 of file GuidelineStateContext.cpp.

241{
242 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
243
244 m_posCursorGraph = posGraph;
245}

◆ slotTimeout

void GuidelineStateContext::slotTimeout ( )
slot

Definition at line 247 of file GuidelineStateContext.cpp.

248{
249 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
250
251 m_states[m_currentState]->handleTimeout ();
252 transitionIfRequested ();
253}

◆ stateDump()

QString GuidelineStateContext::stateDump ( ) const

Dump state for debugging only.

Definition at line 255 of file GuidelineStateContext.cpp.

256{
257 return m_guidelines.stateDump ();
258}

◆ stateName()

QString GuidelineStateContext::stateName ( ) const

State as a string for debugging only.

Definition at line 260 of file GuidelineStateContext.cpp.

261{
262 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
263
264 return m_states[m_currentState]->stateName();
265}

◆ transformation()

Transformation GuidelineStateContext::transformation ( ) const

Return copy of transformation owned by MainWindow.

Definition at line 267 of file GuidelineStateContext.cpp.

268{
269 return m_guidelines.transformation ();
270}

◆ updateWithLatestTransformation()

void GuidelineStateContext::updateWithLatestTransformation ( )

Update given Transformation in GuidelineStateContext.

Definition at line 288 of file GuidelineStateContext.cpp.

289{
290 ENGAUGE_ASSERT (m_currentState != NUM_GUIDELINE_STATES);
291
292 m_states[m_currentState]->updateWithLatestTransformation();
293 transitionIfRequested ();
294}

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