Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | Protected Member Functions | List of all members
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 29 of file GuidelineAbstract.cpp.

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

◆ ~GuidelineAbstract()

GuidelineAbstract::~GuidelineAbstract ( )

Definition at line 36 of file GuidelineAbstract.cpp.

37{
38 delete m_context;
39}

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 41 of file GuidelineAbstract.cpp.

42{
43 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::bindGuidelineVisibleToInvisible";
44
45 m_guidelineVisible = guidelineVisible;
46
49}
const int INNER_RADIUS_MIN
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 51 of file GuidelineAbstract.cpp.

52{
53 return m_context;
54}

◆ context() [2/2]

const GuidelineStateContext * GuidelineAbstract::context ( ) const
protected

State machine context owned by this class as a const.

Definition at line 56 of file GuidelineAbstract.cpp.

57{
58 return m_context;
59}

◆ 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 61 of file GuidelineAbstract.cpp.

62{
63 m_context->handleActiveChange (active);
64}
void handleActiveChange(bool active)
DigitizeState change so active status may (or may not) be toggled.

◆ handleGuidelineMode()

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

User toggled Guideline visibility and/or locked mode.

Definition at line 66 of file GuidelineAbstract.cpp.

68{
69 m_context->handleGuidelineMode (visible,
70 locked);
71}
void handleGuidelineMode(bool visibile, bool locked)
User toggled Guideline visibility and/or locked mode.

◆ handleHoverEnterEvent()

void GuidelineAbstract::handleHoverEnterEvent ( )

Highlight this Guideline upon hover enter.

Definition at line 73 of file GuidelineAbstract.cpp.

74{
75 m_context->handleHoverEnterEvent ();
76}
void handleHoverEnterEvent()
If transparent then make visible when hover starts.

◆ handleHoverLeaveEvent()

void GuidelineAbstract::handleHoverLeaveEvent ( )

Unset highlighting triggered by hover enter.

Definition at line 78 of file GuidelineAbstract.cpp.

79{
80 m_context->handleHoverLeaveEvent ();
81}
void handleHoverLeaveEvent()
If previously transparent before hover enter then make transparent again.

◆ handleMouseMoveEvent()

void GuidelineAbstract::handleMouseMoveEvent ( const QPointF & posScene)

Forward movements to visible Guideline.

Definition at line 83 of file GuidelineAbstract.cpp.

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

◆ handleMousePressEvent()

void GuidelineAbstract::handleMousePressEvent ( const QPointF & posScene)

Forward press event to state machine.

Definition at line 95 of file GuidelineAbstract.cpp.

96{
97 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMousePressEvent";
98
99 m_context->handleMousePress(posScene);
100}
void handleMousePress(const QPointF &posScene)
At the start of dragging, convert the original Guideline into an invisible handle and visible slaved ...
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ handleMouseReleaseEvent()

void GuidelineAbstract::handleMouseReleaseEvent ( const QPointF & posScene)

Cleanup after being dragged.

Definition at line 102 of file GuidelineAbstract.cpp.

103{
104 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMouseReleaseEvent";
105
106 m_context->handleMouseRelease (posScene);
107}
void handleMouseRelease(const QPointF &posScene)
At the end of dragging, clone the Guideline that owns the state machine where these states live.

◆ 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 145 of file GuidelineAbstract.cpp.

146{
147 return m_context->posCursorGraph ();
148}
QPointF posCursorGraph() const
Get method for current cursor coordinate when object was last created/dragged.

◆ 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 109 of file GuidelineAbstract.cpp.

111{
112 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines"
113 << " keeping identifier=" << identifier().toLatin1().data()
114 << " in " << stateName ().toLatin1().data();
115
116 if (m_guidelineVisible != nullptr) {
117
118 // If scene position is off-screen then user is removing the visible Guideline
119 bool offscreen = !m_scene.sceneRect().contains (posScene);
120
121 // Remove transient Guideline, which was never registered with Guidelines
122 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines identifierDeleting="
123 << m_guidelineVisible->identifier().toLatin1().data();
125 m_guidelineVisible, SLOT (slotHandleMoved (QPointF)));
126 m_guidelineVisible->removeFromScene (&m_scene);
127 delete m_guidelineVisible;
128 m_guidelineVisible = nullptr;
129
130 // Update Guideline value from cursor position
132
134 value,
135 offscreen,
137 }
138}
virtual QString identifier() const =0
Unique identifier from QGraphicsItem.
virtual void removeFromScene(QGraphicsScene *scene)=0
Make graphics item remove itself from the scene.
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 140 of file GuidelineAbstract.cpp.

141{
142 return m_scene;
143}

◆ setContext()

void GuidelineAbstract::setContext ( GuidelineStateContext * context)
protected

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

Definition at line 150 of file GuidelineAbstract.cpp.

151{
152 m_context = context;
153}

◆ 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 155 of file GuidelineAbstract.cpp.

156{
157 // Update geometry
158 updateGeometry (posScreen);
159}
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 161 of file GuidelineAbstract.cpp.

162{
163 // This is used by Guidelines::stateDump and GuidelineStateContext::stateDump
164 QString out;
166
167 str << " " << m_context->stateName ();
168 str << " (";
169 str << (getGraphicsItemSelected() ? "selected" : "unselected") << " ";
170 str << (getGraphicsItemAcceptHover() ? "hoverable" : "unhoverable") << " ";
171 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsFocusable ) != 0 ? "focusable" : "unfocusable") << " ";
172 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsMovable ) != 0 ? "movable" : "unmovable") << " ";
173 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsSelectable) != 0 ? "selectable" : "unselectable") << " ";
174 str << ")";
175
176 return out;
177}
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.
QString stateName() const
State as a string for debugging only.

◆ stateName()

QString GuidelineAbstract::stateName ( ) const

Current state name for debugging and unit test only.

Definition at line 179 of file GuidelineAbstract.cpp.

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

◆ 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 184 of file GuidelineAbstract.cpp.

185{
186 m_context->updateWithLatestTransformation ();
187}
void updateWithLatestTransformation()
Update given Transformation in GuidelineStateContext.

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