Engauge Digitizer  2
Public Member Functions | List of all members
BackgroundStateContext Class Reference

Context class that manages the background image state machine. More...

#include <BackgroundStateContext.h>

Collaboration diagram for BackgroundStateContext:
Collaboration graph

Public Member Functions

 BackgroundStateContext (MainWindow &mainWindow)
 Single constructor. More...
 
 ~BackgroundStateContext ()
 Destructor deallocates memory. More...
 
void close ()
 Open Document is being closed so remove the background. More...
 
void fitInView (GraphicsView &view)
 Zoom so background fills the window. More...
 
QImage imageForCurveState () const
 Image for the Curve state, even if the current state is different. More...
 
void requestStateTransition (BackgroundState backgroundState)
 Initiate state transition to be performed later, when BackgroundState is off the stack. More...
 
void setBackgroundImage (BackgroundImage backgroundImage)
 Transition to the specified state. This method is used by classes outside of the state machine to trigger transitions. More...
 
void setCurveSelected (bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QString &curveSelected)
 Update the selected curve. More...
 
void setPixmap (bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmapOriginal, const QString &curveSelected)
 Update the images of all states, rather than just the current state. More...
 
void updateColorFilter (bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
 Apply color filter settings. More...
 

Detailed Description

Context class that manages the background image state machine.

Overall strategy is that changing the currently selected curve should not affect the background image if the original image is being shown, or no image is being shown. However, if the curve-specific color filter image is being shown, then it should be replaced by the filtered image specific to the new curve.

Other considerations are that the processing should be robust in terms of ordering of the following incoming events:

  1. State transitions
  2. Setting of the background image
  3. Setting of the currently selected curve name

Definition at line 32 of file BackgroundStateContext.h.

Constructor & Destructor Documentation

◆ BackgroundStateContext()

BackgroundStateContext::BackgroundStateContext ( MainWindow mainWindow)

Single constructor.

Definition at line 21 of file BackgroundStateContext.cpp.

21  :
22  m_mainWindow (mainWindow)
23 {
24  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::BackgroundStateContext";
25 
26  // These states follow the same order as the BackgroundState enumeration
27  m_states.insert (BACKGROUND_STATE_CURVE , new BackgroundStateCurve (*this, mainWindow.scene()));
28  m_states.insert (BACKGROUND_STATE_NONE , new BackgroundStateNone (*this, mainWindow.scene()));
29  m_states.insert (BACKGROUND_STATE_ORIGINAL, new BackgroundStateOriginal (*this, mainWindow.scene()));
30  m_states.insert (BACKGROUND_STATE_UNLOADED, new BackgroundStateUnloaded (*this, mainWindow.scene()));
31  ENGAUGE_ASSERT (m_states.size () == NUM_BACKGROUND_STATES);
32 
33  m_currentState = NUM_BACKGROUND_STATES; // Value that forces a transition right away
35  completeRequestedStateTransitionIfExists();
36 }
Background image state for interval between startup and loading of the image.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Background image state for showing filter image from current curve.
void requestStateTransition(BackgroundState backgroundState)
Initiate state transition to be performed later, when BackgroundState is off the stack.
Background image state for showing no image.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Background image state for showing original (=unfiltered) image.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#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

◆ ~BackgroundStateContext()

BackgroundStateContext::~BackgroundStateContext ( )

Destructor deallocates memory.

Definition at line 38 of file BackgroundStateContext.cpp.

39 {
40  qDeleteAll (m_states);
41 }

Member Function Documentation

◆ close()

void BackgroundStateContext::close ( )

Open Document is being closed so remove the background.

Definition at line 43 of file BackgroundStateContext.cpp.

44 {
45  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::close";
46 
47  // It is safe to transition to the new state immediately since no BackgroundState classes are on the stack
49  completeRequestedStateTransitionIfExists ();
50 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void requestStateTransition(BackgroundState backgroundState)
Initiate state transition to be performed later, when BackgroundState is off the stack.
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ fitInView()

void BackgroundStateContext::fitInView ( GraphicsView view)

Zoom so background fills the window.

Definition at line 72 of file BackgroundStateContext.cpp.

73 {
74  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::fitInView";
75 
76  // After initialization, we should be in unloaded state or some other equally valid state
77  ENGAUGE_ASSERT (m_currentState != NUM_BACKGROUND_STATES);
78 
79  const QGraphicsPixmapItem *imageItem = &m_states [BACKGROUND_STATE_CURVE]->imageItem ();
80 
81  double width = imageItem->boundingRect().width();
82  double height = imageItem->boundingRect().height();
83 
84  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::fitInView"
85  << " state=" << m_states [m_currentState]->state ().toLatin1().data()
86  << " boundingRect=(" << width << "x" << height << ")";
87 
88  // Get the image from a state that is guaranteed to have an image
89  view.fitInView (imageItem);
90 
91 }
#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) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20

◆ imageForCurveState()

QImage BackgroundStateContext::imageForCurveState ( ) const

Image for the Curve state, even if the current state is different.

Definition at line 93 of file BackgroundStateContext.cpp.

94 {
95  return m_states [BACKGROUND_STATE_CURVE]->image();
96 }

◆ requestStateTransition()

void BackgroundStateContext::requestStateTransition ( BackgroundState  backgroundState)

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

Definition at line 98 of file BackgroundStateContext.cpp.

99 {
100  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::requestStateTransition";
101 
102  m_requestedState = backgroundState;
103 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ setBackgroundImage()

void BackgroundStateContext::setBackgroundImage ( BackgroundImage  backgroundImage)

Transition to the specified state. This method is used by classes outside of the state machine to trigger transitions.

Definition at line 105 of file BackgroundStateContext.cpp.

106 {
107  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::setBackgroundImage"
108  << " background=" << backgroundImageToString (backgroundImage).toLatin1().data();
109 
110  BackgroundState backgroundState= BACKGROUND_STATE_NONE;
111 
112  switch (backgroundImage) {
114  backgroundState = BACKGROUND_STATE_CURVE;
115  break;
116 
118  backgroundState = BACKGROUND_STATE_NONE;
119  break;
120 
122  backgroundState = BACKGROUND_STATE_ORIGINAL;
123  break;
124  }
125 
126  // It is safe to transition to the new state immediately since no BackgroundState classes are on the stack
127  requestStateTransition (backgroundState);
128  completeRequestedStateTransitionIfExists ();
129 }
BackgroundState
Set of possible states of background image.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void requestStateTransition(BackgroundState backgroundState)
Initiate state transition to be performed later, when BackgroundState is off the stack.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
QString backgroundImageToString(BackgroundImage backgroundImage)

◆ setCurveSelected()

void BackgroundStateContext::setCurveSelected ( bool  isGnuplot,
const Transformation transformation,
const DocumentModelGridRemoval modelGridRemoval,
const DocumentModelColorFilter modelColorFilter,
const QString &  curveSelected 
)

Update the selected curve.

Although this probably affects only the BACKGROUND_STATE_CURVE state, we will forward it to all states (consistent with setPixmap)

Definition at line 131 of file BackgroundStateContext.cpp.

136 {
137  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::setCurveSelected"
138  << " curve=" << curveSelected.toLatin1().data();
139 
140  for (int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
141 
142  m_states [backgroundState]->setCurveSelected (isGnuplot,
143  transformation,
144  modelGridRemoval,
145  modelColorFilter,
146  curveSelected);
147  }
148 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ setPixmap()

void BackgroundStateContext::setPixmap ( bool  isGnuplot,
const Transformation transformation,
const DocumentModelGridRemoval modelGridRemoval,
const DocumentModelColorFilter modelColorFilter,
const QPixmap &  pixmapOriginal,
const QString &  curveSelected 
)

Update the images of all states, rather than just the current state.

Definition at line 150 of file BackgroundStateContext.cpp.

156 {
157  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::setPixmap"
158  << " image=" << pixmapOriginal.width() << "x" << pixmapOriginal.height()
159  << " currentState=" << m_states [m_currentState]->state().toLatin1().data();
160 
161  for (int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
162 
163  m_states [backgroundState]->setPixmap (isGnuplot,
164  transformation,
165  modelGridRemoval,
166  modelColorFilter,
167  pixmapOriginal,
168  curveSelected);
169  }
170 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateColorFilter()

void BackgroundStateContext::updateColorFilter ( bool  isGnuplot,
const Transformation transformation,
const DocumentModelGridRemoval modelGridRemoval,
const DocumentModelColorFilter colorFilter,
const QString &  curveSelected 
)

Apply color filter settings.

Definition at line 172 of file BackgroundStateContext.cpp.

177 {
178  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateContext::updateColorFilter";
179 
180  for (int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
181 
182  m_states [backgroundState]->updateColorFilter (isGnuplot,
183  transformation,
184  modelGridRemoval,
185  modelColorFilter,
186  curveSelected);
187  }
188 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

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