-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsmaptoolrotatefeature.h
127 lines (93 loc) · 3.63 KB
/
qgsmaptoolrotatefeature.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
qgsmaptoolrotatefeature.h - map tool for rotating features by mouse drag
---------------------
begin : January 2013
copyright : (C) 2013 by Vinayan Parameswaran
email : vinayan123 at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMAPTOOLROTATEFEATURE_H
#define QGSMAPTOOLROTATEFEATURE_H
#include <QWidget>
#include "qgsmaptooladvanceddigitizing.h"
#include "qgsvertexmarker.h"
#include "qgis_app.h"
#include "qgsgeometry.h"
#include "qgsfeatureid.h"
class QgsDoubleSpinBox;
class QHBoxLayout;
class QgsSpinBox;
class QgsSnapIndicator;
class APP_EXPORT QgsAngleMagnetWidget : public QWidget
{
Q_OBJECT
public:
explicit QgsAngleMagnetWidget( const QString &label = QString(), QWidget *parent = nullptr );
void setAngle( double angle );
double angle() const;
void setMagnet( int magnet );
int magnet() const;
QgsDoubleSpinBox *editor() const {return mAngleSpinBox;}
signals:
void angleChanged( double angle );
void angleEditingFinished( double angle );
void angleEditingCanceled();
public slots:
protected:
bool eventFilter( QObject *obj, QEvent *ev ) override;
private slots:
void angleSpinBoxValueChanged( double angle );
private:
QHBoxLayout *mLayout = nullptr;
QgsDoubleSpinBox *mAngleSpinBox = nullptr;
QgsSpinBox *mMagnetSpinBox = nullptr;
};
//! Map tool to rotate features
class APP_EXPORT QgsMapToolRotateFeature: public QgsMapToolAdvancedDigitizing
{
Q_OBJECT
public:
QgsMapToolRotateFeature( QgsMapCanvas *canvas );
~QgsMapToolRotateFeature() override;
void cadCanvasMoveEvent( QgsMapMouseEvent *e ) override;
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
//! called when map tool is being deactivated
void deactivate() override;
void activate() override;
//! catch escape when active to cancel selection
void keyReleaseEvent( QKeyEvent *e ) override;
private slots:
void updateRubberband( double rotation );
void applyRotation( double rotation );
void cancel();
private:
QgsGeometry rotateGeometry( QgsGeometry geom, QgsPointXY point, double angle );
QgsPointXY rotatePoint( QgsPointXY point, double angle );
void deleteRubberband();
void createRotationWidget();
void deleteRotationWidget();
//! Start point of the rotation in map coordinates
QgsPointXY mStartPointMapCoords;
QgsPointXY mInitialPos;
//! Rubberband that shows the feature being rotated
QgsRubberBand *mRubberBand = nullptr;
//! Snapping indicators
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
//! Id of rotated feature
QgsFeatureIds mRotatedFeatures;
double mRotation;
double mRotationOffset;
QPoint mStPoint;
std::unique_ptr<QgsVertexMarker> mAnchorPoint = nullptr;
bool mAutoSetAnchorPoint = false;
bool mRotationActive;
//! Shows current angle value and allows numerical editing
QgsAngleMagnetWidget *mRotationWidget = nullptr;
};
#endif