/
qgsmaptoolsimplify.h
162 lines (119 loc) · 4.81 KB
/
qgsmaptoolsimplify.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
qgsmaptoolsimplify.h - simplify vector layer features
---------------------
begin : April 2009
copyright : (C) 2009 by Richard Kostecky
email : csf dot kostej at mail 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 QGSMAPTOOLSIMPLIFY_H
#define QGSMAPTOOLSIMPLIFY_H
#include "qgsmaptooledit.h"
#include "ui_qgssimplifytolerancedialog.h"
#include <QVector>
#include "qgstolerance.h"
#include "qgsgeometry.h"
#include "qgis_app.h"
#include "qgsfeature.h"
class QgsRubberBand;
class QgsMapToolSimplify;
class QgsCoordinateTransform;
class QgsSimplifyUserInputWidget;
//! Map tool to simplify line/polygon features
class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
{
Q_OBJECT
public:
enum Method
{
SimplifyDistance = 0,
SimplifySnapToGrid = 1,
SimplifyVisvalingam = 2,
Smooth = 3
};
QgsMapToolSimplify( QgsMapCanvas *canvas );
~QgsMapToolSimplify() override;
void canvasPressEvent( QgsMapMouseEvent *e ) override;
void canvasMoveEvent( QgsMapMouseEvent *e ) override;
void canvasReleaseEvent( QgsMapMouseEvent *e ) override;
void keyReleaseEvent( QKeyEvent *e ) override;
//! called when map tool is being deactivated
void deactivate() override;
double tolerance() const { return mTolerance; }
QgsTolerance::UnitType toleranceUnits() const { return mToleranceUnits; }
QString statusText() const;
Method method() const;
int smoothIterations() const;
void setSmoothIterations( int smoothIterations );
double smoothOffset() const;
void setSmoothOffset( double smoothOffset );
public slots:
//! Slot to change display when slidebar is moved
void setTolerance( double tolerance );
void setToleranceUnits( QgsTolerance::UnitType units );
//! Slot to store feature after simplification
void storeSimplified();
void clearSelection();
void setMethod( Method method );
private:
void selectOneFeature( QPoint canvasPoint );
void selectFeaturesInRect();
void updateSimplificationPreview();
void createUserInputWidget();
/**
* Simplifies a \a geometry to the specified \a tolerance, respecting the preset
* simplification method.
*/
QgsGeometry processGeometry( const QgsGeometry &geometry, double tolerance ) const;
// data
//! Dialog with slider to set correct tolerance value
QgsSimplifyUserInputWidget *mSimplifyUserWidget = nullptr;
//! Rubber bands to draw current state of simplification
QList<QgsRubberBand *> mRubberBands;
//! Features with which we are working
QList<QgsFeature> mSelectedFeatures;
//! Real value of tolerance
double mTolerance = 1.0;
QgsTolerance::UnitType mToleranceUnits = QgsTolerance::LayerUnits;
//! stores actual selection rect
QRect mSelectionRect;
//! shows actual selection rect
QgsRubberBand *mSelectionRubberBand = nullptr;
//! Flag to indicate a map canvas drag operation is taking place
bool mDragging = false;
int mOriginalVertexCount = 0;
int mReducedVertexCount = 0;
bool mReducedHasErrors = false;
Method mMethod = SimplifyDistance;
int mSmoothIterations = 1;
double mSmoothOffset = 0.25;
};
class APP_EXPORT QgsSimplifyUserInputWidget : public QWidget, private Ui::SimplifyUserInputWidgetBase
{
Q_OBJECT
public:
QgsSimplifyUserInputWidget( QWidget *parent = nullptr );
void updateStatusText( const QString &text );
void enableOkButton( bool enabled );
void setConfig( const QgsMapToolSimplify::Method &method, const double &tolerance,
const QgsTolerance::UnitType &units, const double &smoothOffset,
const int &smoothIterations );
signals:
void accepted();
void rejected();
void toleranceChanged( double tolerance );
void toleranceUnitsChanged( QgsTolerance::UnitType units );
void methodChanged( QgsMapToolSimplify::Method method );
void smoothOffsetChanged( double offset );
void smoothIterationsChanged( int iterations );
protected:
bool eventFilter( QObject *object, QEvent *ev ) override;
void keyReleaseEvent( QKeyEvent *event ) override;
};
#endif