QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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.
 
void deactivated ()
 Emitted when the tool is deactivated.
 

Public Member Functions

 ~QgsPlotTool () override
 
QAction * action ()
 Returns the action associated with the tool or nullptr if no action is associated.
 
virtual void activate ()
 Called when the tool is set as the currently active plot tool.
 
QgsPlotCanvascanvas () const
 Returns the tool's plot canvas.
 
virtual bool canvasToolTipEvent (QHelpEvent *event)
 Tooltip event for overriding.
 
virtual void deactivate ()
 Called when the tool is being deactivated.
 
virtual Qgis::PlotToolFlags flags () const
 Returns the flags for the plot tool.
 
virtual bool gestureEvent (QGestureEvent *event)
 Gesture event for overriding.
 
bool isActive () const
 Returns true if this tool is the current tool active on the plot canvas.
 
virtual void keyPressEvent (QKeyEvent *event)
 Key press event for overriding.
 
virtual void keyReleaseEvent (QKeyEvent *event)
 Key release event for overriding.
 
virtual void plotDoubleClickEvent (QgsPlotMouseEvent *event)
 Mouse double-click event for overriding.
 
virtual void plotMoveEvent (QgsPlotMouseEvent *event)
 Mouse move event for overriding.
 
virtual void plotPressEvent (QgsPlotMouseEvent *event)
 Mouse press event for overriding.
 
virtual void plotReleaseEvent (QgsPlotMouseEvent *event)
 Mouse release event for overriding.
 
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.
 
void setAction (QAction *action)
 Associates an action with this tool.
 
void setCursor (const QCursor &cursor)
 Sets a user defined cursor for use when the tool is active.
 
QString toolName () const
 Returns a user-visible, translated name for the tool.
 
virtual void wheelEvent (QWheelEvent *event)
 Mouse wheel event for overriding.
 

Protected Member Functions

 QgsPlotTool (QgsPlotCanvas *canvas, const QString &name)
 Constructor takes a plot canvas as a parameter.
 
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".
 
QgsPointXY toCanvasCoordinates (const QgsPoint &point) const
 Converts a point in map coordinates to the associated canvas point.
 
QgsPoint toMapCoordinates (const QgsPointXY &point) const
 Converts a point on the canvas to the associated map coordinate.
 

Static Protected Member Functions

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

Protected Attributes

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

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 69 of file qgsplottool.cpp.

◆ QgsPlotTool()

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

Constructor takes a plot canvas as a parameter.

Definition at line 26 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 158 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 80 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 148 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 143 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 54 of file qgsplottool.cpp.

◆ deactivate()

void QgsPlotTool::deactivate ( )
virtual

Called when the tool is being deactivated.

Reimplemented in QgsPlotToolPan, and QgsPlotToolZoom.

Definition at line 90 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 75 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 138 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 98 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 47 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 128 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 133 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 108 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 103 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 113 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 118 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 168 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 153 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 163 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 42 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 37 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 123 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: