QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
20#include "qgsplotcanvas.h"
21#include "qgsplotmouseevent.h"
22
23#include "moc_qgsplottoolpan.cpp"
24
26 : QgsPlotTool( canvas, tr( "Pan" ) )
27{
28 setCursor( Qt::OpenHandCursor );
29}
30
35
37{
38 if ( !mIsPanning )
39 {
40 event->ignore();
41 return;
42 }
43
44 mCanvas->panContentsBy( event->x() - mLastMousePos.x(), event->y() - mLastMousePos.y() );
45 mLastMousePos = event->pos();
46}
47
49{
50 mMousePressStartPos = event->pos();
51
52 if ( event->button() != Qt::LeftButton )
53 {
54 event->ignore();
55 return;
56 }
57
58 mIsPanning = true;
59 mLastMousePos = event->pos();
60 mCanvas->viewport()->setCursor( Qt::ClosedHandCursor );
61}
62
64{
65 const bool clickOnly = !isClickAndDrag( mMousePressStartPos, event->pos() );
66
67 if ( event->button() == Qt::MiddleButton && clickOnly )
68 {
69 //middle mouse button click = recenter on point
70 mCanvas->centerPlotOn( event->pos().x(), event->pos().y() );
71 return;
72 }
73
74 if ( !mIsPanning || event->button() != Qt::LeftButton )
75 {
76 event->ignore();
77 return;
78 }
79
80 mIsPanning = false;
81 canvas()->viewport()->setCursor( Qt::OpenHandCursor );
82}
83
85{
86 mIsPanning = false;
88}
QFlags< PlotToolFlag > PlotToolFlags
Definition qgis.h:4112
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
Definition qgis.h:4109
Plot canvas is a class for displaying interactive 2d charts and plots.
A mouse event which is the result of a user interaction with 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.
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.
QgsPlotTool(QgsPlotCanvas *canvas, const QString &name)
Constructor takes a plot canvas as a parameter.
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...