Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
DigitizeStateAxis.cpp
1 #include "CmdAddPointAxis.h"
2 #include "CmdMediator.h"
3 #include "CursorFactory.h"
4 #include "DigitizeStateAxis.h"
5 #include "DigitizeStateContext.h"
6 #include "DlgEditPoint.h"
7 #include "Document.h"
8 #include "GraphicsScene.h"
9 #include "GraphicsView.h"
10 #include "Logger.h"
11 #include "MainWindow.h"
12 #include "PointStyle.h"
13 #include <QCursor>
14 #include <QImage>
15 #include <QMessageBox>
16 #include <QTimer>
17 
20 {
21 }
22 
23 DigitizeStateAxis::~DigitizeStateAxis ()
24 {
25 }
26 
28 {
29  return AXIS_CURVE_NAME;
30 }
31 
32 void DigitizeStateAxis::begin (DigitizeState /* previousState */)
33 {
34  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::begin";
35 
36  setCursor();
37  context().setDragMode(QGraphicsView::NoDrag);
39 }
40 
41 void DigitizeStateAxis::createTemporaryPoint (const QPointF &posScreen)
42 {
43  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::createTemporaryPoint";
44 
45  // Temporary point that user can see while DlgEditPoint is active
46  const Curve &curveAxes = context().cmdMediator().curveAxes();
47  PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
49  pointStyleAxes,
50  posScreen);
51 
53  point);
54 }
55 
57 {
58  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::cursor";
59 
60  CursorFactory cursorFactory;
61  QCursor cursor = cursorFactory.generate (context().cmdMediator().document().modelDigitizeCurve());
62 
63  return cursor;
64 }
65 
67 {
68  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::end";
69 }
70 
72 {
73  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleCurveChange";
74 }
75 
77  bool /* atLeastOneSelectedItem */)
78 {
79  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleKeyPress"
80  << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
81 }
82 
83 void DigitizeStateAxis::handleMouseMove (QPointF /* posScreen */)
84 {
85 // LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAxis::handleMouseMove";
86 }
87 
88 void DigitizeStateAxis::handleMousePress (QPointF /* posScreen */)
89 {
90  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMousePress";
91 }
92 
93 void DigitizeStateAxis::handleMouseRelease (QPointF posScreen)
94 {
95  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::handleMouseRelease";
96 
97  if (context().mainWindow().transformIsDefined()) {
98 
99  QMessageBox::warning (0,
100  "Application",
101  "Three axis points have been defined, and no more are needed or allowed.");
102 
103  } else {
104 
105  createTemporaryPoint (posScreen);
106 
107  // Ask user for coordinates
108  DlgEditPoint *dlg = new DlgEditPoint (context ().mainWindow (),
109  *this,
110  context().cmdMediator().document().modelCoords(),
111  context().mainWindow().modelMainWindow(),
112  cursor (),
113  context().mainWindow().transformation());
114  int rtn = dlg->exec ();
115  QPointF posGraph = dlg->posGraph ();
116  delete dlg;
117 
118  // Remove temporary point
120 
121  if (rtn == QDialog::Accepted) {
122 
123  // User wants to add this axis point, but let's perform sanity checks first
124 
125  bool isError;
126  QString errorMessage;
127  int nextOrdinal = context().cmdMediator().document().nextOrdinalForCurve(AXIS_CURVE_NAME);
128 
130  posGraph,
131  isError,
132  errorMessage);
133 
134  if (isError) {
135 
136  QMessageBox::warning (0,
137  "Application",
138  errorMessage);
139 
140  } else {
141 
142  // Create command to add point
143  Document &document = context ().cmdMediator ().document ();
144  QUndoCommand *cmd = new CmdAddPointAxis (context ().mainWindow(),
145  document,
146  posScreen,
147  posGraph,
148  nextOrdinal);
149  context().appendNewCmd(cmd);
150  }
151  }
152  }
153 }
154 
156 {
157  return "DigitizeStateAxis";
158 }
159 
161 {
162  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelDigitizeCurve";
163 
164  setCursor();
165 }
166 
168 {
169  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAxis::updateModelSegments";
170 }
const Curve & curveAxes() const
See Document::curveAxes.
Definition: CmdMediator.cpp:46
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void handleMouseMove(QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
CmdMediator & cmdMediator()
Provide CmdMediator for indirect access to the Document.
void removePoint(const QString &identifier)
Remove specified point. This aborts if the point does not exist.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void handleMousePress(QPointF posScreen)
Handle a mouse press that was intercepted earlier.
Create standard cross cursor, or custom cursor, according to settings.
Definition: CursorFactory.h:9
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
PointStyle pointStyle() const
Get method for PointStyle.
Definition: CurveStyle.cpp:69
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:61
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
MainWindow & mainWindow()
Reference to the MainWindow, without const.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition: Point.cpp:444
QPointF posGraph() const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
Details for a specific Point.
Definition: PointStyle.h:14
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
virtual QString state() const
State name for debugging.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setCursor()
Update the cursor according to the current state.
Command for adding one axis point.
virtual void handleCurveChange()
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
Storage of one imported image and the data attached to that image.
Definition: Document.h:29
Container for one set of digitized Points.
Definition: Curve.h:26
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:33
virtual void updateModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
Dialog box for editing the information of one axis point.
Definition: DlgEditPoint.h:23
void appendNewCmd(QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:705
virtual void handleKeyPress(Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void handleMouseRelease(QPointF posScreen)
Handle a mouse release that was intercepted earlier.
void addTemporaryPoint(const QString &identifier, GraphicsPoint *point)
Add one temporary point to m_graphicsLinesForCurves. Non-temporary points are handled by the updateLi...
Model for DlgSettingsSegments and CmdSettingsSegments.
CurveStyle curveStyle() const
Return the curve style.
Definition: Curve.cpp:132
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
virtual QCursor cursor() const
Returns the state-specific cursor shape.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
DigitizeStateAxis(DigitizeStateContext &context)
Single constructor.
virtual void begin(DigitizeState previousState)
Method that is called at the exact moment a state is entered.
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
Definition: Document.cpp:218
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...