Engauge Digitizer 2
Loading...
Searching...
No Matches
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 bool guidelinesAreSelectable () const
 Enable/disable guidelines according to 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.
virtual void handleKeyPressArrow (CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
 If the key is an arrow (left, right, up, down) then move currently selected items.
QString moveTextDown () const
 Display text for down arrow.
QString moveTextLeft () const
 Display text for left arrow.
QString moveTextRight () const
 Display text for right arrow.
QString moveTextUp () const
 Display text for up arrow.

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 24 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}
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
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);
53}
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...
void handleGuidelinesActiveChange(bool active)
Handle Guidelines active status toggle.
#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 55 of file DigitizeStateScale.cpp.

57{
58 return false;
59}

◆ cursor()

QCursor DigitizeStateScale::cursor ( CmdMediator * cmdMediator) const
virtual

Returns the state-specific cursor shape.

Implements DigitizeStateAbstractBase.

Definition at line 61 of file DigitizeStateScale.cpp.

62{
63 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::cursor";
64
65 CursorFactory cursorFactory;
66 QCursor cursor = cursorFactory.generate (cmdMediator->document().modelDigitizeCurve());
67
68 return cursor;
69}
Document & document()
Provide the Document to commands, primarily for undo/redo processing.
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:721
#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 71 of file DigitizeStateScale.cpp.

72{
73 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::end";
74}

◆ guidelinesAreSelectable()

bool DigitizeStateScale::guidelinesAreSelectable ( ) const
virtual

Enable/disable guidelines according to state.

Implements DigitizeStateAbstractBase.

Definition at line 76 of file DigitizeStateScale.cpp.

77{
78 return false;
79}

◆ 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 81 of file DigitizeStateScale.cpp.

83{
84 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventAxis "
85 << " point=" << pointIdentifier.toLatin1 ().data ();
86}

◆ 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 88 of file DigitizeStateScale.cpp.

90{
91 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleContextMenuEventGraph "
92 << "points=" << pointIdentifiers.join(",").toLatin1 ().data ();
93}

◆ 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 95 of file DigitizeStateScale.cpp.

96{
97 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleCurveChange";
98}

◆ 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 100 of file DigitizeStateScale.cpp.

103{
104 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleKeyPress"
105 << " key=" << QKeySequence (key).toString ().toLatin1 ().data ();
106}

◆ 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 108 of file DigitizeStateScale.cpp.

110{
111 if (m_temporaryPoint1 != nullptr) {
112
113 LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStateScale::handleMouseMove"
114 << " oldPos=" << QPointFToString (m_temporaryPoint1->pos ()).toLatin1().data()
115 << " newPos=" << QPointFToString (posScreen).toLatin1().data();
116
117 m_temporaryPoint1->setPos (posScreen);
118
119 updateLineGeometry();
120 }
121}
QString QPointFToString(const QPointF &pos)

◆ handleMousePress()

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

Handle a mouse press that was intercepted earlier.

Implements DigitizeStateAbstractBase.

Definition at line 123 of file DigitizeStateScale.cpp.

125{
126 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMousePress";
127
128 GeometryWindow *NULL_GEOMETRY_WINDOW = nullptr;
129
130 // Create the scale bar to give the user immediate feedback that something was created
131 const Curve &curveAxes = cmdMediator->curveAxes();
132 PointStyle pointStyleAxes = curveAxes.curveStyle().pointStyle();
133 m_pointIdentifier0 = Point::temporaryPointIdentifier();
134 m_pointIdentifier1 = m_pointIdentifier0 + "b";
135 m_temporaryPoint0 = context().mainWindow().scene().createPoint(m_pointIdentifier0,
136 pointStyleAxes,
137 posScreen,
138 NULL_GEOMETRY_WINDOW);
139 m_temporaryPoint1 = context().mainWindow().scene().createPoint(m_pointIdentifier1,
140 pointStyleAxes,
141 posScreen,
142 NULL_GEOMETRY_WINDOW);
143
144 // Subtle stuff happening here. GraphicsPoints by default can receive focus for clicking/dragging,
145 // but for some reason that was causing the dragged second endpoint to jump to the origin the Nth
146 // time that a scale bar was created, for every N>1. So we make the endpoint passive and update
147 // its position manually in handleMouseMove
148 m_temporaryPoint0->setPassive ();
149 m_temporaryPoint1->setPassive ();
150
151 context().mainWindow().scene().addTemporaryScaleBar (m_temporaryPoint0,
152 m_temporaryPoint1,
153 m_pointIdentifier0,
154 m_pointIdentifier1);
155
156 m_line = new QGraphicsLineItem;
157 context().mainWindow().scene().addItem (m_line);
158 m_line->setPen (QColor (Qt::red));
159 m_line->setZValue (Z_VALUE_CURVE);
160 m_line->setVisible (true);
161
162 updateLineGeometry ();
163
164 // Attempts to select an endpoint right here, or after an super short timer interval
165 // failed. That would have been nice for having the click create the scale bar and, while
166 // the mouse was still pressed, selecting an endpoint thus allowing a single click-and-drag to
167 // create the scale bar. We fall back to the less elegant solution (which the user will never
168 // notice) of capturing mouse move events and using those to move an endpoint
169}
const int Z_VALUE_CURVE
Definition ZValues.cpp:10
const Curve & curveAxes() const
See Document::curveAxes.
PointStyle pointStyle() const
Get method for PointStyle.
CurveStyle curveStyle() const
Return the curve style.
Definition Curve.cpp:149
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.
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 171 of file DigitizeStateScale.cpp.

173{
174 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::handleMouseRelease";
175
176 if (context().mainWindow().transformIsDefined()) {
177
178 QMessageBox::warning (nullptr,
179 QObject::tr ("Engauge Digitizer"),
180 QObject::tr ("The scale bar has been defined, and another is not needed or allowed."));
181
182 removeTemporaryPointsAndLine ();
183
184 } else {
185
186 // Ask user for coordinates
187 DlgEditScale *dlg = new DlgEditScale (context ().mainWindow (),
188 cmdMediator->document().modelCoords(),
189 cmdMediator->document().modelGeneral(),
190 context().mainWindow().modelMainWindow());
191 int rtn = dlg->exec ();
192
193 double scaleLength = dlg->scaleLength ();
194 QPointF posScreen0 = m_temporaryPoint0->pos ();
195 QPointF posScreen1 = m_temporaryPoint1->pos ();
196 delete dlg;
197
198 removeTemporaryPointsAndLine ();
199
200 if (rtn == QDialog::Accepted) {
201
202 // User wants to add this scale point. There are no additional sanity checks to run
203
204 int nextOrdinal0 = cmdMediator->document().nextOrdinalForCurve(AXIS_CURVE_NAME);
205 int nextOrdinal1 = nextOrdinal0 + 1;
206
207 // Create command to add point
208 Document &document = cmdMediator->document ();
209 QUndoCommand *cmd = new CmdAddScale (context ().mainWindow(),
210 document,
211 posScreen0,
212 posScreen1,
213 scaleLength,
214 nextOrdinal0,
215 nextOrdinal1);
216 context().appendNewCmd(cmdMediator,
217 cmd);
218 }
219 }
220}
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
double scaleLength() const
Return the scale bar length specified by the user. Only applies if dialog was accepted.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition Document.cpp:735
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition Document.cpp:791
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition Document.cpp:707

◆ state()

QString DigitizeStateScale::state ( ) const
virtual

State name for debugging.

Implements DigitizeStateAbstractBase.

Definition at line 233 of file DigitizeStateScale.cpp.

234{
235 return "DigitizeStateScale";
236}

◆ updateAfterPointAddition()

void DigitizeStateScale::updateAfterPointAddition ( )
virtual

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

Implements DigitizeStateAbstractBase.

Definition at line 238 of file DigitizeStateScale.cpp.

239{
240 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateAfterPointAddition";
241}

◆ updateModelDigitizeCurve()

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

Update the digitize curve settings.

Implements DigitizeStateAbstractBase.

Definition at line 251 of file DigitizeStateScale.cpp.

253{
254 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelDigitizeCurve";
255
256 setCursor(cmdMediator);
257}

◆ updateModelSegments()

void DigitizeStateScale::updateModelSegments ( const DocumentModelSegments & modelSegments)
virtual

Update the segments given the new settings.

Implements DigitizeStateAbstractBase.

Definition at line 259 of file DigitizeStateScale.cpp.

260{
261 LOG4CPP_INFO_S ((*mainCat)) << "DigitizeStateScale::updateModelSegments";
262}

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