QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 "qgsapplication.h"
20#include "qgsplotmouseevent.h"
21#include "qgsplotcanvas.h"
22#include "qgsplotrubberband.h"
24#include <QWheelEvent>
25
27 : QgsPlotToolZoom( canvas )
28 , mElevationCanvas( canvas )
29{
30 mToolName = tr( "Zoom X Axis" );
31}
32
34
35QPointF QgsPlotToolXAxisZoom::constrainStartPoint( QPointF scenePoint ) const
36{
37 // force the rubber band to take the whole vertical area
38 QRectF plotArea = mElevationCanvas->plotArea();
39 return QPointF( scenePoint.x(), plotArea.top() );
40}
41
42QPointF QgsPlotToolXAxisZoom::constrainMovePoint( QPointF scenePoint ) const
43{
44 const QRectF plotArea = mElevationCanvas->plotArea();
45 // force the rubber band to take the whole vertical area
46 return QPointF( scenePoint.x(), plotArea.bottom() );
47}
48
49QRectF QgsPlotToolXAxisZoom::constrainBounds( const QRectF &sceneBounds ) const
50{
51 const QRectF plotArea = mElevationCanvas->plotArea();
52 // retain current vertical rect
53 return QRectF( sceneBounds.left(), plotArea.top(), sceneBounds.width(), plotArea.height() );
54}
55
56void QgsPlotToolXAxisZoom::zoomOutClickOn( QPointF scenePoint )
57{
58 //just a click, so zoom to clicked point and recenter
59 const QRectF plotArea = mElevationCanvas->plotArea();
60 canvas()->centerPlotOn( scenePoint.x(), plotArea.center().y() );
61 mElevationCanvas->scalePlot( 0.5, 1 );
62}
63
64void QgsPlotToolXAxisZoom::zoomInClickOn( QPointF scenePoint )
65{
66 //just a click, so zoom to clicked point and recenter
67 const QRectF plotArea = mElevationCanvas->plotArea();
68 canvas()->centerPlotOn( scenePoint.x(), plotArea.center().y() );
69 mElevationCanvas->scalePlot( 2.0, 1 );
70}
A canvas for elevation profiles.
void scalePlot(double factor) override
Scales the plot by a specified scale factor.
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.
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
QString mToolName
Translated name of the map tool.
Definition: qgsplottool.h:270