QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
28 Qgis::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 }
qgsplotmouseevent.h
QgsPlotToolPan::deactivate
void deactivate() override
Called when the tool is being deactivated.
Definition: qgsplottoolpan.cpp:81
QgsPlotTool::setCursor
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
Definition: qgsplottool.cpp:162
qgsplotcanvas.h
QgsPlotTool::deactivate
virtual void deactivate()
Called when the tool is being deactivated.
Definition: qgsplottool.cpp:89
QgsPlotToolPan::plotReleaseEvent
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
Definition: qgsplottoolpan.cpp:60
qgsplottoolpan.h
QgsPlotToolPan::plotPressEvent
void plotPressEvent(QgsPlotMouseEvent *event) override
Mouse press event for overriding.
Definition: qgsplottoolpan.cpp:45
QgsPlotCanvas::centerPlotOn
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
Definition: qgsplotcanvas.cpp:282
QgsPlotTool::mCanvas
QgsPlotCanvas * mCanvas
The pointer to the canvas.
Definition: qgsplottool.h:267
QgsPlotToolPan::plotMoveEvent
void plotMoveEvent(QgsPlotMouseEvent *event) override
Mouse move event for overriding.
Definition: qgsplottoolpan.cpp:33
QgsPlotTool
Abstract base class for all interactive plot tools.
Definition: qgsplottool.h:57
Qgis::PlotToolFlag::ShowContextMenu
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
QgsPlotToolPan::flags
Qgis::PlotToolFlags flags() const override
Returns the flags for the plot tool.
Definition: qgsplottoolpan.cpp:28
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPlotCanvas::panContentsBy
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
Definition: qgsplotcanvas.cpp:277
QgsPlotMouseEvent
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
Definition: qgsplotmouseevent.h:39
QgsPlotTool::canvas
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
Definition: qgsplottool.cpp:147
QgsPlotTool::isClickAndDrag
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
QgsPlotToolPan::QgsPlotToolPan
QgsPlotToolPan(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolPan, with the associated canvas.
Definition: qgsplottoolpan.cpp:22