Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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.
 
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.
 

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 30 of file DigitizeStateContext.cpp.

32 :
33 m_mainWindow (mainWindow),
34 m_view (view),
35 m_imageIsLoaded (false),
36 m_isGnuplot (isGnuplot)
37{
38 // These states follow the same order as the DigitizeState enumeration
39 m_states.insert (DIGITIZE_STATE_AXIS , new DigitizeStateAxis (*this));
40 m_states.insert (DIGITIZE_STATE_COLOR_PICKER, new DigitizeStateColorPicker (*this));
41 m_states.insert (DIGITIZE_STATE_CURVE , new DigitizeStateCurve (*this));
42 m_states.insert (DIGITIZE_STATE_EMPTY , new DigitizeStateEmpty (*this));
43 m_states.insert (DIGITIZE_STATE_POINT_MATCH , new DigitizeStatePointMatch (*this));
44 m_states.insert (DIGITIZE_STATE_SEGMENT , new DigitizeStateSegment (*this));
45 m_states.insert (DIGITIZE_STATE_SELECT , new DigitizeStateSelect (*this));
46 m_states.insert (DIGITIZE_STATE_SCALE , new DigitizeStateScale (*this)); // Out of order since added later
47 ENGAUGE_ASSERT (m_states.size () == NUM_DIGITIZE_STATES);
48
49 m_currentState = NUM_DIGITIZE_STATES; // Value that forces a transition right away
52}
@ DIGITIZE_STATE_POINT_MATCH
@ DIGITIZE_STATE_SELECT
@ DIGITIZE_STATE_COLOR_PICKER
@ DIGITIZE_STATE_SEGMENT
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Digitizing state for digitizing one axis point at a time.
Digitizing state for selecting a color for DigitizeStateSegment.
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.
Digitizing state for creating Curve Points, one at a time.
Digitizing state before a Document has been created. In this state, the cursor is Qt::ArrowCursor.
Digitizing state for matching Curve Points, one at a time.
Digitizing state for creating the scale bar.
Digitizing state for creating multiple Points along a highlighted segment.
Digitizing state for selecting one or more Points in the Document.
CmdMediator * cmdMediator()
Accessor for commands to process the Document.

◆ ~DigitizeStateContext()

DigitizeStateContext::~DigitizeStateContext ( )
virtual

Definition at line 54 of file DigitizeStateContext.cpp.

55{
56 qDeleteAll (m_states);
57}
const int INNER_RADIUS_MIN

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 59 of file DigitizeStateContext.cpp.

60{
61 return m_states [m_currentState]->activeCurve ();
62}

◆ appendNewCmd()

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

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

Definition at line 64 of file DigitizeStateContext.cpp.

66{
67 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::appendNewCmd";
68
69 cmdMediator->push (cmd);
70}
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 72 of file DigitizeStateContext.cpp.

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

◆ handleContextMenuEventAxis()

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

See DigitizeStateAbstractBase::handleContextMenuEventAxis.

Definition at line 103 of file DigitizeStateContext.cpp.

105{
106 m_states [m_currentState]->handleContextMenuEventAxis (cmdMediator,
108}

◆ handleContextMenuEventGraph()

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

See DigitizeStateAbstractBase::handleContextMenuEventGraph.

Definition at line 110 of file DigitizeStateContext.cpp.

112{
113 m_states [m_currentState]->handleContextMenuEventGraph (cmdMediator,
115}

◆ handleCurveChange()

void DigitizeStateContext::handleCurveChange ( CmdMediator * cmdMediator)

See DigitizeStateAbstractBase::handleCurveChange.

Definition at line 117 of file DigitizeStateContext.cpp.

118{
119 m_states [m_currentState]->handleCurveChange(cmdMediator);
120}

◆ handleKeyPress()

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

See DigitizeStateAbstractBase::handleKeyPress.

Definition at line 122 of file DigitizeStateContext.cpp.

125{
126 m_states [m_currentState]->handleKeyPress (cmdMediator,
127 key,
129
130 completeRequestedStateTransitionIfExists(cmdMediator);
131
132}

◆ handleMouseMove()

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

See DigitizeStateAbstractBase::handleMouseMove.

Definition at line 134 of file DigitizeStateContext.cpp.

136{
137 m_states [m_currentState]->handleMouseMove (cmdMediator,
138 pos);
139
140 completeRequestedStateTransitionIfExists(cmdMediator);
141
142}

◆ handleMousePress()

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

See DigitizeStateAbstractBase::handleMousePress.

Definition at line 144 of file DigitizeStateContext.cpp.

146{
147 m_states [m_currentState]->handleMousePress (cmdMediator,
148 pos);
149
150 completeRequestedStateTransitionIfExists(cmdMediator);
151
152}

◆ handleMouseRelease()

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

See DigitizeStateAbstractBase::handleMouseRelease.

Definition at line 154 of file DigitizeStateContext.cpp.

156{
157 m_states [m_currentState]->handleMouseRelease (cmdMediator,
158 pos);
159
160 completeRequestedStateTransitionIfExists(cmdMediator);
161}

◆ isGnuplot()

bool DigitizeStateContext::isGnuplot ( ) const

Get method for gnuplot flag.

Definition at line 163 of file DigitizeStateContext.cpp.

164{
165 return m_isGnuplot;
166}

◆ mainWindow() [1/2]

MainWindow & DigitizeStateContext::mainWindow ( )

Reference to the MainWindow, without const.

Definition at line 168 of file DigitizeStateContext.cpp.

169{
170 return m_mainWindow;
171}

◆ mainWindow() [2/2]

const MainWindow & DigitizeStateContext::mainWindow ( ) const

Reference to the MainWindow, with const.

Definition at line 173 of file DigitizeStateContext.cpp.

174{
175 return m_mainWindow;
176}

◆ requestDelayedStateTransition()

void DigitizeStateContext::requestDelayedStateTransition ( DigitizeState digitizeState)

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

Definition at line 178 of file DigitizeStateContext.cpp.

179{
180 m_requestedState = digitizeState;
181}

◆ requestImmediateStateTransition()

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

Perform immediate state transition. Called from outside state machine.

Definition at line 183 of file DigitizeStateContext.cpp.

185{
186 m_requestedState = digitizeState;
187 completeRequestedStateTransitionIfExists(cmdMediator);
188}

◆ resetOnLoad()

void DigitizeStateContext::resetOnLoad ( CmdMediator * cmdMediator)

Resetting makes re-initializes for documents after the first.

Definition at line 190 of file DigitizeStateContext.cpp.

191{
192 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::resetOnLoad";
193
194 // Reset current state. At this point, the current state is DIGITIZE_STATE_EMPTY when opening the first document
195 // so for consistency we always reset it so succeeding documents work the same way
196 if (m_currentState != DIGITIZE_STATE_EMPTY) {
197 m_requestedState = DIGITIZE_STATE_EMPTY;
198 completeRequestedStateTransitionIfExists(cmdMediator);
199 }
200}

◆ setCursor()

void DigitizeStateContext::setCursor ( CmdMediator * cmdMediator)

Set cursor after asking state for the new cursor shape.

Definition at line 202 of file DigitizeStateContext.cpp.

203{
204 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::setCursor";
205
206 ENGAUGE_ASSERT(m_currentState < m_states.count());
207
208 m_states [m_currentState]->setCursor (cmdMediator);
209}

◆ setDragMode()

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

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

Definition at line 211 of file DigitizeStateContext.cpp.

212{
213 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateContext::setDragMode";
214
215 if (m_imageIsLoaded) {
216 m_view.setDragMode (dragMode);
217 }
218}
#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 220 of file DigitizeStateContext.cpp.

222{
223 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::setImageIsLoaded";
224
225 m_imageIsLoaded = imageIsLoaded;
226 setCursor (cmdMediator);
227}
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 229 of file DigitizeStateContext.cpp.

230{
231 ENGAUGE_ASSERT (m_currentState != NUM_DIGITIZE_STATES);
232
233 return m_states [m_currentState]->state();
234}

◆ updateAfterPointAddition()

void DigitizeStateContext::updateAfterPointAddition ( )

Update the graphics attributes.

Definition at line 236 of file DigitizeStateContext.cpp.

237{
238 ENGAUGE_ASSERT (m_currentState != NUM_DIGITIZE_STATES);
239
240 m_states [m_currentState]->updateAfterPointAddition ();
241}

◆ updateModelDigitizeCurve()

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

Update the digitize curve settings.

Definition at line 243 of file DigitizeStateContext.cpp.

245{
246 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::updateModelDigitizeCurve";
247
248 ENGAUGE_ASSERT(m_currentState < m_states.count());
249
250 m_states [m_currentState]->updateModelDigitizeCurve (cmdMediator,
251 modelDigitizeCurve);
252}

◆ updateModelSegments()

void DigitizeStateContext::updateModelSegments ( const DocumentModelSegments & modelSegments)

Update the segments given the new settings.

Definition at line 254 of file DigitizeStateContext.cpp.

255{
256 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateContext::updateModelSegments";
257
258 ENGAUGE_ASSERT(m_currentState < m_states.count());
259
260 m_states [m_currentState]->updateModelSegments (modelSegments);
261}

◆ view()

QGraphicsView & DigitizeStateContext::view ( )

QGraphicsView for use by DigitizeStateAbstractBase subclasses.

Definition at line 263 of file DigitizeStateContext.cpp.

264{
265 return m_view;
266}

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