Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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. More...
 
virtual ~DigitizeStateContext ()
 
QString activeCurve () const
 Curve name for active Curve. This can include AXIS_CURVE_NAME, and empty string. More...
 
void appendNewCmd (CmdMediator *cmdMediator, QUndoCommand *cmd)
 Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subclasses. More...
 
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. More...
 
void handleContextMenuEventAxis (CmdMediator *cmdMediator, const QString &pointIdentifier)
 See DigitizeStateAbstractBase::handleContextMenuEventAxis. More...
 
void handleContextMenuEventGraph (CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
 See DigitizeStateAbstractBase::handleContextMenuEventGraph. More...
 
void handleCurveChange (CmdMediator *cmdMediator)
 See DigitizeStateAbstractBase::handleCurveChange. More...
 
void handleKeyPress (CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
 See DigitizeStateAbstractBase::handleKeyPress. More...
 
void handleMouseMove (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMouseMove. More...
 
void handleMousePress (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMousePress. More...
 
void handleMouseRelease (CmdMediator *cmdMediator, QPointF pos)
 See DigitizeStateAbstractBase::handleMouseRelease. More...
 
bool isGnuplot () const
 Get method for gnuplot flag. More...
 
MainWindowmainWindow ()
 Reference to the MainWindow, without const. More...
 
const MainWindowmainWindow () const
 Reference to the MainWindow, with const. More...
 
void requestDelayedStateTransition (DigitizeState digitizeState)
 Initiate state transition to be performed later, when DigitizeState is off the stack. More...
 
void requestImmediateStateTransition (CmdMediator *cmdMediator, DigitizeState digitizeState)
 Perform immediate state transition. Called from outside state machine. More...
 
void resetOnLoad (CmdMediator *cmdMediator)
 Resetting makes re-initializes for documents after the first. More...
 
void setCursor (CmdMediator *cmdMediator)
 Set cursor after asking state for the new cursor shape. More...
 
void setDragMode (QGraphicsView::DragMode dragMode)
 Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses. More...
 
void setImageIsLoaded (CmdMediator *cmdMediator, bool imageIsLoaded)
 Set the image so QGraphicsView cursor and drag mode are accessible. More...
 
QString state () const
 State name for debugging. More...
 
void updateAfterPointAddition ()
 Update the graphics attributes. More...
 
void updateModelDigitizeCurve (CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
 Update the digitize curve settings. More...
 
void updateModelSegments (const DocumentModelSegments &modelSegments)
 Update the segments given the new settings. More...
 
QGraphicsView & view ()
 QGraphicsView for use by DigitizeStateAbstractBase subclasses. More...
 

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 ( 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 }
Digitizing state for creating the scale bar.
Digitizing state for selecting a color for DigitizeStateSegment.
Digitizing state before a Document has been created. In this state, the cursor is Qt::ArrowCursor...
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:350
Digitizing state for matching Curve Points, one at a time.
Digitizing state for selecting one or more Points in the Document.
bool isGnuplot() const
Get method for gnuplot flag.
Digitizing state for creating Curve Points, one at a time.
QGraphicsView & view()
QGraphicsView for use by DigitizeStateAbstractBase subclasses.
Digitizing state for creating multiple Points along a highlighted segment.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
Digitizing state for digitizing one axis point at a time.
void requestImmediateStateTransition(CmdMediator *cmdMediator, DigitizeState digitizeState)
Perform immediate state transition. Called from outside state machine.
DigitizeStateContext::~DigitizeStateContext ( )
virtual

Definition at line 54 of file DigitizeStateContext.cpp.

55 {
56  qDeleteAll (m_states);
57 }

Member Function Documentation

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 }
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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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 }
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,
107  pointIdentifier);
108 }
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,
114  pointIdentifiers);
115 }
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 }
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,
128  atLeastOneSelectedItem);
129 
130  completeRequestedStateTransitionIfExists(cmdMediator);
131 
132 }
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 }
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 }
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 }
bool DigitizeStateContext::isGnuplot ( ) const

Get method for gnuplot flag.

Definition at line 163 of file DigitizeStateContext.cpp.

164 {
165  return m_isGnuplot;
166 }
MainWindow & DigitizeStateContext::mainWindow ( )

Reference to the MainWindow, without const.

Definition at line 168 of file DigitizeStateContext.cpp.

169 {
170  return m_mainWindow;
171 }
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 }
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 }
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 }
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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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 }
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20
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.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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 }
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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 }
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) &amp;&amp; !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
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: