QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
19
21#include "qgsplotcanvas.h"
22
23#include <QWheelEvent>
24
25#include "moc_qgsplottoolxaxiszoom.cpp"
26
29 , mElevationCanvas( canvas )
30{
31 mToolName = tr( "Zoom X Axis" );
32}
33
35
36QPointF 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
50QPointF 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
67QRectF 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
83void 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
91void 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}
A canvas for elevation profiles.
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
QgsPlotToolXAxisZoom(QgsElevationProfileCanvas *canvas)
Constructor for QgsPlotToolXAxisZoom, with the associated canvas.
~QgsPlotToolXAxisZoom() override
void zoomOutClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
QRectF constrainBounds(const QRectF &sceneBounds) const override
Applies constraints to the overall bounds of the rubber band.
QPointF constrainStartPoint(QPointF scenePoint) const override
Applies constraints to the start point of the zoom rubber band.
QPointF constrainMovePoint(QPointF scenePoint) const override
Applies constraints to a move point of the zoom rubber band.
void zoomInClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
QPointF mRubberBandStartPos
Start position for drag, in scene coordinates.
QgsPlotToolZoom(QgsPlotCanvas *canvas)
Constructor for QgsPlotToolZoom, with the associated canvas.
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
QString mToolName
Translated name of the map tool.