QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
plot
qgsplottoolxaxiszoom.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsplottoolxaxiszoom.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 "
qgsplottoolxaxiszoom.h
"
19
20
#include "
qgselevationprofilecanvas.h
"
21
#include "
qgsplotcanvas.h
"
22
23
#include <QWheelEvent>
24
25
#include "moc_qgsplottoolxaxiszoom.cpp"
26
27
QgsPlotToolXAxisZoom::QgsPlotToolXAxisZoom
(
QgsElevationProfileCanvas
*
canvas
)
28
:
QgsPlotToolZoom
(
canvas
)
29
, mElevationCanvas(
canvas
)
30
{
31
mToolName
= tr(
"Zoom X Axis"
);
32
}
33
34
QgsPlotToolXAxisZoom::~QgsPlotToolXAxisZoom
() =
default
;
35
36
QPointF
QgsPlotToolXAxisZoom::constrainStartPoint
( QPointF scenePoint )
const
37
{
38
if
( mElevationCanvas->lockAxisScales() )
39
{
40
return
scenePoint;
41
}
42
else
43
{
44
// force the rubber band to take the whole vertical area
45
QRectF plotArea = mElevationCanvas->plotArea();
46
return
QPointF( scenePoint.x(), plotArea.top() );
47
}
48
}
49
50
QPointF
QgsPlotToolXAxisZoom::constrainMovePoint
( QPointF scenePoint )
const
51
{
52
const
QRectF plotArea = mElevationCanvas->plotArea();
53
if
( mElevationCanvas->lockAxisScales() )
54
{
55
const
double
selectedDistanceRange = std::fabs( scenePoint.x() -
mRubberBandStartPos
.x() );
56
// ensure the same aspect ratio is retained
57
const
double
calculatedElevationRange = plotArea.height() / plotArea.width() * selectedDistanceRange;
58
return
QPointF( scenePoint.x(),
mRubberBandStartPos
.y() + calculatedElevationRange );
59
}
60
else
61
{
62
// force the rubber band to take the whole vertical area
63
return
QPointF( scenePoint.x(), plotArea.bottom() );
64
}
65
}
66
67
QRectF
QgsPlotToolXAxisZoom::constrainBounds
(
const
QRectF &sceneBounds )
const
68
{
69
const
QRectF plotArea = mElevationCanvas->plotArea();
70
71
if
( mElevationCanvas->lockAxisScales() )
72
{
73
// constraint has already been applied
74
return
sceneBounds;
75
}
76
else
77
{
78
// retain current vertical rect
79
return
QRectF( sceneBounds.left(), plotArea.top(), sceneBounds.width(), plotArea.height() );
80
}
81
}
82
83
void
QgsPlotToolXAxisZoom::zoomOutClickOn
( QPointF scenePoint )
84
{
85
//just a click, so zoom to clicked point and recenter
86
const
QRectF plotArea = mElevationCanvas->plotArea();
87
canvas
()->
centerPlotOn
( scenePoint.x(), plotArea.center().y() );
88
mElevationCanvas->scalePlot( 0.5, 1 );
89
}
90
91
void
QgsPlotToolXAxisZoom::zoomInClickOn
( QPointF scenePoint )
92
{
93
//just a click, so zoom to clicked point and recenter
94
const
QRectF plotArea = mElevationCanvas->plotArea();
95
canvas
()->
centerPlotOn
( scenePoint.x(), plotArea.center().y() );
96
mElevationCanvas->scalePlot( 2.0, 1 );
97
}
QgsElevationProfileCanvas
A canvas for elevation profiles.
Definition
qgselevationprofilecanvas.h:49
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
QgsPlotToolXAxisZoom::QgsPlotToolXAxisZoom
QgsPlotToolXAxisZoom(QgsElevationProfileCanvas *canvas)
Constructor for QgsPlotToolXAxisZoom, with the associated canvas.
Definition
qgsplottoolxaxiszoom.cpp:27
QgsPlotToolXAxisZoom::~QgsPlotToolXAxisZoom
~QgsPlotToolXAxisZoom() override
QgsPlotToolXAxisZoom::zoomOutClickOn
void zoomOutClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
Definition
qgsplottoolxaxiszoom.cpp:83
QgsPlotToolXAxisZoom::constrainBounds
QRectF constrainBounds(const QRectF &sceneBounds) const override
Applies constraints to the overall bounds of the rubber band.
Definition
qgsplottoolxaxiszoom.cpp:67
QgsPlotToolXAxisZoom::constrainStartPoint
QPointF constrainStartPoint(QPointF scenePoint) const override
Applies constraints to the start point of the zoom rubber band.
Definition
qgsplottoolxaxiszoom.cpp:36
QgsPlotToolXAxisZoom::constrainMovePoint
QPointF constrainMovePoint(QPointF scenePoint) const override
Applies constraints to a move point of the zoom rubber band.
Definition
qgsplottoolxaxiszoom.cpp:50
QgsPlotToolXAxisZoom::zoomInClickOn
void zoomInClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
Definition
qgsplottoolxaxiszoom.cpp:91
QgsPlotToolZoom::mRubberBandStartPos
QPointF mRubberBandStartPos
Start position for drag, in scene coordinates.
Definition
qgsplottoolzoom.h:96
QgsPlotToolZoom::QgsPlotToolZoom
QgsPlotToolZoom(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolZoom, with the associated canvas.
Definition
qgsplottoolzoom.cpp:29
QgsPlotTool::canvas
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
Definition
qgsplottool.cpp:147
QgsPlotTool::mToolName
QString mToolName
Translated name of the map tool.
Definition
qgsplottool.h:268
qgselevationprofilecanvas.h
qgsplotcanvas.h
qgsplottoolxaxiszoom.h
Generated on
for QGIS API Documentation by
1.17.0