QGIS API Documentation 3.38.0-Grenoble (exported)
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 "qgsplotcanvas.h"
20#include "qgsplotmouseevent.h"
21
23 : QgsPlotTool( canvas, tr( "Pan" ) )
24{
25 setCursor( Qt::OpenHandCursor );
26}
27
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}
QFlags< PlotToolFlag > PlotToolFlags
Definition qgis.h:3533
@ 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...