QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
plot
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
25
QgsPlotToolPan::QgsPlotToolPan
(
QgsPlotCanvas
*
canvas
)
26
:
QgsPlotTool
(
canvas
, tr(
"Pan"
) )
27
{
28
setCursor
( Qt::OpenHandCursor );
29
}
30
31
Qgis::PlotToolFlags
QgsPlotToolPan::flags
()
const
32
{
33
return
Qgis::PlotToolFlag::ShowContextMenu
;
34
}
35
36
void
QgsPlotToolPan::plotMoveEvent
(
QgsPlotMouseEvent
*event )
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
48
void
QgsPlotToolPan::plotPressEvent
(
QgsPlotMouseEvent
*event )
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
63
void
QgsPlotToolPan::plotReleaseEvent
(
QgsPlotMouseEvent
*event )
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
84
void
QgsPlotToolPan::deactivate
()
85
{
86
mIsPanning =
false
;
87
QgsPlotTool::deactivate
();
88
}
Qgis::PlotToolFlags
QFlags< PlotToolFlag > PlotToolFlags
Definition
qgis.h:4387
Qgis::PlotToolFlag::ShowContextMenu
@ ShowContextMenu
Show a context menu when right-clicking with the tool.
Definition
qgis.h:4384
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition
qgsplotcanvas.h:55
QgsPlotMouseEvent
A mouse event which is the result of a user interaction with a QgsPlotCanvas.
Definition
qgsplotmouseevent.h:40
QgsPlotToolPan::plotReleaseEvent
void plotReleaseEvent(QgsPlotMouseEvent *event) override
Mouse release event for overriding.
Definition
qgsplottoolpan.cpp:63
QgsPlotToolPan::plotPressEvent
void plotPressEvent(QgsPlotMouseEvent *event) override
Mouse press event for overriding.
Definition
qgsplottoolpan.cpp:48
QgsPlotToolPan::QgsPlotToolPan
QgsPlotToolPan(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolPan, with the associated canvas.
Definition
qgsplottoolpan.cpp:25
QgsPlotToolPan::deactivate
void deactivate() override
Called when the tool is being deactivated.
Definition
qgsplottoolpan.cpp:84
QgsPlotToolPan::flags
Qgis::PlotToolFlags flags() const override
Returns the flags for the plot tool.
Definition
qgsplottoolpan.cpp:31
QgsPlotToolPan::plotMoveEvent
void plotMoveEvent(QgsPlotMouseEvent *event) override
Mouse move event for overriding.
Definition
qgsplottoolpan.cpp:36
QgsPlotTool::canvas
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
Definition
qgsplottool.cpp:147
QgsPlotTool::deactivate
virtual void deactivate()
Called when the tool is being deactivated.
Definition
qgsplottool.cpp:89
QgsPlotTool::mCanvas
QgsPlotCanvas * mCanvas
The pointer to the canvas.
Definition
qgsplottool.h:265
QgsPlotTool::QgsPlotTool
QgsPlotTool(QgsPlotCanvas *canvas, const QString &name)
Constructor takes a plot canvas as a parameter.
Definition
qgsplottool.cpp:28
QgsPlotTool::setCursor
void setCursor(const QCursor &cursor)
Sets a user defined cursor for use when the tool is active.
Definition
qgsplottool.cpp:162
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
qgsplotcanvas.h
qgsplotmouseevent.h
qgsplottoolpan.h
Generated on
for QGIS API Documentation by
1.17.0