QGIS API Documentation 4.1.0-Master (4aad578bf8d)
Loading...
Searching...
No Matches
qgsmaptoolselectionhandler.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaptoolselectionhandler.cpp
3 ---------------------
4 begin : March 2018
5 copyright : (C) 2018 by Viktor Sklencar
6 email : vsklencar 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 QGSMAPTOOLSELECTIONHANDLER_H
17#define QGSMAPTOOLSELECTIONHANDLER_H
18
19#include "qgis_gui.h"
20#include "qgsgeometry.h"
21
22#include <QObject>
23#include <QTimer>
24#include <QWidget>
25
26#define SIP_NO_FILE
27
28class QHBoxLayout;
29class QKeyEvent;
30
32class QgsMapCanvas;
34class QgsRubberBand;
36class QgsIdentifyMenu;
37
38
40
48class QgsDistanceWidget : public QWidget
49{
50 Q_OBJECT
51
52 public:
54 explicit QgsDistanceWidget( const QString &label = QString(), QWidget *parent = nullptr );
55
57 void setDistance( double distance );
59 double distance();
60
61 signals:
63 void distanceChanged( double distance );
65 void distanceEditingFinished( double distance, const Qt::KeyboardModifiers &modifiers );
67 void distanceEditingCanceled();
68
69 protected:
70 bool eventFilter( QObject *obj, QEvent *ev ) override;
71
72 private:
73 QHBoxLayout *mLayout = nullptr;
74 QgsDoubleSpinBox *mDistanceSpinBox = nullptr;
75};
76
78
79
85class GUI_EXPORT QgsMapToolSelectionHandler : public QObject
86{
87 Q_OBJECT
88
89 public:
108 Q_ENUM( SelectionMode )
109
110
112
115
117 QgsGeometry selectedGeometry() const;
118
120 SelectionMode selectionMode() const;
122 void setSelectionMode( SelectionMode mode );
123
125 void deactivate();
126
128 void canvasMoveEvent( QgsMapMouseEvent *e );
130 void canvasPressEvent( QgsMapMouseEvent *e );
132 void canvasReleaseEvent( QgsMapMouseEvent *e );
134 bool keyReleaseEvent( QKeyEvent *e );
135
137 void setSelectedGeometry( const QgsGeometry &geometry, Qt::KeyboardModifiers modifiers = Qt::NoModifier );
138
139 signals:
141 void geometryChanged( Qt::KeyboardModifiers modifiers = Qt::NoModifier );
142
143 private slots:
145 void updateRadiusRubberband( double radius );
146
151 void radiusValueEntered( double radius, Qt::KeyboardModifiers modifiers );
152
154 void cancel();
155
156 private:
157 void selectFeaturesMoveEvent( QgsMapMouseEvent *e );
158 void selectFeaturesReleaseEvent( QgsMapMouseEvent *e );
159 void selectFeaturesPressEvent( QgsMapMouseEvent *e );
160
161 void selectPolygonMoveEvent( QgsMapMouseEvent *e );
162 void selectPolygonPressEvent( QgsMapMouseEvent *e );
163
164 void selectFreehandMoveEvent( QgsMapMouseEvent *e );
165 void selectFreehandReleaseEvent( QgsMapMouseEvent *e );
166
167 void selectRadiusMoveEvent( QgsMapMouseEvent *e );
168 void selectRadiusReleaseEvent( QgsMapMouseEvent *e );
169
170 void initRubberBand();
171
172 QgsPointXY toMapCoordinates( QPoint point );
173
174 void createDistanceWidget();
175 void deleteDistanceWidget();
176
177 void updateRadiusFromEdge( QgsPointXY &radiusEdge );
178
179 private:
180 QgsMapCanvas *mCanvas = nullptr;
181
183 std::unique_ptr<QgsRubberBand> mSelectionRubberBand;
184
186 QgsGeometry mSelectionGeometry;
187
189 bool mSelectionActive = false;
190
191 SelectionMode mSelectionMode = SelectSimple;
192
194 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
195
197 QPoint mInitDragPos;
198
200 QgsPointXY mRadiusCenter;
201
203 QgsDistanceWidget *mDistanceWidget = nullptr;
204
205 QColor mFillColor = QColor( 254, 178, 76, 63 );
206 QColor mStrokeColor = QColor( 254, 58, 29, 100 );
207
209 QgsIdentifyMenu *mIdentifyMenu = nullptr; // owned by canvas
210
212 std::unique_ptr<QTimer> mOnMouseMoveDelayTimer;
213
215 QPoint mMoveLastCursorPos;
216};
217
218#endif
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
A geometry is the spatial representation of a feature.
Builds a menu to be used with identify results.
Map canvas is a class for displaying all GIS data types on a canvas.
A mouse event which is the result of a user interaction with a QgsMapCanvas.
Utility class for handling various methods to create geometry for selection in layers.
SelectionMode
Select features to identify by:
@ SelectSimple
SelectSimple - single click or drawing a rectangle, default option.
@ SelectRadius
SelectRadius - a circle selection.
@ SelectOnMouseOver
SelectOnMouseMove - selection on mouse over.
@ SelectPolygon
SelectPolygon - drawing a polygon or right-click on existing polygon feature.
@ SelectFreehand
SelectFreehand - free hand selection.
void geometryChanged(Qt::KeyboardModifiers modifiers=Qt::NoModifier)
emitted when a new geometry has been picked (selectedGeometry())
QgsMapToolSelectionHandler(QgsMapCanvas *canvas, QgsMapToolSelectionHandler::SelectionMode selectionMode=QgsMapToolSelectionHandler::SelectionMode::SelectSimple)
constructor
Represents a 2D point.
Definition qgspointxy.h:62
Responsible for drawing transient features (e.g.
Shows a snapping marker on map canvas for the current snapping match.