QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
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#include "qobjectuniqueptr.h"
24
25class QgsMapCanvas;
26
27
32class GUI_EXPORT QgsMapToolExtent : public QgsMapTool
33{
34 Q_OBJECT
35
36 public:
37
40
41 Flags flags() const override { return QgsMapTool::AllowZoomRect; }
42 void canvasMoveEvent( QgsMapMouseEvent *e ) override;
43 void canvasPressEvent( QgsMapMouseEvent *e ) override;
44 void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
45 void activate() override;
46 void deactivate() override;
47
53 void setRatio( QSize ratio ) { mRatio = ratio; }
54
59 QSize ratio() const { return mRatio; }
60
64 QgsRectangle extent() const;
65
71 void clearRubberBand();
72
73 signals:
74
76 void extentChanged( const QgsRectangle &extent );
77
78 private:
79
80 void calculateEndPoint( QgsPointXY &point );
81
82 void drawExtent();
83
85
86 QgsPointXY mStartPoint;
87 QgsPointXY mEndPoint;
88
89 bool mDraw = false;
90
91 QSize mRatio;
92
93};
94
95#endif
Map canvas is a class for displaying all GIS data types on a canvas.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
A map tool that emits an extent from a rectangle drawn onto the map canvas.
Flags flags() const override
Returns the flags for the map tool.
QSize ratio() const
Returns the current fixed aspect ratio to be used when dragging extent onto the canvas.
void extentChanged(const QgsRectangle &extent)
signal emitted on extent change
void setRatio(QSize ratio)
Sets a fixed aspect ratio to be used when dragging extent onto the canvas.
Abstract base class for all map tools.
Definition qgsmaptool.h:71
QFlags< Flag > Flags
Definition qgsmaptool.h:116
virtual void canvasPressEvent(QgsMapMouseEvent *e)
Mouse press event for overriding. Default implementation does nothing.
virtual void canvasMoveEvent(QgsMapMouseEvent *e)
Mouse move event for overriding. Default implementation does nothing.
virtual void canvasReleaseEvent(QgsMapMouseEvent *e)
Mouse release event for overriding. Default implementation does nothing.
@ AllowZoomRect
Allow zooming by rectangle (by holding shift and dragging) while the tool is active.
Definition qgsmaptool.h:113
virtual void activate()
called when set as currently active map tool
virtual void deactivate()
called when map tool is being deactivated
A class to represent a 2D point.
Definition qgspointxy.h:60
A rectangle specified with double values.