Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineAbstract Class Referenceabstract

This class is a special case of the standard QGraphicsLineItem for guidelines, and serves as the base class for the guideline state classes. More...

#include <GuidelineAbstract.h>

Inheritance diagram for GuidelineAbstract:
Inheritance graph
Collaboration diagram for GuidelineAbstract:
Collaboration graph

Public Slots

void slotHandleMoved (QPointF posScreen)
 Slot for signal from cloned deployed Guideline from handle Guideline.

Signals

void signalGuidelineDragged (QString, double, bool, GuidelineState)
 Signal indicating end of Guideline drag.
void signalHandleMoved (QPointF)
 Signal for cloned deployed Guideline from handle Guideline.

Public Member Functions

 GuidelineAbstract (QGraphicsScene &scene)
 Single constructor.
 ~GuidelineAbstract ()
void bindGuidelineVisibleToInvisible (GuidelineAbstract *guidelineVisible)
 Bind a newly-created visible Guideline to this Guideline, and make this one invisible.
virtual bool getGraphicsItemAcceptHover () const =0
 Return true if accepting hover events.
virtual bool getGraphicsItemSelected () const =0
 Wrapper for QGraphicsItem::isSelected.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags () const =0
 Wraps QGraphicsItem::flags.
void handleActiveChange (bool active)
 DigitizeState change so active status may (or may not) be toggled.
void handleGuidelineMode (bool visible, bool locked)
 User toggled Guideline visibility and/or locked mode.
void handleHoverEnterEvent ()
 Highlight this Guideline upon hover enter.
void handleHoverLeaveEvent ()
 Unset highlighting triggered by hover enter.
void handleMouseMoveEvent (const QPointF &posScene)
 Forward movements to visible Guideline.
void handleMousePressEvent (const QPointF &posScene)
 Forward press event to state machine.
void handleMouseReleaseEvent (const QPointF &posScene)
 Cleanup after being dragged.
virtual QString identifier () const =0
 Unique identifier from QGraphicsItem.
QPointF posCursorGraph () const
 Get position in graph coordinates.
virtual void removeFromScene (QGraphicsScene *scene)=0
 Make graphics item remove itself from the scene.
void sacrificeHandleAndVisibleGuidelines (const QPointF &posScene, GuidelineState guidelineStateForReplacement)
 Replace visible and handle Guidelines after click and drag.
QGraphicsScene & scene ()
 GraphicsScene that owns this class.
virtual void setGraphicsItemAcceptHoverEvents (bool accept)=0
 Wrapper for QGraphicsItem::setAcceptHoverEvents.
virtual void setGraphicsItemFlags (QGraphicsItem::GraphicsItemFlags flags)=0
 Wrapper for QGraphicsItem::setFlags.
virtual void setGraphicsItemLine (const QLineF &line)=0
 Wrapper for QGraphicsLineItem::setLine.
virtual void setGraphicsItemPen (const QColor &color, double lineWidth)=0
 Wrapper for QGraphicsItem::setPen.
virtual void setGraphicsItemVisible (bool visible)=0
 Wrapper for QGraphicsItem::setVisible.
virtual void setGraphicsItemZValue (double z)=0
 Wrapper for QGraphicsItem::setZValue.
QString stateDump () const
 Dump of state as a string for debugging only. Context like the QGraphicsItem flags is included.
QString stateName () const
 Current state name for debugging and unit test only.
void updateActive (bool active)
 Update active versus inactive state.
virtual void updateColor ()=0
 Force a color update.
virtual void updateGeometry (double valueGraph)=0
 Update the geometry so it passes through the specified coordinate value in graph coordinates.
virtual void updateGeometry (const QPointF &posScreen)=0
 Update the geometry so it passes through the specified point in screen coordinates.
void updateWithLatestTransformation ()
 Update given Transformation in GuidelineStateContext. This is called after a command has been executed.

Protected Member Functions

GuidelineStateContextcontext ()
 State machine context owned by this class.
const GuidelineStateContextcontext () const
 State machine context owned by this class as a const.
void setContext (GuidelineStateContext *context)
 Create state machine after virtual methods of child classes have been defined.

Detailed Description

This class is a special case of the standard QGraphicsLineItem for guidelines, and serves as the base class for the guideline state classes.

This class has a state machine to handle state-specific behavior for hovering, dragging, and formatting.

General strategy: When a deployed Guideline is dragged, the following process occurs 1) The dragged Guideline becomes invisible, and its state changes to Handle 2) A new deployed Guideline is generated where the dragged Guideline was located 3) Dragging the Handle causes the same movements in the new deployed Guideline 4) The new deployed Guideline is continually resized to just fit the scene, and in the case of polar coordinates resized to go between origin and scene edge (theta) or curved elliptically (range) 5) At the end of the drag, the Handle and Visible Guidelines are sacrificed (=discarded) and a new Deployed Guideline is created. Since the new Deployed Guideline is off the stack, the new CmdGuidelineMove can work on it safely State transitions are diagrammed in the GuidelineStateContext class

This strategy works with the following constraints 1) Since it is not the dragged object that we modify in 3d above, we can resize and adjust the curvature of the visible new deployed Guideline as necessary 2) When a Guideline is clicked on, that is the one that is active during the cursor drag. It is not possible to move the focus to another QGraphicsItem 3) At the end of the drag, a new CmdGuidelineMove is created and its redo method is run before the Handle Guideline is off the stack. This would corrupt the movement if that CmdGuidelineMove tried to move the (on the stack) Handle, so we do not transition the Handle state back to the Deployed state. Instead, a third Guideline is created as the target of the new CmdGuidelineMove. The Handle and Visible Guidelines are sacrificed (=moved to Discard state or deleted).j

State names are defined as:

horizontal = Follows constant-y isocontour

vertical = Follows constant-x isocontour

deployed = One of the guidelines created by button press or dragging an existing Guideline

hide = Used when all Guidelines have been turned off

hover = Applies when cursor is hovering over the Guideline, to add some highlighting

normal = After a deployed Guideline has been created and lost the hover

discarded = A noop state. The Guideline is no longer useful and has been removed

handle = This Guideline is invisible, being dragged, and moving a bound deployed

Guideline along the same drag trajectory

There are two derived classes:

one for drawing lines (cartesian and polar angle) with QGraphicsLineItem

one for drawing ellipses (range angle) with QGraphicsEllipseItem

An attempt to draw lines with just QGraphicsEllipseItem, for simplicity, failed with the result having sinusoidally changing line width.

Definition at line 68 of file GuidelineAbstract.h.

Constructor & Destructor Documentation

◆ GuidelineAbstract()

GuidelineAbstract::GuidelineAbstract ( QGraphicsScene & scene)

Single constructor.

Definition at line 28 of file GuidelineAbstract.cpp.

28 :
29 m_scene (scene),
30 m_context (nullptr),
31 m_guidelineVisible (nullptr)
32{
33}
QGraphicsScene & scene()
GraphicsScene that owns this class.

◆ ~GuidelineAbstract()

GuidelineAbstract::~GuidelineAbstract ( )

Definition at line 35 of file GuidelineAbstract.cpp.

36{
37 delete m_context;
38}

Member Function Documentation

◆ bindGuidelineVisibleToInvisible()

void GuidelineAbstract::bindGuidelineVisibleToInvisible ( GuidelineAbstract * guidelineVisible)

Bind a newly-created visible Guideline to this Guideline, and make this one invisible.

Definition at line 40 of file GuidelineAbstract.cpp.

41{
42 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::bindGuidelineVisibleToInvisible";
43
44 m_guidelineVisible = guidelineVisible;
45
46 connect (this, SIGNAL (signalHandleMoved (QPointF)),
47 guidelineVisible, SLOT (slotHandleMoved (QPointF)));
48}
log4cpp::Category * mainCat
Definition Logger.cpp:14
void slotHandleMoved(QPointF posScreen)
Slot for signal from cloned deployed Guideline from handle Guideline.
void signalHandleMoved(QPointF)
Signal for cloned deployed Guideline from handle Guideline.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ context() [1/2]

GuidelineStateContext * GuidelineAbstract::context ( )
protected

State machine context owned by this class.

Definition at line 50 of file GuidelineAbstract.cpp.

51{
52 return m_context;
53}

◆ context() [2/2]

const GuidelineStateContext * GuidelineAbstract::context ( ) const
protected

State machine context owned by this class as a const.

Definition at line 55 of file GuidelineAbstract.cpp.

56{
57 return m_context;
58}

◆ getGraphicsItemAcceptHover()

virtual bool GuidelineAbstract::getGraphicsItemAcceptHover ( ) const
pure virtual

Return true if accepting hover events.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ getGraphicsItemSelected()

virtual bool GuidelineAbstract::getGraphicsItemSelected ( ) const
pure virtual

Wrapper for QGraphicsItem::isSelected.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ graphicsItemFlags()

virtual QGraphicsItem::GraphicsItemFlags GuidelineAbstract::graphicsItemFlags ( ) const
pure virtual

Wraps QGraphicsItem::flags.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ handleActiveChange()

void GuidelineAbstract::handleActiveChange ( bool active)

DigitizeState change so active status may (or may not) be toggled.

Definition at line 60 of file GuidelineAbstract.cpp.

61{
62 m_context->handleActiveChange (active);
63}

◆ handleGuidelineMode()

void GuidelineAbstract::handleGuidelineMode ( bool visible,
bool locked )

User toggled Guideline visibility and/or locked mode.

Definition at line 65 of file GuidelineAbstract.cpp.

67{
68 m_context->handleGuidelineMode (visible,
69 locked);
70}

◆ handleHoverEnterEvent()

void GuidelineAbstract::handleHoverEnterEvent ( )

Highlight this Guideline upon hover enter.

Definition at line 72 of file GuidelineAbstract.cpp.

73{
74 m_context->handleHoverEnterEvent ();
75}

◆ handleHoverLeaveEvent()

void GuidelineAbstract::handleHoverLeaveEvent ( )

Unset highlighting triggered by hover enter.

Definition at line 77 of file GuidelineAbstract.cpp.

78{
79 m_context->handleHoverLeaveEvent ();
80}

◆ handleMouseMoveEvent()

void GuidelineAbstract::handleMouseMoveEvent ( const QPointF & posScene)

Forward movements to visible Guideline.

Definition at line 82 of file GuidelineAbstract.cpp.

83{
84 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::handleMouseMoveEvent ("
85 << posScene.x() << ", " << posScene.y() << ")";
86
87 // Skip if there is no bound visible Guideline
88 if (m_guidelineVisible != nullptr) {
89
90 emit signalHandleMoved (posScene);
91 }
92}

◆ handleMousePressEvent()

void GuidelineAbstract::handleMousePressEvent ( const QPointF & posScene)

Forward press event to state machine.

Definition at line 94 of file GuidelineAbstract.cpp.

95{
96 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMousePressEvent";
97
98 m_context->handleMousePress(posScene);
99}
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ handleMouseReleaseEvent()

void GuidelineAbstract::handleMouseReleaseEvent ( const QPointF & posScene)

Cleanup after being dragged.

Definition at line 101 of file GuidelineAbstract.cpp.

102{
103 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMouseReleaseEvent";
104
105 m_context->handleMouseRelease (posScene);
106}

◆ identifier()

virtual QString GuidelineAbstract::identifier ( ) const
pure virtual

Unique identifier from QGraphicsItem.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ posCursorGraph()

QPointF GuidelineAbstract::posCursorGraph ( ) const

Get position in graph coordinates.

Definition at line 144 of file GuidelineAbstract.cpp.

145{
146 return m_context->posCursorGraph ();
147}

◆ removeFromScene()

virtual void GuidelineAbstract::removeFromScene ( QGraphicsScene * scene)
pure virtual

Make graphics item remove itself from the scene.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ sacrificeHandleAndVisibleGuidelines()

void GuidelineAbstract::sacrificeHandleAndVisibleGuidelines ( const QPointF & posScene,
GuidelineState guidelineStateForReplacement )

Replace visible and handle Guidelines after click and drag.

Definition at line 108 of file GuidelineAbstract.cpp.

110{
111 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines"
112 << " keeping identifier=" << identifier().toLatin1().data()
113 << " in " << stateName ().toLatin1().data();
114
115 if (m_guidelineVisible != nullptr) {
116
117 // If scene position is off-screen then user is removing the visible Guideline
118 bool offscreen = !m_scene.sceneRect().contains (posScene);
119
120 // Remove transient Guideline, which was never registered with Guidelines
121 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines identifierDeleting="
122 << m_guidelineVisible->identifier().toLatin1().data();
123 disconnect (this, SIGNAL (signalHandleMoved (QPointF)),
124 m_guidelineVisible, SLOT (slotHandleMoved (QPointF)));
125 m_guidelineVisible->removeFromScene (&m_scene);
126 delete m_guidelineVisible;
127 m_guidelineVisible = nullptr;
128
129 // Update Guideline value from cursor position
130 double value = context()->convertScreenPointToGraphCoordinate (posScene);
131
133 value,
134 offscreen,
135 guidelineStateForReplacement);
136 }
137}
virtual QString identifier() const =0
Unique identifier from QGraphicsItem.
GuidelineStateContext * context()
State machine context owned by this class.
void signalGuidelineDragged(QString, double, bool, GuidelineState)
Signal indicating end of Guideline drag.
QString stateName() const
Current state name for debugging and unit test only.
double convertScreenPointToGraphCoordinate(const QPointF &posScreen) const
Convert screen point pair into single graph coordinate.

◆ scene()

QGraphicsScene & GuidelineAbstract::scene ( )

GraphicsScene that owns this class.

Definition at line 139 of file GuidelineAbstract.cpp.

140{
141 return m_scene;
142}

◆ setContext()

void GuidelineAbstract::setContext ( GuidelineStateContext * context)
protected

Create state machine after virtual methods of child classes have been defined.

Definition at line 149 of file GuidelineAbstract.cpp.

150{
151 m_context = context;
152}

◆ setGraphicsItemAcceptHoverEvents()

virtual void GuidelineAbstract::setGraphicsItemAcceptHoverEvents ( bool accept)
pure virtual

Wrapper for QGraphicsItem::setAcceptHoverEvents.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ setGraphicsItemFlags()

virtual void GuidelineAbstract::setGraphicsItemFlags ( QGraphicsItem::GraphicsItemFlags flags)
pure virtual

Wrapper for QGraphicsItem::setFlags.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ setGraphicsItemLine()

virtual void GuidelineAbstract::setGraphicsItemLine ( const QLineF & line)
pure virtual

Wrapper for QGraphicsLineItem::setLine.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ setGraphicsItemPen()

virtual void GuidelineAbstract::setGraphicsItemPen ( const QColor & color,
double lineWidth )
pure virtual

Wrapper for QGraphicsItem::setPen.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ setGraphicsItemVisible()

virtual void GuidelineAbstract::setGraphicsItemVisible ( bool visible)
pure virtual

Wrapper for QGraphicsItem::setVisible.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ setGraphicsItemZValue()

virtual void GuidelineAbstract::setGraphicsItemZValue ( double z)
pure virtual

Wrapper for QGraphicsItem::setZValue.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ signalGuidelineDragged

void GuidelineAbstract::signalGuidelineDragged ( QString ,
double ,
bool ,
GuidelineState  )
signal

Signal indicating end of Guideline drag.

◆ signalHandleMoved

void GuidelineAbstract::signalHandleMoved ( QPointF )
signal

Signal for cloned deployed Guideline from handle Guideline.

◆ slotHandleMoved

void GuidelineAbstract::slotHandleMoved ( QPointF posScreen)
slot

Slot for signal from cloned deployed Guideline from handle Guideline.

Definition at line 154 of file GuidelineAbstract.cpp.

155{
156 // Update geometry
157 updateGeometry (posScreen);
158}
virtual void updateGeometry(double valueGraph)=0
Update the geometry so it passes through the specified coordinate value in graph coordinates.

◆ stateDump()

QString GuidelineAbstract::stateDump ( ) const

Dump of state as a string for debugging only. Context like the QGraphicsItem flags is included.

Definition at line 160 of file GuidelineAbstract.cpp.

161{
162 // This is used by Guidelines::stateDump and GuidelineStateContext::stateDump
163 QString out;
164 QTextStream str (&out);
165
166 str << " " << m_context->stateName ();
167 str << " (";
168 str << (getGraphicsItemSelected() ? "selected" : "unselected") << " ";
169 str << (getGraphicsItemAcceptHover() ? "hoverable" : "unhoverable") << " ";
170 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsFocusable ) != 0 ? "focusable" : "unfocusable") << " ";
171 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsMovable ) != 0 ? "movable" : "unmovable") << " ";
172 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsSelectable) != 0 ? "selectable" : "unselectable") << " ";
173 str << ")";
174
175 return out;
176}
virtual bool getGraphicsItemAcceptHover() const =0
Return true if accepting hover events.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags() const =0
Wraps QGraphicsItem::flags.
virtual bool getGraphicsItemSelected() const =0
Wrapper for QGraphicsItem::isSelected.

◆ stateName()

QString GuidelineAbstract::stateName ( ) const

Current state name for debugging and unit test only.

Definition at line 178 of file GuidelineAbstract.cpp.

179{
180 return m_context->stateName ();
181}

◆ updateActive()

void GuidelineAbstract::updateActive ( bool active)

Update active versus inactive state.

Inactive state applies when DigitizeState is not DigitizeStateSelect, since the Guidelines can help with moving points around. This method is called on DigitizeState transitions. Active is not the same as visibility. When inactive, guidelines ignore hover and click events

◆ updateColor()

virtual void GuidelineAbstract::updateColor ( )
pure virtual

Force a color update.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ updateGeometry() [1/2]

virtual void GuidelineAbstract::updateGeometry ( const QPointF & posScreen)
pure virtual

Update the geometry so it passes through the specified point in screen coordinates.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ updateGeometry() [2/2]

virtual void GuidelineAbstract::updateGeometry ( double valueGraph)
pure virtual

Update the geometry so it passes through the specified coordinate value in graph coordinates.

Implemented in GuidelineEllipse, and GuidelineLine.

◆ updateWithLatestTransformation()

void GuidelineAbstract::updateWithLatestTransformation ( )

Update given Transformation in GuidelineStateContext. This is called after a command has been executed.

Definition at line 183 of file GuidelineAbstract.cpp.

184{
185 m_context->updateWithLatestTransformation ();
186}

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