QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #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 
35 QPointF 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 
42 QPointF 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 
49 QRectF 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 
56 void 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 
64 void 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 }
qgsplotmouseevent.h
QgsElevationProfileCanvas::scalePlot
void scalePlot(double factor) override
Scales the plot by a specified scale factor.
Definition: qgselevationprofilecanvas.cpp:408
qgsplotcanvas.h
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
qgsapplication.h
QgsElevationProfileCanvas
A canvas for elevation profiles.
Definition: qgselevationprofilecanvas.h:45
QgsPlotTool::mToolName
QString mToolName
Translated name of the map tool.
Definition: qgsplottool.h:270
QgsElevationProfileCanvas::plotArea
QRectF plotArea() const
Returns the interior rectangle representing the surface of the plot, in canvas coordinates.
Definition: qgselevationprofilecanvas.cpp:633
QgsPlotToolXAxisZoom::zoomInClickOn
void zoomInClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
Definition: qgsplottoolxaxiszoom.cpp:64
QgsPlotToolXAxisZoom::~QgsPlotToolXAxisZoom
~QgsPlotToolXAxisZoom() override
QgsPlotToolXAxisZoom::zoomOutClickOn
void zoomOutClickOn(QPointF scenePoint) override
Handles a zoom out click on the given point.
Definition: qgsplottoolxaxiszoom.cpp:56
qgselevationprofilecanvas.h
QgsPlotToolXAxisZoom::constrainBounds
QRectF constrainBounds(const QRectF &sceneBounds) const override
Applies constraints to the overall bounds of the rubber band.
Definition: qgsplottoolxaxiszoom.cpp:49
QgsPlotToolXAxisZoom::constrainMovePoint
QPointF constrainMovePoint(QPointF scenePoint) const override
Applies constraints to a move point of the zoom rubber band.
Definition: qgsplottoolxaxiszoom.cpp:42
QgsPlotToolXAxisZoom::constrainStartPoint
QPointF constrainStartPoint(QPointF scenePoint) const override
Applies constraints to the start point of the zoom rubber band.
Definition: qgsplottoolxaxiszoom.cpp:35
QgsPlotToolZoom
Plot tool for zooming into and out of the plot.
Definition: qgsplottoolzoom.h:34
QgsPlotTool::canvas
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
Definition: qgsplottool.cpp:147
QgsPlotToolXAxisZoom::QgsPlotToolXAxisZoom
QgsPlotToolXAxisZoom(QgsElevationProfileCanvas *canvas)
Constructor for QgsPlotToolXAxisZoom, with the associated canvas.
Definition: qgsplottoolxaxiszoom.cpp:26
qgsplottoolxaxiszoom.h
qgsplotrubberband.h