Engauge Digitizer  2
DigitizeStateAbstractBase.cpp
1 #include "CmdEditPointAxis.h"
2 #include "CmdMediator.h"
3 #include "DigitizeStateAbstractBase.h"
4 #include "DigitizeStateContext.h"
5 #include "DlgEditPoint.h"
6 #include "Document.h"
7 #include "Logger.h"
8 #include "MainWindow.h"
9 #include <QApplication>
10 #include <QGraphicsScene>
11 #include <QImage>
12 #include <QMessageBox>
13 #include <QTimer>
14 #include "QtToString.h"
15 #include "Version.h"
16 
18  m_context (context),
19  m_isOverrideCursor (false)
20 {
21 }
22 
23 DigitizeStateAbstractBase::~DigitizeStateAbstractBase()
24 {
25 }
26 
28 {
29  return m_context;
30 }
31 
33 {
34  return m_context;
35 }
36 
37 void DigitizeStateAbstractBase::handleContextMenuEvent (const QString &pointIdentifier)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleContextMenuEvent point=" << pointIdentifier.toLatin1 ().data ();
40 
41  QPointF posScreen = context().cmdMediator().document().positionScreen (pointIdentifier);
42  QPointF posGraphBefore = context().cmdMediator().document().positionGraph (pointIdentifier);
43 
44  // Ask user for coordinates
45  double x = posGraphBefore.x();
46  double y = posGraphBefore.y();
47  DlgEditPoint *dlg = new DlgEditPoint(context().mainWindow(),
48  *this,
49  context().cmdMediator().document().modelCoords(),
50  context().mainWindow().modelMainWindow(),
51  cursor (),
52  context().mainWindow().transformation(),
53  &x,
54  &y);
55  int rtn = dlg->exec ();
56 
57  QPointF posGraphAfter = dlg->posGraph ();
58  delete dlg;
59 
60  if (rtn == QDialog::Accepted) {
61 
62  // User wants to edit this axis point, but let's perform sanity checks first
63 
64  bool isError;
65  QString errorMessage;
66 
68  posScreen,
69  posGraphAfter,
70  isError,
71  errorMessage);
72 
73  if (isError) {
74 
75  QMessageBox::warning (0,
76  engaugeWindowTitle(),
77  errorMessage);
78 
79  } else {
80 
81  // Create a command to edit the point
82  CmdEditPointAxis *cmd = new CmdEditPointAxis (context().mainWindow(),
83  context().cmdMediator().document(),
84  pointIdentifier,
85  posGraphBefore,
86  posGraphAfter);
87  context().appendNewCmd(cmd);
88  }
89  }
90 }
91 
93 {
94  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave";
95 
97 }
98 
100 {
102 
103  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleSetOverrideCursor setOverrideCursor="
104  << QtCursorToString (cursor.shape ()).toLatin1 ().data ();
105 
106  QApplication::setOverrideCursor (cursor);
107  m_isOverrideCursor = true;
108 }
109 
111 {
112  if (m_isOverrideCursor) {
113 
114  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateAbstractBase::handleLeave restoreOverrideCursor="
115  << QtCursorToString (QApplication::overrideCursor ()->shape ()).toLatin1 ().data ();
116 
117  // Override cursor from last QDialog must be restored
118  QApplication::restoreOverrideCursor ();
119 
120  m_isOverrideCursor = false;
121  }
122 }
123 
125 {
126  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateAbstractBase::setCursor";
127 
129  context().view().setCursor (cursor ());
130 }
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:734
CmdMediator & cmdMediator()
Provide CmdMediator for indirect access to the Document.
virtual void handleLeave()
Handle leave in case an override cursor is in effect from last QDialog, by resetting the override cur...
CmdMediator & cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:244
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...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
Definition: Document.cpp:239
virtual QCursor cursor() const =0
Returns the state-specific cursor shape.
QPointF posGraph() const
Return the graph coordinates position specified by the user. Only applies if dialog was accepted...
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setCursor()
Update the cursor according to the current state.
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:726
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...
void handleContextMenuEvent(const QString &pointIdentifier)
Handle a right click that was intercepted earlier. This is done in the superclass since it works the ...
void removeOverrideCursor()
Remove the override cursor if it is in use. This is called after a leave event, and prior to displayi...
QGraphicsView & view()
QGraphicsView for use by DigitizeStateAbstractBase subclasses.
Command for editing the graph coordinates one axis point.
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
void handleSetOverrideCursor(const QCursor &cursor)
Handle the command to set the override cursor.