Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateContext Class Reference

Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a standard state machine implementation. More...

#include <DigitizeStateContext.h>

Inheritance diagram for DigitizeStateContext:
Inheritance graph
Collaboration diagram for DigitizeStateContext:
Collaboration graph

Public Member Functions

 DigitizeStateContext (MainWindow &mainWindow, QGraphicsView &view, bool isGnuplot)
 Single constructor.
virtual ~DigitizeStateContext ()
QString activeCurve () const
 Curve name for active Curve. This can include AXIS_CURVE_NAME, and empty string.
void appendNewCmd (CmdMediator *cmdMediator, QUndoCommand *cmd)
 Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subclasses.
bool canPaste (const Transformation &transformation, const QSize &viewSize) const
 Return true if there is good data in the clipboard for pasting, and that operation is compatible with the current state.
bool guidelinesAreSelectable () const
 Enable/disable guidelines according to state.
void handleContextMenuEventAxis (CmdMediator *cmdMediator, const QString &pointIdentifier)
 See DigitizeStateAbstractBase::handleContextMenuEventAxis.
void handleContextMenuEventGraph (CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
 See DigitizeStateAbstractBase::handleContextMenuEventGraph.
void handleCurveChange (CmdMediator *cmdMediator)
 See DigitizeStateAbstractBase::handleCurveChange.
void handleKeyPress (CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
 See DigitizeStateAbstractBase::handleKeyPress.
void handleMouseMove (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMouseMove.
void handleMousePress (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMousePress.
void handleMouseRelease (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMouseRelease.
bool isGnuplot () const
 Get method for gnuplot flag.
MainWindowmainWindow ()
 Reference to the MainWindow, without const.
const MainWindowmainWindow () const
 Reference to the MainWindow, with const.
void requestDelayedStateTransition (DigitizeState digitizeState)
 Initiate state transition to be performed later, when DigitizeState is off the stack.
void requestImmediateStateTransition (CmdMediator *cmdMediator, DigitizeState digitizeState)
 Perform immediate state transition. Called from outside state machine.
void resetOnLoad (CmdMediator *cmdMediator)
 Resetting makes re-initializes for documents after the first.
void setCursor (CmdMediator *cmdMediator)
 Set cursor after asking state for the new cursor shape.
void setDragMode (QGraphicsView::DragMode dragMode)
 Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void setImageIsLoaded (CmdMediator *cmdMediator, bool imageIsLoaded)
 Set the image so QGraphicsView cursor and drag mode are accessible.
QString state () const
 State name for debugging.
void updateAfterPointAddition ()
 Update the graphics attributes.
void updateModelDigitizeCurve (CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
 Update the digitize curve settings.
void updateModelSegments (const DocumentModelSegments &modelSegments)
 Update the segments given the new settings.
QGraphicsView & view ()
 QGraphicsView for use by DigitizeStateAbstractBase subclasses.

Friends

class MainWindow
 For CmdAbstract constructor only, via MainWindow, we offer the state to friend class MainWindow.

Detailed Description

Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a standard state machine implementation.

Definition at line 27 of file DigitizeStateContext.h.

Constructor & Destructor Documentation

◆ DigitizeStateContext()

DigitizeStateContext::DigitizeStateContext ( MainWindow & mainWindow,
QGraphicsView & view,
bool isGnuplot )

Single constructor.

Definition at line 31 of file DigitizeStateContext.cpp.

33 :
34 m_mainWindow (mainWindow),
35 m_view (view),
36 m_imageIsLoaded (false),
37 m_isGnuplot (isGnuplot)
38{
39 // These states follow the same order as the DigitizeState enumeration
40 m_states.insert (DIGITIZE_STATE_AXIS , new DigitizeStateAxis (*this));
41 m_states.insert (DIGITIZE_STATE_COLOR_PICKER, new DigitizeStateColorPicker (*this));
42 m_states.insert (DIGITIZE_STATE_CURVE , new DigitizeStateCurve (*this));
43 m_states.insert (DIGITIZE_STATE_EMPTY , new DigitizeStateEmpty (*this));
44 m_states.insert (DIGITIZE_STATE_POINT_MATCH , new DigitizeStatePointMatch (*this));
45 m_states.insert (DIGITIZE_STATE_SEGMENT , new DigitizeStateSegment (*this));
46 m_states.insert (DIGITIZE_STATE_SELECT , new DigitizeStateSelect (*this));
47 m_states.insert (DIGITIZE_STATE_SCALE , new DigitizeStateScale (*this)); // Out of order since added later
48 m_states.insert (DIGITIZE_STATE_GUIDELINE , new DigitizeStateGuideline (*this)); // Out of order since added later
49 ENGAUGE_ASSERT (m_states.size () == NUM_DIGITIZE_STATES);
50
51 m_currentState = NUM_DIGITIZE_STATES; // Value that forces a transition right away
54}
@ DIGITIZE_STATE_POINT_MATCH
@ DIGITIZE_STATE_SELECT
@ DIGITIZE_STATE_COLOR_PICKER
@ DIGITIZE_STATE_GUIDELINE
@ NUM_DIGITIZE_STATES
@ DIGITIZE_STATE_CURVE
@ DIGITIZE_STATE_SCALE
@ DIGITIZE_STATE_SEGMENT
@ DIGITIZE_STATE_AXIS
@ DIGITIZE_STATE_EMPTY
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
bool isGnuplot() const
Get method for gnuplot flag.
void requestImmediateStateTransition(CmdMediator *cmdMediator, DigitizeState digitizeState)
Perform immediate state transition. Called from outside state machine.
QGraphicsView & view()
QGraphicsView for use by DigitizeStateAbstractBase subclasses.
MainWindow & mainWindow()
Reference to the MainWindow, without const.

◆ ~DigitizeStateContext()

DigitizeStateContext::~DigitizeStateContext ( )
virtual

Definition at line 56 of file DigitizeStateContext.cpp.

57{
58 qDeleteAll (m_states);
59}

Member Function Documentation

◆ activeCurve()

QString DigitizeStateContext::activeCurve ( ) const

Curve name for active Curve. This can include AXIS_CURVE_NAME, and empty string.

Definition at line 61 of file DigitizeStateContext.cpp.

62{
63 return m_states [m_currentState]->activeCurve ();
64}

◆ appendNewCmd()

void DigitizeStateContext::appendNewCmd ( CmdMediator * cmdMediator,
QUndoCommand * cmd )

Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subclasses.

Definition at line 66 of file DigitizeStateContext.cpp.

68{
69 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::appendNewCmd";
70
71 cmdMediator->push (cmd);
72}
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ canPaste()

bool DigitizeStateContext::canPaste ( const Transformation & transformation,
const QSize & viewSize ) const

Return true if there is good data in the clipboard for pasting, and that operation is compatible with the current state.

Definition at line 74 of file DigitizeStateContext.cpp.

76{
77 return m_states [m_currentState]->canPaste (transformation,
78 size);
79}

◆ guidelinesAreSelectable()

bool DigitizeStateContext::guidelinesAreSelectable ( ) const

Enable/disable guidelines according to state.

Definition at line 110 of file DigitizeStateContext.cpp.

111{
112 return m_states [m_currentState]->guidelinesAreSelectable();
113}

◆ handleContextMenuEventAxis()

void DigitizeStateContext::handleContextMenuEventAxis ( CmdMediator * cmdMediator,
const QString & pointIdentifier )

See DigitizeStateAbstractBase::handleContextMenuEventAxis.

Definition at line 115 of file DigitizeStateContext.cpp.

117{
118 m_states [m_currentState]->handleContextMenuEventAxis (cmdMediator,
119 pointIdentifier);
120}

◆ handleContextMenuEventGraph()

void DigitizeStateContext::handleContextMenuEventGraph ( CmdMediator * cmdMediator,
const QStringList & pointIdentifiers )

See DigitizeStateAbstractBase::handleContextMenuEventGraph.

Definition at line 122 of file DigitizeStateContext.cpp.

124{
125 m_states [m_currentState]->handleContextMenuEventGraph (cmdMediator,
126 pointIdentifiers);
127}

◆ handleCurveChange()

void DigitizeStateContext::handleCurveChange ( CmdMediator * cmdMediator)

See DigitizeStateAbstractBase::handleCurveChange.

Definition at line 129 of file DigitizeStateContext.cpp.

130{
131 m_states [m_currentState]->handleCurveChange(cmdMediator);
132}

◆ handleKeyPress()

void DigitizeStateContext::handleKeyPress ( CmdMediator * cmdMediator,
Qt::Key key,
bool atLeastOneSelectedItem )

See DigitizeStateAbstractBase::handleKeyPress.

Definition at line 134 of file DigitizeStateContext.cpp.

137{
138 m_states [m_currentState]->handleKeyPress (cmdMediator,
139 key,
140 atLeastOneSelectedItem);
141
142 completeRequestedStateTransitionIfExists(cmdMediator);
143
144}

◆ handleMouseMove()

void DigitizeStateContext::handleMouseMove ( CmdMediator * cmdMediator,
QPointF pos )

See DigitizeStateAbstractBase::handleMouseMove.

Definition at line 146 of file DigitizeStateContext.cpp.

148{
149 m_states [m_currentState]->handleMouseMove (cmdMediator,
150 pos);
151
152 completeRequestedStateTransitionIfExists(cmdMediator);
153
154}

◆ handleMousePress()

void DigitizeStateContext::handleMousePress ( CmdMediator * cmdMediator,
QPointF pos )

See DigitizeStateAbstractBase::handleMousePress.

Definition at line 156 of file DigitizeStateContext.cpp.

158{
159 m_states [m_currentState]->handleMousePress (cmdMediator,
160 pos);
161
162 completeRequestedStateTransitionIfExists(cmdMediator);
163
164}

◆ handleMouseRelease()

void DigitizeStateContext::handleMouseRelease ( CmdMediator * cmdMediator,
QPointF pos )

See DigitizeStateAbstractBase::handleMouseRelease.

Definition at line 166 of file DigitizeStateContext.cpp.

168{
169 m_states [m_currentState]->handleMouseRelease (cmdMediator,
170 pos);
171
172 completeRequestedStateTransitionIfExists(cmdMediator);
173}

◆ isGnuplot()

bool DigitizeStateContext::isGnuplot ( ) const

Get method for gnuplot flag.

Definition at line 175 of file DigitizeStateContext.cpp.

176{
177 return m_isGnuplot;
178}

◆ mainWindow() [1/2]

MainWindow & DigitizeStateContext::mainWindow ( )

Reference to the MainWindow, without const.

Definition at line 180 of file DigitizeStateContext.cpp.

181{
182 return m_mainWindow;
183}

◆ mainWindow() [2/2]

const MainWindow & DigitizeStateContext::mainWindow ( ) const

Reference to the MainWindow, with const.

Definition at line 185 of file DigitizeStateContext.cpp.

186{
187 return m_mainWindow;
188}

◆ requestDelayedStateTransition()

void DigitizeStateContext::requestDelayedStateTransition ( DigitizeState digitizeState)

Initiate state transition to be performed later, when DigitizeState is off the stack.

Definition at line 190 of file DigitizeStateContext.cpp.

191{
192 m_requestedState = digitizeState;
193}

◆ requestImmediateStateTransition()

void DigitizeStateContext::requestImmediateStateTransition ( CmdMediator * cmdMediator,
DigitizeState digitizeState )

Perform immediate state transition. Called from outside state machine.

Definition at line 195 of file DigitizeStateContext.cpp.

197{
198 m_requestedState = digitizeState;
199 completeRequestedStateTransitionIfExists(cmdMediator);
200}

◆ resetOnLoad()

void DigitizeStateContext::resetOnLoad ( CmdMediator * cmdMediator)

Resetting makes re-initializes for documents after the first.

Definition at line 202 of file DigitizeStateContext.cpp.

203{
204 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::resetOnLoad";
205
206 // Reset current state. At this point, the current state is DIGITIZE_STATE_EMPTY when opening the first document
207 // so for consistency we always reset it so succeeding documents work the same way
208 if (m_currentState != DIGITIZE_STATE_EMPTY) {
209 m_requestedState = DIGITIZE_STATE_EMPTY;
210 completeRequestedStateTransitionIfExists(cmdMediator);
211 }
212}

◆ setCursor()

void DigitizeStateContext::setCursor ( CmdMediator * cmdMediator)

Set cursor after asking state for the new cursor shape.

Definition at line 214 of file DigitizeStateContext.cpp.

215{
216 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::setCursor";
217
218 ENGAUGE_ASSERT(m_currentState < m_states.count());
219
220 m_states [m_currentState]->setCursor (cmdMediator);
221}

◆ setDragMode()

void DigitizeStateContext::setDragMode ( QGraphicsView::DragMode dragMode)

Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.

Definition at line 223 of file DigitizeStateContext.cpp.

224{
225 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateContext::setDragMode";
226
227 if (m_imageIsLoaded) {
228 m_view.setDragMode (dragMode);
229 }
230}
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ setImageIsLoaded()

void DigitizeStateContext::setImageIsLoaded ( CmdMediator * cmdMediator,
bool imageIsLoaded )

Set the image so QGraphicsView cursor and drag mode are accessible.

Definition at line 232 of file DigitizeStateContext.cpp.

234{
235 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::setImageIsLoaded";
236
237 m_imageIsLoaded = imageIsLoaded;
238 setCursor (cmdMediator);
239}
void setCursor(CmdMediator *cmdMediator)
Set cursor after asking state for the new cursor shape.

◆ state()

QString DigitizeStateContext::state ( ) const

State name for debugging.

Definition at line 241 of file DigitizeStateContext.cpp.

242{
243 ENGAUGE_ASSERT (m_currentState != NUM_DIGITIZE_STATES);
244
245 return m_states [m_currentState]->state();
246}

◆ updateAfterPointAddition()

void DigitizeStateContext::updateAfterPointAddition ( )

Update the graphics attributes.

Definition at line 248 of file DigitizeStateContext.cpp.

249{
250 ENGAUGE_ASSERT (m_currentState != NUM_DIGITIZE_STATES);
251
252 m_states [m_currentState]->updateAfterPointAddition ();
253}

◆ updateModelDigitizeCurve()

void DigitizeStateContext::updateModelDigitizeCurve ( CmdMediator * cmdMediator,
const DocumentModelDigitizeCurve & modelDigitizeCurve )

Update the digitize curve settings.

Definition at line 255 of file DigitizeStateContext.cpp.

257{
258 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::updateModelDigitizeCurve";
259
260 ENGAUGE_ASSERT(m_currentState < m_states.count());
261
262 m_states [m_currentState]->updateModelDigitizeCurve (cmdMediator,
263 modelDigitizeCurve);
264}

◆ updateModelSegments()

void DigitizeStateContext::updateModelSegments ( const DocumentModelSegments & modelSegments)

Update the segments given the new settings.

Definition at line 266 of file DigitizeStateContext.cpp.

267{
268 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::updateModelSegments";
269
270 ENGAUGE_ASSERT(m_currentState < m_states.count());
271
272 m_states [m_currentState]->updateModelSegments (modelSegments);
273}

◆ view()

QGraphicsView & DigitizeStateContext::view ( )

QGraphicsView for use by DigitizeStateAbstractBase subclasses.

Definition at line 275 of file DigitizeStateContext.cpp.

276{
277 return m_view;
278}

◆ MainWindow

friend class MainWindow
friend

For CmdAbstract constructor only, via MainWindow, we offer the state to friend class MainWindow.

Definition at line 131 of file DigitizeStateContext.h.


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