Engauge Digitizer  2
TutorialStateContext.cpp
Go to the documentation of this file.
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "EngaugeAssert.h"
8 #include "Logger.h"
9 #include <QTimer>
10 #include "TutorialDlg.h"
16 #include "TutorialStateContext.h"
18 #include "TutorialStateCurveType.h"
22 
23 const int TIMER_INTERVAL = 1;
24 
26  m_tutorialDlg (tutorialDlg)
27 {
28  createStates ();
29  createTimer ();
30 }
31 
33 {
34  qDeleteAll (m_states);
35 }
36 
37 void TutorialStateContext::createStates ()
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createStates";
40 
41  // These states follow the same order as the TutorialState enumeration
42  m_states.insert (TUTORIAL_STATE_AXIS_POINTS , new TutorialStateAxisPoints (*this));
45  m_states.insert (TUTORIAL_STATE_COLOR_FILTER , new TutorialStateColorFilter (*this));
46  m_states.insert (TUTORIAL_STATE_CURVE_SELECTION , new TutorialStateCurveSelection (*this));
47  m_states.insert (TUTORIAL_STATE_CURVE_TYPE , new TutorialStateCurveType (*this));
48  m_states.insert (TUTORIAL_STATE_INTRODUCTION , new TutorialStateIntroduction (*this));
49  m_states.insert (TUTORIAL_STATE_POINT_MATCH , new TutorialStatePointMatch (*this));
50  m_states.insert (TUTORIAL_STATE_SEGMENT_FILL , new TutorialStateSegmentFill (*this));
51  ENGAUGE_ASSERT (m_states.size () == NUM_TUTORIAL_STATES);
52 
53  m_currentState = NUM_TUTORIAL_STATES; // Value that forces a transition right away;
55  completeRequestedStateTransitionIfExists ();
56 }
57 
58 void TutorialStateContext::createTimer ()
59 {
60  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::createTimer";
61 
62  m_timer = new QTimer ();
63  m_timer->setInterval (TIMER_INTERVAL);
64  m_timer->setSingleShot (true);
65  connect (m_timer, SIGNAL (timeout ()), this, SLOT (slotTimeout ()));
66 }
67 
68 void TutorialStateContext::completeRequestedStateTransitionIfExists ()
69 {
70  if (m_currentState != m_requestedState) {
71 
72  // A transition is waiting so perform it
73 
74  if (m_currentState != NUM_TUTORIAL_STATES) {
75 
76  // This is not the first state so close the previous state
77  m_states [m_currentState]->end ();
78  }
79 
80  // Start the new state
81  m_currentState = m_requestedState;
82  m_states [m_requestedState]->begin ();
83  }
84 }
85 
87 {
88  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestDelayedStateTransition";
89 
90  m_requestedState = tutorialState;
91 
92  m_timer->start ();
93 }
94 
96 {
97  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::requestImmediateStateTransition";
98 
99  m_requestedState = tutorialState;
100 }
101 
102 void TutorialStateContext::slotTimeout()
103 {
104  LOG4CPP_INFO_S ((*mainCat)) << "TutorialStateContext::slotTimeout";
105 
106  completeRequestedStateTransitionIfExists();
107 }
108 
110 {
111  return m_tutorialDlg;
112 }
Point match panel discusses the matching of points in curves without lines.
Curve type state/panel lets user select the curve type (lines or points)
void requestImmediateStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Checklist wizard panel for lines discusses the checklist wizard, and returns to TRANSITION_STATE_SEGM...
Color filter panel discusses the curve-specific color filtering.
Axis points panel discusses axis point digitization.
Tutorial using a strategy like a comic strip with decision points deciding which panels appear.
Definition: TutorialDlg.h:19
Curve selection panel discusses how to select a curve, and perform setup on the selected curve.
TutorialStateContext(TutorialDlg &tutorialDlg)
Single constructor.
Checklist wizard panel for points discusses the checklist wizard, and returns to TRANSITION_STATE_POI...
Segment fill panel discusses the digitization of points along curve lines.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const int TIMER_INTERVAL
Introduction state/panel is the first panel the user sees.
void requestDelayedStateTransition(TutorialState tutorialState)
Request a transition to the specified state from the current state.
TutorialDlg & tutorialDlg()
Access to tutorial dialogs and its scene.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20
~TutorialStateContext()
Destructor deallocates memory.