QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsplottoolpan.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplottoolpan.cpp
3 ---------------
4 begin : March 2022
5 copyright : (C) 2022 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsplottoolpan.h"
19#include "qgsplotcanvas.h"
20#include "qgsplotmouseevent.h"
21
23 : QgsPlotTool( canvas, tr( "Pan" ) )
24{
25 setCursor( Qt::OpenHandCursor );
26}
27
28Qgis::PlotToolFlags QgsPlotToolPan::flags() const
29{
31}
32
34{
35 if ( !mIsPanning )
36 {
37 event->ignore();
38 return;
39 }
40
41 mCanvas->panContentsBy( event->x() - mLastMousePos.x(), event->y() - mLastMousePos.y() );
42 mLastMousePos = event->pos();
43}
44
46{
47 mMousePressStartPos = event->pos();
48
49 if ( event->button() != Qt::LeftButton )
50 {
51 event->ignore();
52 return;
53 }
54
55 mIsPanning = true;
56 mLastMousePos = event->pos();
57 mCanvas->viewport()->setCursor( Qt::ClosedHandCursor );
58}
59
61{
62 const bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );
63
64 if ( event->button() == Qt::MiddleButton && clickOnly )
65 {
66 //middle mouse button click = recenter on point
67 mCanvas->centerPlotOn( event->pos().x(), event->pos().y() );
68 return;
69 }
70
71 if ( !mIsPanning || event->button() != Qt::LeftButton )
72 {
73 event->ignore();
74 return;
75 }
76
77 mIsPanning = false;
78 canvas()->viewport()->setCursor( Qt::OpenHandCursor );
79}
80
82{
83 mIsPanning = false;
85}
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:54
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
void plotPressEvent(QgsPlotMouseEvent *event) override
Mouse press event for overriding.
QgsPlotToolPan(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolPan, with the associated canvas.
void deactivate() override
Called when the tool is being deactivated.
Qgis::PlotToolFlags flags() const override
Returns the flags for the plot tool.
void plotMoveEvent(QgsPlotMouseEvent *event) override
Mouse move event for overriding.
Abstract base class for all interactive plot tools.
Definition: qgsplottool.h:58
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
virtual void deactivate()
Called when the tool is being deactivated.
Definition: qgsplottool.cpp:89
QgsPlotCanvas * mCanvas
The pointer to the canvas.
Definition: qgsplottool.h:267
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
bool isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const
Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewP...
Definition: qgsplottool.cpp:46