1 #include "CmdMediator.h"
2 #include "DigitizeStateAxis.h"
3 #include "DigitizeStateColorPicker.h"
4 #include "DigitizeStateContext.h"
5 #include "DigitizeStateCurve.h"
6 #include "DigitizeStateEmpty.h"
7 #include "DigitizeStatePointMatch.h"
8 #include "DigitizeStateSegment.h"
9 #include "DigitizeStateSelect.h"
10 #include "DocumentModelSegments.h"
11 #include "EngaugeAssert.h"
12 #include "GraphicsScene.h"
13 #include "GraphicsView.h"
15 #include "MainWindow.h"
16 #include <QApplication>
18 #include <QGraphicsScene>
19 #include <QGraphicsView>
20 #include "QtToString.h"
25 m_mainWindow (mainWindow),
27 m_imageIsLoaded (false),
29 m_isGnuplot (isGnuplot)
39 ENGAUGE_ASSERT (m_states.size () == NUM_DIGITIZE_STATES);
41 m_currentState = NUM_DIGITIZE_STATES;
45 DigitizeStateContext::~DigitizeStateContext()
51 return m_states [m_currentState]->activeCurve ();
56 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::appendNewCmd";
58 ENGAUGE_ASSERT (m_cmdMediator != 0);
59 m_cmdMediator->push (cmd);
64 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::bindToCmdMediatorAndResetOnLoad";
70 if (m_currentState != DIGITIZE_STATE_EMPTY) {
71 m_requestedState = DIGITIZE_STATE_EMPTY;
72 completeRequestedStateTransitionIfExists();
78 ENGAUGE_ASSERT (m_cmdMediator != 0);
80 return *m_cmdMediator;
85 ENGAUGE_ASSERT (m_cmdMediator != 0);
87 return *m_cmdMediator;
90 void DigitizeStateContext::completeRequestedStateTransitionIfExists ()
92 if (m_currentState != m_requestedState) {
96 if (m_currentState != NUM_DIGITIZE_STATES) {
99 m_states [m_currentState]->end ();
103 DigitizeState previousState = m_currentState;
104 m_currentState = m_requestedState;
105 m_states [m_requestedState]->begin (previousState);
115 m_states [m_currentState]->handleContextMenuEvent (pointIdentifier);
120 m_states [m_currentState]->handleCurveChange();
124 bool atLeastOneSelectedItem)
126 m_states [m_currentState]->handleKeyPress (key,
127 atLeastOneSelectedItem);
129 completeRequestedStateTransitionIfExists();
135 m_states [m_currentState]->handleLeave ();
137 completeRequestedStateTransitionIfExists();
143 m_states [m_currentState]->handleMouseMove (pos);
145 completeRequestedStateTransitionIfExists();
151 m_states [m_currentState]->handleMousePress (pos);
153 completeRequestedStateTransitionIfExists();
159 m_states [m_currentState]->handleMouseRelease (pos);
161 completeRequestedStateTransitionIfExists();
166 m_states [m_currentState]->handleSetOverrideCursor (cursor);
186 m_requestedState = digitizeState;
191 m_requestedState = digitizeState;
192 completeRequestedStateTransitionIfExists();
197 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::setCursor";
199 m_states [m_currentState]->setCursor ();
204 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateContext::setDragMode";
206 if (m_imageIsLoaded) {
207 m_view.setDragMode (dragMode);
213 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::setImageIsLoaded";
215 m_imageIsLoaded = imageIsLoaded;
221 ENGAUGE_ASSERT (m_currentState != NUM_DIGITIZE_STATES);
223 return m_states [m_currentState]->state();
228 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::updateModelDigitizeCurve";
230 m_states [m_currentState]->updateModelDigitizeCurve (modelDigitizeCurve);
235 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateContext::updateModelSegments";
237 m_states [m_currentState]->updateModelSegments (modelSegments);
void requestDelayedStateTransition(DigitizeState digitizeState)
Initiate state transition to be performed later, when DigitizeState is off the stack.
void handleMouseMove(QPointF pos)
See DigitizeStateAbstractBase::handleMouseMove.
void updateDigitizeStateIfSoftwareTriggered(DigitizeState digitizeState)
After software-triggered state transition, this method manually triggers the action as if user had cl...
CmdMediator & cmdMediator()
Provide CmdMediator for indirect access to the Document.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void setImageIsLoaded(bool imageIsLoaded)
Set the image so QGraphicsView cursor and drag mode are accessible.
QString activeCurve() const
Curve name for active Curve. This can include AXIS_CURVE_NAME, and empty string.
void bindToCmdMediatorAndResetOnLoad(CmdMediator *cmdMediator)
Bind to CmdMediator class.
Digitizing state for selecting a color for DigitizeStateSegment.
void updateModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
void handleContextMenuEvent(const QString &pointIdentifier)
See DigitizeStateAbstractBase::handleContextMenuEvent.
Digitizing state before a Document has been created. In this state, the cursor is Qt::ArrowCursor...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
Digitizing state for matching Curve Points, one at a time.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Digitizing state for selecting one or more Points in the Document.
DigitizeStateContext(MainWindow &mainWindow, QGraphicsView &view, bool isGnuplot)
Single constructor.
void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
QString state() const
State name for debugging.
void requestImmediateStateTransition(DigitizeState digitizeState)
Perform immediate state transition. Called from outside state machine.
void handleLeave()
See DigitizeStateAbstractBase::handleLeave.
void appendNewCmd(QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
Model for DlgSettingsSegments and CmdSettingsSegments.
bool isGnuplot() const
Get method for gnuplot flag.
void handleSetOverrideCursor(const QCursor &cursor)
See DigitizeStateAbstractBase::handleSetOverrideCursor.
Digitizing state for creating Curve Points, one at a time.
QGraphicsView & view()
QGraphicsView for use by DigitizeStateAbstractBase subclasses.
void handleCurveChange()
See DigitizeStateAbstractBase::handleCurveChange.
Digitizing state for creating multiple Points along a highlighted segment.
void handleMouseRelease(QPointF pos)
See DigitizeStateAbstractBase::handleMouseRelease.
void handleKeyPress(Qt::Key key, bool atLeastOneSelectedItem)
See DigitizeStateAbstractBase::handleKeyPress.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void setCursor()
Set cursor after asking state for the new cursor shape.
void handleMousePress(QPointF pos)
See DigitizeStateAbstractBase::handleMousePress.
Digitizing state for digitizing one axis point at a time.