QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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 "moc_qgsplottoolpan.cpp"
20#include "qgsplotcanvas.h"
21#include "qgsplotmouseevent.h"
22
24 : QgsPlotTool( canvas, tr( "Pan" ) )
25{
26 setCursor( Qt::OpenHandCursor );
27}
28
33
35{
36 if ( !mIsPanning )
37 {
38 event->ignore();
39 return;
40 }
41
42 mCanvas->panContentsBy( event->x() - mLastMousePos.x(), event->y() - mLastMousePos.y() );
43 mLastMousePos = event->pos();
44}
45
47{
48 mMousePressStartPos = event->pos();
49
50 if ( event->button() != Qt::LeftButton )
51 {
52 event->ignore();
53 return;
54 }
55
56 mIsPanning = true;
57 mLastMousePos = event->pos();
58 mCanvas->viewport()->setCursor( Qt::ClosedHandCursor );
59}
60
62{
63 const bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );
64
65 if ( event->button() == Qt::MiddleButton && clickOnly )
66 {
67 //middle mouse button click = recenter on point
68 mCanvas->centerPlotOn( event->pos().x(), event->pos().y() );
69 return;
70 }
71
72 if ( !mIsPanning || event->button() != Qt::LeftButton )
73 {
74 event->ignore();
75 return;
76 }
77
78 mIsPanning = false;
79 canvas()->viewport()->setCursor( Qt::OpenHandCursor );
80}
81
83{
84 mIsPanning = false;
86}
QFlags< PlotToolFlag > PlotToolFlags
Definition qgis.h:3874
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
Plot canvas is a class for displaying interactive 2d charts and plots.
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.
QgsPlotCanvas * mCanvas
The pointer to the canvas.
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...