26
26
#include < cmath>
27
27
#include < cfloat>
28
28
29
- QgsSimplifyDialog::QgsSimplifyDialog ( QWidget* parent )
29
+ QgsSimplifyDialog::QgsSimplifyDialog ( QgsMapToolSimplify* tool, QWidget* parent )
30
30
: QDialog( parent )
31
+ , mTool( tool )
31
32
{
32
33
setupUi ( this );
33
- connect ( horizontalSlider, SIGNAL ( valueChanged ( int ) ),
34
- this , SLOT ( valueChanged ( int ) ) );
35
- connect ( horizontalSlider, SIGNAL ( valueChanged ( int ) ),
36
- spinBox, SLOT ( setValue ( int ) ) );
37
- connect ( spinBox, SIGNAL ( valueChanged ( int ) ),
38
- horizontalSlider, SLOT ( setValue ( int ) ) );
39
- connect ( okButton, SIGNAL ( clicked () ),
40
- this , SLOT ( simplify () ) );
41
-
42
- }
43
-
44
- void QgsSimplifyDialog::valueChanged ( int value )
45
- {
46
- emit toleranceChanged ( value );
47
- }
48
-
49
- void QgsSimplifyDialog::simplify ()
50
- {
51
- emit storeSimplified ();
34
+ // synchronization of values
35
+ connect ( horizontalSlider, SIGNAL ( valueChanged ( int ) ), spinBox, SLOT ( setValue ( int ) ) );
36
+ connect ( spinBox, SIGNAL ( valueChanged ( int ) ), horizontalSlider, SLOT ( setValue ( int ) ) );
37
+
38
+ // communication with map tool
39
+ connect ( spinBox, SIGNAL ( valueChanged ( int ) ), this , SLOT ( toleranceChanged ( int ) ) );
40
+ connect ( okButton, SIGNAL ( clicked () ), this , SLOT ( okClicked () ) );
41
+ connect ( this , SIGNAL ( finished ( int ) ), this , SLOT ( onFinished () ) );
52
42
}
53
43
54
44
void QgsSimplifyDialog::setRange ( int minValue, int maxValue )
@@ -61,17 +51,29 @@ void QgsSimplifyDialog::setRange( int minValue, int maxValue )
61
51
spinBox->setRange ( horizontalSlider->minimum (), horizontalSlider->maximum () );
62
52
}
63
53
54
+ void QgsSimplifyDialog::toleranceChanged ( int tol )
55
+ {
56
+ mTool ->setTolerance ( tol );
57
+ }
58
+
59
+ void QgsSimplifyDialog::okClicked ()
60
+ {
61
+ mTool ->storeSimplified ();
62
+ }
63
+
64
+ void QgsSimplifyDialog::onFinished ()
65
+ {
66
+ mTool ->removeRubberBand ();
67
+ }
68
+
69
+
70
+ // //////////////////////////////////////////////////////////////////////////
71
+
64
72
65
73
QgsMapToolSimplify::QgsMapToolSimplify ( QgsMapCanvas* canvas )
66
74
: QgsMapToolEdit( canvas ), mRubberBand( 0 )
67
75
{
68
- mSimplifyDialog = new QgsSimplifyDialog ( canvas->topLevelWidget () );
69
- connect ( mSimplifyDialog , SIGNAL ( toleranceChanged ( int ) ),
70
- this , SLOT ( toleranceChanged ( int ) ) );
71
- connect ( mSimplifyDialog , SIGNAL ( storeSimplified () ),
72
- this , SLOT ( storeSimplified () ) );
73
- connect ( mSimplifyDialog , SIGNAL ( finished ( int ) ),
74
- this , SLOT ( removeRubberBand () ) );
76
+ mSimplifyDialog = new QgsSimplifyDialog ( this , canvas->topLevelWidget () );
75
77
}
76
78
77
79
QgsMapToolSimplify::~QgsMapToolSimplify ()
@@ -81,13 +83,12 @@ QgsMapToolSimplify::~QgsMapToolSimplify()
81
83
}
82
84
83
85
84
- void QgsMapToolSimplify::toleranceChanged ( int tolerance )
86
+ void QgsMapToolSimplify::setTolerance ( int tolerance )
85
87
{
86
- mTolerance = double ( tolerance ) / toleranceDivider ;
88
+ mTolerance = double ( tolerance ) / mToleranceDivider ;
87
89
88
90
// create a copy of selected feature and do the simplification
89
91
QgsFeature f = mSelectedFeature ;
90
- // QgsSimplifyFeature::simplifyLine(f, mTolerance);
91
92
if ( mTolerance > 0 )
92
93
{
93
94
if ( mSelectedFeature .geometry ()->type () == QGis::Line )
@@ -243,10 +244,10 @@ bool QgsMapToolSimplify::calculateSliderBoudaries()
243
244
}
244
245
}
245
246
}
246
- toleranceDivider = calculateDivider ( minTolerance, maxTolerance );
247
+ mToleranceDivider = calculateDivider ( minTolerance, maxTolerance );
247
248
// set min and max
248
- mSimplifyDialog ->setRange ( int ( minTolerance * toleranceDivider ),
249
- int ( maxTolerance * toleranceDivider ) );
249
+ mSimplifyDialog ->setRange ( int ( minTolerance * mToleranceDivider ),
250
+ int ( maxTolerance * mToleranceDivider ) );
250
251
return true ;
251
252
}
252
253
@@ -351,6 +352,8 @@ QVector<QgsPoint> QgsMapToolSimplify::getPointList( QgsFeature& f )
351
352
}
352
353
353
354
355
+ // //////////////////////////////////////////////////////////////////////////
356
+
354
357
355
358
bool QgsSimplifyFeature::simplifyLine ( QgsFeature& lineFeature, double tolerance )
356
359
{
0 commit comments