Engauge Digitizer 2
Loading...
Searching...
No Matches
DigitizeStateCurve.cpp
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 "CmdAddPointGraph.h"
8#include "CmdMediator.h"
9#include "CursorFactory.h"
10#include "DigitizeStateContext.h"
11#include "DigitizeStateCurve.h"
12#include "Logger.h"
13#include "MainWindow.h"
14#include "OrdinalGenerator.h"
15#include <QCursor>
16#include <QGraphicsScene>
17#include <QImage>
18
23
24DigitizeStateCurve::~DigitizeStateCurve ()
25{
26}
27
29{
31}
32
34 DigitizeState /* previousState */)
35{
36 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::begin";
37
38 setCursor(cmdMediator);
39 context().setDragMode(QGraphicsView::NoDrag);
41}
42
43QCursor DigitizeStateCurve::cursor(CmdMediator *cmdMediator) const
44{
45 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateCurve::cursor";
46
47 CursorFactory cursorFactory;
48 QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
49
50 return cursor;
51}
52
54{
55 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::end";
56}
57
59{
60 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleCurveChange";
61}
62
64 Qt::Key key,
65 bool /* atLeastOneSelectedItem */)
66{
67 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleKeyPress"
68 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
69}
70
72 QPointF /* posScreen */)
73{
74// LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateCurve::handleMouseMove";
75}
76
78 QPointF /* posScreen */)
79{
80 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleMousePress";
81}
82
84 QPointF posScreen)
85{
86 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::handleMouseRelease";
87
88 // Create command to add point
89 OrdinalGenerator ordinalGenerator;
90 Document &document = cmdMediator->document ();
91 const Transformation &transformation = context ().mainWindow ().transformation();
92 QUndoCommand *cmd = new CmdAddPointGraph (context ().mainWindow(),
93 document,
94 context ().mainWindow().selectedGraphCurve(),
95 posScreen,
96 ordinalGenerator.generateCurvePointOrdinal(document,
97 transformation,
98 posScreen,
99 activeCurve ()));
100 context().appendNewCmd(cmdMediator,
101 cmd);
102}
103
105{
106 return "DigitizeStateCurve";
107}
108
110 const DocumentModelDigitizeCurve & /*modelDigitizeCurve */)
111{
112 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::updateModelDigitizeCurve";
113
114 setCursor(cmdMediator);
115}
116
118{
119 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateCurve::updateModelSegments";
120}
Command for adding one graph point.
Command queue stack.
Definition CmdMediator.h:24
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Create standard cross cursor, or custom cursor, according to settings.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual QString state() const
State name for debugging.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
DigitizeStateCurve(DigitizeStateContext &context)
Single constructor.
virtual void handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Model for DlgSettingsSegments and CmdSettingsSegments.
Storage of one imported image and the data attached to that image.
Definition Document.h:41
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition Document.cpp:625
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
Transformation transformation() const
Return read-only copy of transformation.
Utility class for generating ordinal numbers.
double generateCurvePointOrdinal(const Document &document, const Transformation &transformation, const QPointF &posScreen, const QString &curveName)
Select ordinal so new point curve passes smoothly through existing points.
Affine transformation between screen and graph coordinates, based on digitized axis points.