Skip to content

Commit e93c713

Browse files
committedJan 22, 2015
Simplify tool - a bit of housekeeping (no functional changes)
1 parent 60712cd commit e93c713

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed
 

‎src/app/qgsmaptoolsimplify.cpp

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,19 @@
2626
#include <cmath>
2727
#include <cfloat>
2828

29-
QgsSimplifyDialog::QgsSimplifyDialog( QWidget* parent )
29+
QgsSimplifyDialog::QgsSimplifyDialog( QgsMapToolSimplify* tool, QWidget* parent )
3030
: QDialog( parent )
31+
, mTool( tool )
3132
{
3233
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() ) );
5242
}
5343

5444
void QgsSimplifyDialog::setRange( int minValue, int maxValue )
@@ -61,17 +51,29 @@ void QgsSimplifyDialog::setRange( int minValue, int maxValue )
6151
spinBox->setRange( horizontalSlider->minimum(), horizontalSlider->maximum() );
6252
}
6353

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+
6472

6573
QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas* canvas )
6674
: QgsMapToolEdit( canvas ), mRubberBand( 0 )
6775
{
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() );
7577
}
7678

7779
QgsMapToolSimplify::~QgsMapToolSimplify()
@@ -81,13 +83,12 @@ QgsMapToolSimplify::~QgsMapToolSimplify()
8183
}
8284

8385

84-
void QgsMapToolSimplify::toleranceChanged( int tolerance )
86+
void QgsMapToolSimplify::setTolerance( int tolerance )
8587
{
86-
mTolerance = double( tolerance ) / toleranceDivider;
88+
mTolerance = double( tolerance ) / mToleranceDivider;
8789

8890
// create a copy of selected feature and do the simplification
8991
QgsFeature f = mSelectedFeature;
90-
//QgsSimplifyFeature::simplifyLine(f, mTolerance);
9192
if ( mTolerance > 0 )
9293
{
9394
if ( mSelectedFeature.geometry()->type() == QGis::Line )
@@ -243,10 +244,10 @@ bool QgsMapToolSimplify::calculateSliderBoudaries()
243244
}
244245
}
245246
}
246-
toleranceDivider = calculateDivider( minTolerance, maxTolerance );
247+
mToleranceDivider = calculateDivider( minTolerance, maxTolerance );
247248
// set min and max
248-
mSimplifyDialog->setRange( int( minTolerance * toleranceDivider ),
249-
int( maxTolerance * toleranceDivider ) );
249+
mSimplifyDialog->setRange( int( minTolerance * mToleranceDivider ),
250+
int( maxTolerance * mToleranceDivider ) );
250251
return true;
251252
}
252253

@@ -351,6 +352,8 @@ QVector<QgsPoint> QgsMapToolSimplify::getPointList( QgsFeature& f )
351352
}
352353

353354

355+
////////////////////////////////////////////////////////////////////////////
356+
354357

355358
bool QgsSimplifyFeature::simplifyLine( QgsFeature& lineFeature, double tolerance )
356359
{

‎src/app/qgsmaptoolsimplify.h

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,37 @@
2323
#include "qgsfeature.h"
2424

2525
class QgsRubberBand;
26-
26+
class QgsMapToolSimplify;
2727

2828
class APP_EXPORT QgsSimplifyDialog : public QDialog, private Ui::SimplifyLineDialog
2929
{
3030
Q_OBJECT
3131

3232
public:
3333

34-
QgsSimplifyDialog( QWidget* parent = NULL );
34+
QgsSimplifyDialog( QgsMapToolSimplify* tool, QWidget* parent = NULL );
3535

3636
/** Setting range of slide bar */
3737
void setRange( int minValue, int maxValue );
3838

39-
signals:
39+
private:
40+
QgsMapToolSimplify* mTool;
41+
42+
private slots:
43+
4044
/** Signal when slidebar is moved */
4145
void toleranceChanged( int tol );
42-
4346
/** Signal to accept changes */
44-
void storeSimplified();
47+
void okClicked();
48+
49+
void onFinished();
4550

46-
private slots:
47-
/** Internal signal when value is changed */
48-
void valueChanged( int value );
49-
/** Internal signal to store simplified feature */
50-
void simplify();
5151
};
5252

5353

5454
/** Map tool to simplify line/polygon features */
5555
class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
5656
{
57-
Q_OBJECT
5857

5958
public:
6059
QgsMapToolSimplify( QgsMapCanvas* canvas );
@@ -65,7 +64,12 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
6564
//! called when map tool is being deactivated
6665
void deactivate() override;
6766

68-
public slots:
67+
/** slot to change display when slidebar is moved */
68+
void setTolerance( int tolerance );
69+
70+
/** slot to store feture after simplification */
71+
void storeSimplified();
72+
6973
void removeRubberBand();
7074

7175
private:
@@ -89,18 +93,11 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
8993
QgsFeature mSelectedFeature;
9094

9195
/** tolerance divider is value which tells with which delete value from sidebar */
92-
long toleranceDivider;
96+
long mToleranceDivider;
9397

9498
/** real value of tolerance */
9599
double mTolerance;
96100

97-
private slots:
98-
/** slot to change display when slidebar is moved */
99-
void toleranceChanged( int tolerance );
100-
101-
/** slot to store feture after simplification */
102-
void storeSimplified();
103-
104101
};
105102

106103
/**

0 commit comments

Comments
 (0)
Please sign in to comment.