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

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.
 

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}
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,...

◆ ~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}
log4cpp::Category * mainCat
Definition Logger.cpp:14
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from 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 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

◆ 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
66
67 return cursor;
68}
const int INNER_RADIUS_MIN
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.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition Document.cpp:709
#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}

◆ 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}

◆ 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}

◆ 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}

◆ 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}

◆ 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}
QString QPointFToString(const QPointF &pos)
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void setPos(const QPointF pos)
Update the position.

◆ 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
123
124 // Create the scale bar to give the user immediate feedback that something was created
125 const Curve &curveAxes = cmdMediator->curveAxes();
127 m_pointIdentifier0 = Point::temporaryPointIdentifier();
128 m_pointIdentifier1 = m_pointIdentifier0 + "b";
129 m_temporaryPoint0 = context().mainWindow().scene().createPoint(m_pointIdentifier0,
131 posScreen,
133 m_temporaryPoint1 = context().mainWindow().scene().createPoint(m_pointIdentifier1,
135 posScreen,
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 int Z_VALUE_CURVE
Definition ZValues.cpp:10
const Curve & curveAxes() const
See Document::curveAxes.
PointStyle pointStyle() const
Get method for PointStyle.
Container for one set of digitized Points.
Definition Curve.h:34
CurveStyle curveStyle() const
Return the curve style.
Definition Curve.cpp:149
Window that displays the geometry information, as a table, for the current curve.
void setPassive()
Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work proper...
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...
void addTemporaryScaleBar(GraphicsPoint *point0, GraphicsPoint *point1, const QString &pointIdentifier0, const QString &pointIdentifier1)
Add temporary scale bar to scene.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
Details for a specific Point.
Definition PointStyle.h:21
static QString temporaryPointIdentifier()
Point identifier for temporary point that is used by DigitzeStateAxis.
Definition Point.cpp:519

◆ 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(),
184 context().mainWindow().modelMainWindow());
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
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,
207 scaleLength,
210 context().appendNewCmd(cmdMediator,
211 cmd);
212 }
213 }
214}
Command for adding one scale point.
Definition CmdAddScale.h:17
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
Dialog box for editing the information of the map scale.
Storage of one imported image and the data attached to that image.
Definition Document.h:42
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition Document.cpp:723
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition Document.cpp:765
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition Document.cpp:695

◆ 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}

◆ 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}

◆ 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}

The documentation for this class was generated from the following files: