@@ -35,22 +35,40 @@ QgsSimplifyDialog::QgsSimplifyDialog( QgsMapToolSimplify *tool, QWidget *parent
35
35
{
36
36
setupUi ( this );
37
37
38
- mMethodComboBox ->addItem ( tr ( " Simplify by distance" ), ( int )QgsVectorSimplifyMethod::Distance );
39
- mMethodComboBox ->addItem ( tr ( " Simplify by snapping to grid" ), ( int )QgsVectorSimplifyMethod::SnapToGrid );
40
- mMethodComboBox ->addItem ( tr ( " Simplify by area (Visvalingam)" ), ( int )QgsVectorSimplifyMethod::Visvalingam );
38
+ mMethodComboBox ->addItem ( tr ( " Simplify by distance" ), QgsMapToolSimplify::SimplifyDistance );
39
+ mMethodComboBox ->addItem ( tr ( " Simplify by snapping to grid" ), QgsMapToolSimplify::SimplifySnapToGrid );
40
+ mMethodComboBox ->addItem ( tr ( " Simplify by area (Visvalingam)" ), QgsMapToolSimplify::SimplifyVisvalingam );
41
+ mMethodComboBox ->addItem ( tr ( " Smooth" ), QgsMapToolSimplify::Smooth );
41
42
42
43
spinTolerance->setValue ( mTool ->tolerance () );
43
44
spinTolerance->setShowClearButton ( false );
44
45
cboToleranceUnits->setCurrentIndex ( ( int ) mTool ->toleranceUnits () );
46
+
47
+ mOffsetSpin ->setClearValue ( 25 );
48
+ mOffsetSpin ->setValue ( mTool ->smoothOffset () * 100 );
49
+ mIterationsSpin ->setClearValue ( 1 );
50
+ mIterationsSpin ->setValue ( mTool ->smoothIterations () );
51
+
45
52
mMethodComboBox ->setCurrentIndex ( mMethodComboBox ->findData ( mTool ->method () ) );
53
+ if ( mMethodComboBox ->currentData ().toInt () != QgsMapToolSimplify::Smooth )
54
+ mOptionsStackedWidget ->setCurrentIndex ( 0 );
55
+ else
56
+ mOptionsStackedWidget ->setCurrentIndex ( 1 );
46
57
47
58
// communication with map tool
48
59
connect ( spinTolerance, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), mTool , &QgsMapToolSimplify::setTolerance );
49
60
connect ( cboToleranceUnits, static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), mTool , &QgsMapToolSimplify::setToleranceUnits );
50
61
connect ( mMethodComboBox , static_cast <void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), mTool , [ = ]
51
62
{
52
- mTool ->setMethod ( static_cast < QgsMapToPixelSimplifier::SimplifyAlgorithm >( mMethodComboBox ->currentData ().toInt () ) );
63
+ mTool ->setMethod ( static_cast < QgsMapToolSimplify::Method >( mMethodComboBox ->currentData ().toInt () ) );
64
+ if ( mMethodComboBox ->currentData ().toInt () != QgsMapToolSimplify::Smooth )
65
+ mOptionsStackedWidget ->setCurrentIndex ( 0 );
66
+ else
67
+ mOptionsStackedWidget ->setCurrentIndex ( 1 );
53
68
} );
69
+
70
+ connect ( mOffsetSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mTool , [ = ]( int value ) { mTool ->setSmoothOffset ( value / 100.0 ); } );
71
+ connect ( mIterationsSpin , static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mTool , [ = ]( int value ) { mTool ->setSmoothIterations ( value ); } );
54
72
connect ( okButton, &QAbstractButton::clicked, mTool , &QgsMapToolSimplify::storeSimplified );
55
73
}
56
74
@@ -79,8 +97,10 @@ QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas *canvas )
79
97
{
80
98
QgsSettings settings;
81
99
mTolerance = settings.value ( QStringLiteral ( " digitizing/simplify_tolerance" ), 1 ).toDouble ();
82
- mToleranceUnits = settings.enumValue ( QStringLiteral ( " digitizing/simplify_tolerance_units" ), QgsTolerance::LayerUnits );
83
- mMethod = static_cast < QgsMapToPixelSimplifier::SimplifyAlgorithm >( settings.value ( QStringLiteral ( " digitizing/simplify_method" ), 0 ).toInt () );
100
+ mToleranceUnits = static_cast < QgsTolerance::UnitType >( settings.value ( QStringLiteral ( " digitizing/simplify_tolerance_units" ), 0 ).toInt () );
101
+ mMethod = static_cast < QgsMapToolSimplify::Method >( settings.value ( QStringLiteral ( " digitizing/simplify_method" ), 0 ).toInt () );
102
+ mSmoothIterations = settings.value ( QStringLiteral ( " digitizing/smooth_iterations" ), 1 ).toInt ();
103
+ mSmoothOffset = settings.value ( QStringLiteral ( " digitizing/smooth_offset" ), 0.25 ).toDouble ();
84
104
85
105
mSimplifyDialog = new QgsSimplifyDialog ( this , canvas->topLevelWidget () );
86
106
}
@@ -144,25 +164,62 @@ QgsGeometry QgsMapToolSimplify::processGeometry( const QgsGeometry &geometry, do
144
164
{
145
165
switch ( mMethod )
146
166
{
147
- case QgsMapToPixelSimplifier::Distance :
167
+ case SimplifyDistance :
148
168
return geometry.simplify ( tolerance );
149
169
150
- case QgsMapToPixelSimplifier::SnapToGrid :
151
- case QgsMapToPixelSimplifier::Visvalingam :
170
+ case SimplifySnapToGrid :
171
+ case SimplifyVisvalingam :
152
172
{
153
- QgsMapToPixelSimplifier simplifier ( QgsMapToPixelSimplifier::SimplifyGeometry, tolerance, mMethod );
173
+
174
+ QgsMapToPixelSimplifier simplifier ( QgsMapToPixelSimplifier::SimplifyGeometry, tolerance, mMethod == SimplifySnapToGrid ? QgsMapToPixelSimplifier::SnapToGrid : QgsMapToPixelSimplifier::Visvalingam );
154
175
return simplifier.simplify ( geometry );
155
176
}
177
+
178
+ case Smooth:
179
+ return geometry.smooth ( mSmoothIterations , mSmoothOffset );
180
+
156
181
}
157
182
return QgsGeometry (); // no warnings
158
183
}
159
184
160
- QgsMapToPixelSimplifier::SimplifyAlgorithm QgsMapToolSimplify::method () const
185
+ double QgsMapToolSimplify::smoothOffset () const
186
+ {
187
+ return mSmoothOffset ;
188
+ }
189
+
190
+ void QgsMapToolSimplify::setSmoothOffset ( double smoothOffset )
191
+ {
192
+ mSmoothOffset = smoothOffset;
193
+
194
+ QgsSettings settings;
195
+ settings.setValue ( QStringLiteral ( " digitizing/smooth_offset" ), smoothOffset );
196
+
197
+ if ( !mSelectedFeatures .isEmpty () )
198
+ updateSimplificationPreview ();
199
+ }
200
+
201
+ int QgsMapToolSimplify::smoothIterations () const
202
+ {
203
+ return mSmoothIterations ;
204
+ }
205
+
206
+ void QgsMapToolSimplify::setSmoothIterations ( int smoothIterations )
207
+ {
208
+ mSmoothIterations = smoothIterations;
209
+
210
+ QgsSettings settings;
211
+ settings.setValue ( QStringLiteral ( " digitizing/smooth_iterations" ), smoothIterations );
212
+
213
+ if ( !mSelectedFeatures .isEmpty () )
214
+ updateSimplificationPreview ();
215
+ }
216
+
217
+ QgsMapToolSimplify::Method QgsMapToolSimplify::method () const
161
218
{
162
219
return mMethod ;
163
220
}
164
221
165
- void QgsMapToolSimplify::setMethod ( QgsMapToPixelSimplifier::SimplifyAlgorithm method )
222
+ void QgsMapToolSimplify::setMethod ( QgsMapToolSimplify::Method method )
166
223
{
167
224
mMethod = method;
168
225
0 commit comments