QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
Signals | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
QgsPlotTool Class Reference

Abstract base class for all interactive plot tools. More...

#include <qgsplottool.h>

Inheritance diagram for QgsPlotTool:
Inheritance graph
[legend]

Signals

void activated ()
 Emitted when the tool is activated. More...
 
void deactivated ()
 Emitted when the tool is deactivated. More...
 

Public Member Functions

 ~QgsPlotTool () override
 
QAction * action ()
 Returns the action associated with the tool or nullptr if no action is associated. More...
 
virtual void activate ()
 Called when the tool is set as the currently active plot tool. More...
 
QgsPlotCanvascanvas () const
 Returns the tool's plot canvas. More...
 
virtual bool canvasToolTipEvent (QHelpEvent *event)
 Tooltip event for overriding. More...
 
virtual void deactivate ()
 Called when the tool is being deactivated. More...
 
virtual Qgis::PlotToolFlags flags () const
 Returns the flags for the plot tool. More...
 
virtual bool gestureEvent (QGestureEvent *event)
 Gesture event for overriding. More...
 
bool isActive () const
 Returns true if this tool is the current tool active on the plot canvas. More...
 
virtual void keyPressEvent (QKeyEvent *event)
 Key press event for overriding. More...
 
virtual void keyReleaseEvent (QKeyEvent *event)
 Key release event for overriding. More...
 
virtual void plotDoubleClickEvent (QgsPlotMouseEvent *event)
 Mouse double-click event for overriding. More...
 
virtual void plotMoveEvent (QgsPlotMouseEvent *event)
 Mouse move event for overriding. More...
 
virtual void plotPressEvent (QgsPlotMouseEvent *event)
 Mouse press event for overriding. More...
 
virtual void plotReleaseEvent (QgsPlotMouseEvent *event)
 Mouse release event for overriding. More...
 
virtual bool populateContextMenuWithEvent (QMenu *menu, QgsPlotMouseEvent *event)
 Allows the tool to populate and customize the given menu, prior to showing it in response to a right-mouse button click. More...
 
void setAction (QAction *action)
 Associates an action with this tool. More...
 
void setCursor (const QCursor &cursor)
 Sets a user defined cursor for use when the tool is active. More...
 
QString toolName () const
 Returns a user-visible, translated name for the tool. More...
 
virtual void wheelEvent (QWheelEvent *event)
 Mouse wheel event for overriding. More...
 

Protected Member Functions

 QgsPlotTool (QgsPlotCanvas *canvas, const QString &name)
 Constructor takes a plot canvas as a parameter. More...
 
bool isClickAndDrag (QPoint startViewPoint, QPoint endViewPoint) const
 Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a "click and drag". More...
 
QgsPointXY toCanvasCoordinates (const QgsPoint &point) const
 Converts a point in map coordinates to the associated canvas point. More...
 
QgsPoint toMapCoordinates (const QgsPointXY &point) const
 Converts a point on the canvas to the associated map coordinate. More...
 

Static Protected Member Functions

static QPointF constrainPointToRect (QPointF point, const QRectF &rect)
 Constrains a point to force it to fall within the specified rectangle. More...
 

Protected Attributes

QPointer< QAction > mAction
 Optional action associated with tool. More...
 
QgsPlotCanvasmCanvas = nullptr
 The pointer to the canvas. More...
 
QCursor mCursor = Qt::ArrowCursor
 Cursor used by tool. More...
 
QString mToolName
 Translated name of the map tool. More...
 

Detailed Description

Abstract base class for all interactive plot tools.

Plot tools are user tools for manipulating and interacting with a QgsPlotCanvas.

Since
QGIS 3.26

Definition at line 57 of file qgsplottool.h.

Constructor & Destructor Documentation

◆ ~QgsPlotTool()

QgsPlotTool::~QgsPlotTool ( )
override

Definition at line 68 of file qgsplottool.cpp.

◆ QgsPlotTool()

QgsPlotTool::QgsPlotTool ( QgsPlotCanvas canvas,
const QString &  name 
)
protected

Constructor takes a plot canvas as a parameter.

Definition at line 25 of file qgsplottool.cpp.

Member Function Documentation

◆ action()

QAction * QgsPlotTool::action ( )

Returns the action associated with the tool or nullptr if no action is associated.

See also
setAction()

Definition at line 157 of file qgsplottool.cpp.

◆ activate()

void QgsPlotTool::activate ( )
virtual

Called when the tool is set as the currently active plot tool.

Reimplemented in QgsPlotToolTemporaryKeyPan, QgsPlotToolTemporaryMousePan, and QgsPlotToolTemporaryKeyZoom.

Definition at line 79 of file qgsplottool.cpp.

◆ activated

void QgsPlotTool::activated ( )
signal

Emitted when the tool is activated.

◆ canvas()

QgsPlotCanvas * QgsPlotTool::canvas ( ) const

Returns the tool's plot canvas.

Definition at line 147 of file qgsplottool.cpp.

◆ canvasToolTipEvent()

bool QgsPlotTool::canvasToolTipEvent ( QHelpEvent *  event)
virtual

Tooltip event for overriding.

Returns true if the event was handled by the tool and should not be propagated further.

Definition at line 142 of file qgsplottool.cpp.

◆ constrainPointToRect()

QPointF QgsPlotTool::constrainPointToRect ( QPointF  point,
const QRectF &  rect 
)
staticprotected

Constrains a point to force it to fall within the specified rectangle.

Definition at line 53 of file qgsplottool.cpp.

◆ deactivate()

void QgsPlotTool::deactivate ( )
virtual

Called when the tool is being deactivated.

Reimplemented in QgsPlotToolPan, and QgsPlotToolZoom.

Definition at line 89 of file qgsplottool.cpp.

◆ deactivated

void QgsPlotTool::deactivated ( )
signal

Emitted when the tool is deactivated.

◆ flags()

Qgis::PlotToolFlags QgsPlotTool::flags ( ) const
virtual

Returns the flags for the plot tool.

Reimplemented in QgsPlotToolPan.

Definition at line 74 of file qgsplottool.cpp.

◆ gestureEvent()

bool QgsPlotTool::gestureEvent ( QGestureEvent *  event)
virtual

Gesture event for overriding.

Returns true if the event was handled by the tool and should not be propagated further.

Definition at line 137 of file qgsplottool.cpp.

◆ isActive()

bool QgsPlotTool::isActive ( ) const

Returns true if this tool is the current tool active on the plot canvas.

Definition at line 97 of file qgsplottool.cpp.

◆ isClickAndDrag()

bool QgsPlotTool::isClickAndDrag ( QPoint  startViewPoint,
QPoint  endViewPoint 
) const
protected

Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewPoint should be considered a "click and drag".

If false is returned, the operation should be instead treated as just a click on startViewPoint.

Definition at line 46 of file qgsplottool.cpp.

◆ keyPressEvent()

void QgsPlotTool::keyPressEvent ( QKeyEvent *  event)
virtual

Key press event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Reimplemented in QgsPlotToolZoom, and QgsPlotToolTemporaryKeyZoom.

Definition at line 127 of file qgsplottool.cpp.

◆ keyReleaseEvent()

void QgsPlotTool::keyReleaseEvent ( QKeyEvent *  event)
virtual

Key release event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Reimplemented in QgsPlotToolZoom, QgsPlotToolTemporaryKeyPan, and QgsPlotToolTemporaryKeyZoom.

Definition at line 132 of file qgsplottool.cpp.

◆ plotDoubleClickEvent()

void QgsPlotTool::plotDoubleClickEvent ( QgsPlotMouseEvent event)
virtual

Mouse double-click event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Definition at line 107 of file qgsplottool.cpp.

◆ plotMoveEvent()

void QgsPlotTool::plotMoveEvent ( QgsPlotMouseEvent event)
virtual

Mouse move event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Reimplemented in QgsPlotToolPan, QgsPlotToolZoom, QgsPlotToolTemporaryKeyPan, and QgsPlotToolTemporaryMousePan.

Definition at line 102 of file qgsplottool.cpp.

◆ plotPressEvent()

void QgsPlotTool::plotPressEvent ( QgsPlotMouseEvent event)
virtual

Mouse press event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Reimplemented in QgsPlotToolPan, and QgsPlotToolZoom.

Definition at line 112 of file qgsplottool.cpp.

◆ plotReleaseEvent()

void QgsPlotTool::plotReleaseEvent ( QgsPlotMouseEvent event)
virtual

Mouse release event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Reimplemented in QgsPlotToolPan, QgsPlotToolZoom, QgsPlotToolTemporaryMousePan, and QgsPlotToolTemporaryKeyZoom.

Definition at line 117 of file qgsplottool.cpp.

◆ populateContextMenuWithEvent()

bool QgsPlotTool::populateContextMenuWithEvent ( QMenu *  menu,
QgsPlotMouseEvent event 
)
virtual

Allows the tool to populate and customize the given menu, prior to showing it in response to a right-mouse button click.

menu will be initially populated with a set of default, generic actions. Any new actions added to the menu should be correctly parented to menu.

A pointer to the plot mouse event can be provided to allow particular behavior depending on the plot tool.

This method can return true to inform the caller that the menu was effectively populated.

The default implementation does nothing and returns false.

Note
The context menu is only shown when the ShowContextMenu flag is present in flags().

Definition at line 167 of file qgsplottool.cpp.

◆ setAction()

void QgsPlotTool::setAction ( QAction *  action)

Associates an action with this tool.

When the setTool method of QgsPlotCanvas is called the action's state will be set to on. Usually this will cause a toolbutton to appear pressed in and the previously used toolbutton to pop out.

See also
action()

Definition at line 152 of file qgsplottool.cpp.

◆ setCursor()

void QgsPlotTool::setCursor ( const QCursor &  cursor)

Sets a user defined cursor for use when the tool is active.

Definition at line 162 of file qgsplottool.cpp.

◆ toCanvasCoordinates()

QgsPointXY QgsPlotTool::toCanvasCoordinates ( const QgsPoint point) const
protected

Converts a point in map coordinates to the associated canvas point.

May return an empty point if the map point cannot be converted to a canvas point.

Definition at line 41 of file qgsplottool.cpp.

◆ toMapCoordinates()

QgsPoint QgsPlotTool::toMapCoordinates ( const QgsPointXY point) const
protected

Converts a point on the canvas to the associated map coordinate.

May return an empty point if the canvas point cannot be converted to a map point.

Definition at line 36 of file qgsplottool.cpp.

◆ toolName()

QString QgsPlotTool::toolName ( ) const
inline

Returns a user-visible, translated name for the tool.

Definition at line 87 of file qgsplottool.h.

◆ wheelEvent()

void QgsPlotTool::wheelEvent ( QWheelEvent *  event)
virtual

Mouse wheel event for overriding.

The default implementation does nothing. When subclasses implement this method and have acted on the event, they must explicitly call event->accept() to prevent the event from being passed on to other widgets.

Definition at line 122 of file qgsplottool.cpp.

Member Data Documentation

◆ mAction

QPointer< QAction > QgsPlotTool::mAction
protected

Optional action associated with tool.

Definition at line 273 of file qgsplottool.h.

◆ mCanvas

QgsPlotCanvas* QgsPlotTool::mCanvas = nullptr
protected

The pointer to the canvas.

Definition at line 267 of file qgsplottool.h.

◆ mCursor

QCursor QgsPlotTool::mCursor = Qt::ArrowCursor
protected

Cursor used by tool.

Definition at line 276 of file qgsplottool.h.

◆ mToolName

QString QgsPlotTool::mToolName
protected

Translated name of the map tool.

Definition at line 270 of file qgsplottool.h.


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