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

Digitizing state for creating the scale bar. More...

#include <DigitizeStateScale.h>

Inheritance diagram for DigitizeStateScale:
Inheritance graph
Collaboration diagram for DigitizeStateScale:
Collaboration graph

Public Member Functions

 DigitizeStateScale (DigitizeStateContext &context)
 Single constructor. More...
 
virtual ~DigitizeStateScale ()
 
virtual QString activeCurve () const
 Name of the active Curve. This can include AXIS_CURVE_NAME. More...
 
virtual void begin (CmdMediator *cmdMediator, DigitizeState previousState)
 Method that is called at the exact moment a state is entered. More...
 
virtual bool canPaste (const Transformation &transformation, const QSize &viewSize) const
 Return true if there is good data in the clipboard for pasting, and that is compatible with the current state. More...
 
virtual QCursor cursor (CmdMediator *cmdMediator) const
 Returns the state-specific cursor shape. More...
 
virtual void end ()
 Method that is called at the exact moment a state is exited. Typically called just before begin for the next state. More...
 
virtual void handleContextMenuEventAxis (CmdMediator *cmdMediator, const QString &pointIdentifier)
 Handle a right click, on an axis point, that was intercepted earlier. More...
 
virtual void handleContextMenuEventGraph (CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
 Handle a right click, on a graph point, that was intercepted earlier. More...
 
virtual void handleCurveChange (CmdMediator *cmdMediator)
 Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Segments. More...
 
virtual void handleKeyPress (CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
 Handle a key press that was intercepted earlier. More...
 
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 mode is worthwhile. More...
 
virtual void handleMousePress (CmdMediator *cmdMediator, QPointF posScreen)
 Handle a mouse press that was intercepted earlier. More...
 
virtual void handleMouseRelease (CmdMediator *cmdMediator, QPointF posScreen)
 Handle a mouse release that was intercepted earlier. More...
 
virtual QString state () const
 State name for debugging. More...
 
virtual void updateAfterPointAddition ()
 Update graphics attributes after possible new points. This is useful for highlight opacity. More...
 
virtual void updateModelDigitizeCurve (CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
 Update the digitize curve settings. More...
 
virtual void updateModelSegments (const DocumentModelSegments &modelSegments)
 Update the segments given the new settings. More...
 
- Public Member Functions inherited from DigitizeStateAbstractBase
 DigitizeStateAbstractBase (DigitizeStateContext &context)
 Single constructor. More...
 
virtual ~DigitizeStateAbstractBase ()
 
DigitizeStateContextcontext ()
 Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses, without const. More...
 
const DigitizeStateContextcontext () const
 Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses, without const. More...
 
void setCursor (CmdMediator *cmdMediator)
 Update the cursor according to the current state. More...
 

Additional Inherited Members

- Protected Member Functions inherited from DigitizeStateAbstractBase
bool canPasteProtected (const Transformation &transformation, const QSize &viewSize) const
 Protected version of canPaste method. Some, but not all, leaf classes use this method. More...
 

Detailed Description

Digitizing state for creating the scale bar.

A scale bar is preferred over an approach using two axis points and DigitizeStateAxis since:

  1. Fewer clicks are involved to move the scale bar. One click and drag operation moves the scale bar, but two click and drag operations would be needed to move two axis points
  2. Clicking on a large scale bar is easier than clicking on much smaller axis points
  3. DigitizeStateAxis solution would have a line, representing the scale bar, that would be unselectable - confusing to users

Definition at line 23 of file DigitizeStateScale.h.

Constructor & Destructor Documentation

◆ DigitizeStateScale()

DigitizeStateScale::DigitizeStateScale ( DigitizeStateContext context)

Single constructor.

Definition at line 27 of file DigitizeStateScale.cpp.

27  :
29  m_temporaryPoint0 (nullptr),
30  m_temporaryPoint1 (nullptr),
31  m_line (nullptr)
32 {
33 }
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.

◆ ~DigitizeStateScale()

DigitizeStateScale::~DigitizeStateScale ( )
virtual

Definition at line 35 of file DigitizeStateScale.cpp.

36 {
37 }

Member Function Documentation

◆ activeCurve()

QString DigitizeStateScale::activeCurve ( ) const
virtual

Name of the active Curve. This can include AXIS_CURVE_NAME.

Implements DigitizeStateAbstractBase.

Definition at line 39 of file DigitizeStateScale.cpp.

40 {
41  return AXIS_CURVE_NAME;
42 }
const QString AXIS_CURVE_NAME

◆ begin()

void DigitizeStateScale::begin ( CmdMediator cmdMediator,
DigitizeState  previousState 
)
virtual

Method that is called at the exact moment a state is entered.

Typically called just after end for the previous state. The previousState value is used by DigitizeStateColorPicker to return to the previous state

Implements DigitizeStateAbstractBase.

Definition at line 44 of file DigitizeStateScale.cpp.

46 {
47  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::begin";
48 
49  setCursor(cmdMediator);
50  context().setDragMode(QGraphicsView::NoDrag);
52 }
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ canPaste()

bool DigitizeStateScale::canPaste ( const Transformation transformation,
const QSize &  viewSize 
) const
virtual

Return true if there is good data in the clipboard for pasting, and that is compatible with the current state.

Implements DigitizeStateAbstractBase.

Definition at line 54 of file DigitizeStateScale.cpp.

56 {
57  return false;
58 }

◆ cursor()

QCursor DigitizeStateScale::cursor ( CmdMediator cmdMediator) const
virtual

Returns the state-specific cursor shape.

Implements DigitizeStateAbstractBase.

Definition at line 60 of file DigitizeStateScale.cpp.

61 {
62  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::cursor";
63 
64  CursorFactory cursorFactory;
65  QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
66 
67  return cursor;
68 }
Create standard cross cursor, or custom cursor, according to settings.
Definition: CursorFactory.h:15
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:709
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
QCursor generate(const DocumentModelDigitizeCurve &modelDigitizeCurve) const
Factory method to generate standard or custom cursor.
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20

◆ end()

void DigitizeStateScale::end ( )
virtual

Method that is called at the exact moment a state is exited. Typically called just before begin for the next state.

Implements DigitizeStateAbstractBase.

Definition at line 70 of file DigitizeStateScale.cpp.

71 {
72  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::end";
73 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ handleContextMenuEventAxis()

void DigitizeStateScale::handleContextMenuEventAxis ( CmdMediator cmdMediator,
const QString &  pointIdentifier 
)
virtual

Handle a right click, on an axis point, that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 75 of file DigitizeStateScale.cpp.

77 {
78  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventAxis "
79  << " point=" << pointIdentifier.toLatin1 ().data ();
80 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ handleContextMenuEventGraph()

void DigitizeStateScale::handleContextMenuEventGraph ( CmdMediator cmdMediator,
const QStringList &  pointIdentifiers 
)
virtual

Handle a right click, on a graph point, that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 82 of file DigitizeStateScale.cpp.

84 {
85  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventGraph "
86  << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
87 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ handleCurveChange()

void DigitizeStateScale::handleCurveChange ( CmdMediator cmdMediator)
virtual

Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Segments.

Implements DigitizeStateAbstractBase.

Definition at line 89 of file DigitizeStateScale.cpp.

90 {
91  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleCurveChange";
92 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ handleKeyPress()

void DigitizeStateScale::handleKeyPress ( CmdMediator cmdMediator,
Qt::Key  key,
bool  atLeastOneSelectedItem 
)
virtual

Handle a key press that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 94 of file DigitizeStateScale.cpp.

97 {
98  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleKeyPress"
99  << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
100 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ handleMouseMove()

void DigitizeStateScale::handleMouseMove ( CmdMediator cmdMediator,
QPointF  posScreen 
)
virtual

Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mode is worthwhile.

Implements DigitizeStateAbstractBase.

Definition at line 102 of file DigitizeStateScale.cpp.

104 {
105  if (m_temporaryPoint1 != nullptr) {
106 
107  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::handleMouseMove"
108  << " oldPos=" << QPointFToString (m_temporaryPoint1->pos ()).toLatin1().data()
109  << " newPos=" << QPointFToString (posScreen).toLatin1().data();
110 
111  m_temporaryPoint1->setPos (posScreen);
112 
113  updateLineGeometry();
114  }
115 }
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void setPos(const QPointF pos)
Update the position.
QString QPointFToString(const QPointF &pos)
Definition: QtToString.cpp:17
log4cpp::Category * mainCat
Definition: Logger.cpp:14
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20

◆ handleMousePress()

void DigitizeStateScale::handleMousePress ( CmdMediator cmdMediator,
QPointF  pos 
)
virtual

Handle a mouse press that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 117 of file DigitizeStateScale.cpp.

119 {
120  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMousePress";
121 
122  GeometryWindow *NULL_GEOMETRY_WINDOW = nullptr;
123 
124  // Create the scale bar to give the user immediate feedback that something was created
125  const Curve &curveAxes = cmdMediator->curveAxes();
126  PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
127  m_pointIdentifier0 = Point::temporaryPointIdentifier();
128  m_pointIdentifier1 = m_pointIdentifier0 + "b";
129  m_temporaryPoint0 = context().mainWindow().scene().createPoint(m_pointIdentifier0,
130  pointStyleAxes,
131  posScreen,
132  NULL_GEOMETRY_WINDOW);
133  m_temporaryPoint1 = context().mainWindow().scene().createPoint(m_pointIdentifier1,
134  pointStyleAxes,
135  posScreen,
136  NULL_GEOMETRY_WINDOW);
137 
138  // Subtle stuff happening here. GraphicsPoints by default can receive focus for clicking/dragging,
139  // but for some reason that was causing the dragged second endpoint to jump to the origin the Nth
140  // time that a scale bar was created, for every N>1. So we make the endpoint passive and update
141  // its position manually in handleMouseMove
142  m_temporaryPoint0->setPassive ();
143  m_temporaryPoint1->setPassive ();
144 
145  context().mainWindow().scene().addTemporaryScaleBar (m_temporaryPoint0,
146  m_temporaryPoint1,
147  m_pointIdentifier0,
148  m_pointIdentifier1);
149 
150  m_line = new QGraphicsLineItem;
151  context().mainWindow().scene().addItem (m_line);
152  m_line->setPen (QColor (Qt::red));
153  m_line->setZValue (Z_VALUE_CURVE);
154  m_line->setVisible (true);
155 
156  updateLineGeometry ();
157 
158  // Attempts to select an endpoint right here, or after an super short timer interval
159  // failed. That would have been nice for having the click create the scale bar and, while
160  // the mouse was still pressed, selecting an endpoint thus allowing a single click-and-drag to
161  // create the scale bar. We fall back to the less elegant solution (which the user will never
162  // notice) of capturing mouse move events and using those to move an endpoint
163 }
const Curve & curveAxes() const
See Document::curveAxes.
Definition: CmdMediator.cpp:57
void setPassive()
Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work proper...
PointStyle pointStyle() const
Get method for PointStyle.
Definition: CurveStyle.cpp:75
void addTemporaryScaleBar(GraphicsPoint *point0, GraphicsPoint *point1, const QString &pointIdentifier0, const QString &pointIdentifier1)
Add temporary scale bar to scene.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Window that displays the geometry information, as a table, for the current curve. ...
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition: Point.cpp:519
const int Z_VALUE_CURVE
Definition: ZValues.cpp:10
GraphicsPoint * createPoint(const QString &identifier, const PointStyle &pointStyle, const QPointF &posScreen, GeometryWindow *geometryWindow)
Create one QGraphicsItem-based object that represents one Point. It is NOT added to m_graphicsLinesFo...
Details for a specific Point.
Definition: PointStyle.h:20
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Container for one set of digitized Points.
Definition: Curve.h:33
log4cpp::Category * mainCat
Definition: Logger.cpp:14
CurveStyle curveStyle() const
Return the curve style.
Definition: Curve.cpp:149

◆ handleMouseRelease()

void DigitizeStateScale::handleMouseRelease ( CmdMediator cmdMediator,
QPointF  pos 
)
virtual

Handle a mouse release that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 165 of file DigitizeStateScale.cpp.

167 {
168  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMouseRelease";
169 
170  if (context().mainWindow().transformIsDefined()) {
171 
172  QMessageBox::warning (nullptr,
173  QObject::tr ("Engauge Digitizer"),
174  QObject::tr ("The scale bar has been defined, and another is not needed or allowed."));
175 
176  removeTemporaryPointsAndLine ();
177 
178  } else {
179 
180  // Ask user for coordinates
181  DlgEditScale *dlg = new DlgEditScale (context ().mainWindow (),
182  cmdMediator->document().modelCoords(),
183  cmdMediator->document().modelGeneral(),
185  int rtn = dlg->exec ();
186 
187  double scaleLength = dlg->scaleLength ();
188  QPointF posScreen0 = m_temporaryPoint0->pos ();
189  QPointF posScreen1 = m_temporaryPoint1->pos ();
190  delete dlg;
191 
192  removeTemporaryPointsAndLine ();
193 
194  if (rtn == QDialog::Accepted) {
195 
196  // User wants to add this scale point. There are no additional sanity checks to run
197 
198  int nextOrdinal0 = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
199  int nextOrdinal1 = nextOrdinal0 + 1;
200 
201  // Create command to add point
202  Document &document = cmdMediator->document ();
203  QUndoCommand *cmd = new CmdAddScale (context ().mainWindow(),
204  document,
205  posScreen0,
206  posScreen1,
207  scaleLength,
208  nextOrdinal0,
209  nextOrdinal1);
210  context().appendNewCmd(cmdMediator,
211  cmd);
212  }
213  }
214 }
QPointF pos() const
Proxy method for QGraphicsItem::pos.
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:765
Dialog box for editing the information of the map scale.
Definition: DlgEditScale.h:22
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition: Document.cpp:723
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
Definition: CmdMediator.cpp:72
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
MainWindowModel modelMainWindow() const
Get method for main window model.
Command for adding one scale point.
Definition: CmdAddScale.h:16
log4cpp::Category * mainCat
Definition: Logger.cpp:14
double scaleLength() const
Return the scale bar length specified by the user. Only applies if dialog was accepted.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:695
const QString AXIS_CURVE_NAME

◆ state()

QString DigitizeStateScale::state ( ) const
virtual

State name for debugging.

Implements DigitizeStateAbstractBase.

Definition at line 227 of file DigitizeStateScale.cpp.

228 {
229  return "DigitizeStateScale";
230 }

◆ updateAfterPointAddition()

void DigitizeStateScale::updateAfterPointAddition ( )
virtual

Update graphics attributes after possible new points. This is useful for highlight opacity.

Implements DigitizeStateAbstractBase.

Definition at line 232 of file DigitizeStateScale.cpp.

233 {
234  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateAfterPointAddition";
235 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateModelDigitizeCurve()

void DigitizeStateScale::updateModelDigitizeCurve ( CmdMediator cmdMediator,
const DocumentModelDigitizeCurve modelDigitizeCurve 
)
virtual

Update the digitize curve settings.

Implements DigitizeStateAbstractBase.

Definition at line 245 of file DigitizeStateScale.cpp.

247 {
248  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelDigitizeCurve";
249 
250  setCursor(cmdMediator);
251 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
log4cpp::Category * mainCat
Definition: Logger.cpp:14

◆ updateModelSegments()

void DigitizeStateScale::updateModelSegments ( const DocumentModelSegments modelSegments)
virtual

Update the segments given the new settings.

Implements DigitizeStateAbstractBase.

Definition at line 253 of file DigitizeStateScale.cpp.

254 {
255  LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelSegments";
256 }
#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: