QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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#include "qgsplotcanvas.h"
21#include <QWheelEvent>
22
24 : QgsPlotToolZoom( canvas )
25 , mElevationCanvas( canvas )
26{
27 mToolName = tr( "Zoom X Axis" );
28}
29
31
32QPointF QgsPlotToolXAxisZoom::constrainStartPoint( QPointF scenePoint ) const
33{
34 if ( mElevationCanvas->lockAxisScales() )
35 {
36 return scenePoint;
37 }
38 else
39 {
40 // force the rubber band to take the whole vertical area
41 QRectF plotArea = mElevationCanvas->plotArea();
42 return QPointF( scenePoint.x(), plotArea.top() );
43 }
44}
45
46QPointF QgsPlotToolXAxisZoom::constrainMovePoint( QPointF scenePoint ) const
47{
48 const QRectF plotArea = mElevationCanvas->plotArea();
49 if ( mElevationCanvas->lockAxisScales() )
50 {
51 const double selectedDistanceRange = std::fabs( scenePoint.x() - mRubberBandStartPos.x() );
52 // ensure the same aspect ratio is retained
53 const double calculatedElevationRange = plotArea.height() / plotArea.width() * selectedDistanceRange;
54 return QPointF( scenePoint.x(), mRubberBandStartPos.y() + calculatedElevationRange );
55 }
56 else
57 {
58 // force the rubber band to take the whole vertical area
59 return QPointF( scenePoint.x(), plotArea.bottom() );
60 }
61}
62
63QRectF QgsPlotToolXAxisZoom::constrainBounds( const QRectF &sceneBounds ) const
64{
65 const QRectF plotArea = mElevationCanvas->plotArea();
66
67 if ( mElevationCanvas->lockAxisScales() )
68 {
69 // constraint has already been applied
70 return sceneBounds;
71 }
72 else
73 {
74 // retain current vertical rect
75 return QRectF( sceneBounds.left(), plotArea.top(), sceneBounds.width(), plotArea.height() );
76 }
77}
78
79void QgsPlotToolXAxisZoom::zoomOutClickOn( QPointF scenePoint )
80{
81 //just a click, so zoom to clicked point and recenter
82 const QRectF plotArea = mElevationCanvas->plotArea();
83 canvas()->centerPlotOn( scenePoint.x(), plotArea.center().y() );
84 mElevationCanvas->scalePlot( 0.5, 1 );
85}
86
87void QgsPlotToolXAxisZoom::zoomInClickOn( QPointF scenePoint )
88{
89 //just a click, so zoom to clicked point and recenter
90 const QRectF plotArea = mElevationCanvas->plotArea();
91 canvas()->centerPlotOn( scenePoint.x(), plotArea.center().y() );
92 mElevationCanvas->scalePlot( 2.0, 1 );
93}
A canvas for elevation profiles.
void scalePlot(double factor) override
Scales the plot by a specified scale factor.
bool lockAxisScales() const
Returns true if the distance and elevation scales are locked to each other.
QRectF plotArea() const
Returns the interior rectangle representing the surface of the plot, in canvas coordinates.
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.
Plot tool for zooming into and out of the plot.
QPointF mRubberBandStartPos
Start position for drag, in scene coordinates.
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
QString mToolName
Translated name of the map tool.