QGIS API Documentation  3.13.0-Master (5a3b1ced84)
qgsmaptoolextent.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolextent.h - map tool that emits an extent
3  ---------------------
4  begin : July 2017
5  copyright : (C) 2017 by Mathieu Pellerin
6  email : nirvn dot asia at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPTOOLEXTENT_H
17 #define QGSMAPTOOLEXTENT_H
18 
19 #include "qgsmaptool.h"
20 #include "qgspointxy.h"
21 #include "qgsrubberband.h"
22 #include "qgis_gui.h"
23 
24 #include <memory>
25 
26 class QgsMapCanvas;
27 
28 
34 class GUI_EXPORT QgsMapToolExtent : public QgsMapTool
35 {
36  Q_OBJECT
37 
38  public:
39 
41  QgsMapToolExtent( QgsMapCanvas *canvas );
42 
43  Flags flags() const override { return QgsMapTool::AllowZoomRect; }
44  void canvasMoveEvent( QgsMapMouseEvent *e ) override;
45  void canvasPressEvent( QgsMapMouseEvent *e ) override;
46  void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
47  void activate() override;
48  void deactivate() override;
49 
55  void setRatio( QSize ratio ) { mRatio = ratio; }
56 
61  QSize ratio() const { return mRatio; }
62 
66  QgsRectangle extent() const;
67 
68  signals:
69 
71  void extentChanged( const QgsRectangle &extent );
72 
73  private:
74 
75  void calculateEndPoint( QgsPointXY &point );
76 
77  void drawExtent();
78 
79  std::unique_ptr< QgsRubberBand > mRubberBand;
80 
81  QgsPointXY mStartPoint;
82  QgsPointXY mEndPoint;
83 
84  bool mDraw = false;
85 
86  QSize mRatio;
87 
88 };
89 
90 #endif
A rectangle specified with double values.
Definition: qgsrectangle.h:41
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:157
A class to represent a 2D point.
Definition: qgspointxy.h:43
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition: qgsmaptool.h:94
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:78
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:167
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:83
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Flags flags() const override
Returns the flags for the map tool.
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:99
A map tool that emits an extent from a rectangle drawn onto the map canvas.
Abstract base class for all map tools.
Definition: qgsmaptool.h:62
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptool.cpp:172