Skip to content

Commit

Permalink
Simplify tool - a bit of housekeeping (no functional changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jan 22, 2015
1 parent 60712cd commit e93c713
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
69 changes: 36 additions & 33 deletions src/app/qgsmaptoolsimplify.cpp
Expand Up @@ -26,29 +26,19 @@
#include <cmath>
#include <cfloat>

QgsSimplifyDialog::QgsSimplifyDialog( QWidget* parent )
QgsSimplifyDialog::QgsSimplifyDialog( QgsMapToolSimplify* tool, QWidget* parent )
: QDialog( parent )
, mTool( tool )
{
setupUi( this );
connect( horizontalSlider, SIGNAL( valueChanged( int ) ),
this, SLOT( valueChanged( int ) ) );
connect( horizontalSlider, SIGNAL( valueChanged( int ) ),
spinBox, SLOT( setValue( int ) ) );
connect( spinBox, SIGNAL( valueChanged( int ) ),
horizontalSlider, SLOT( setValue( int ) ) );
connect( okButton, SIGNAL( clicked() ),
this, SLOT( simplify() ) );

}

void QgsSimplifyDialog::valueChanged( int value )
{
emit toleranceChanged( value );
}

void QgsSimplifyDialog::simplify()
{
emit storeSimplified();
// synchronization of values
connect( horizontalSlider, SIGNAL( valueChanged( int ) ), spinBox, SLOT( setValue( int ) ) );
connect( spinBox, SIGNAL( valueChanged( int ) ), horizontalSlider, SLOT( setValue( int ) ) );

// communication with map tool
connect( spinBox, SIGNAL( valueChanged( int ) ), this, SLOT( toleranceChanged( int ) ) );
connect( okButton, SIGNAL( clicked() ), this, SLOT( okClicked() ) );
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );
}

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

void QgsSimplifyDialog::toleranceChanged( int tol )
{
mTool->setTolerance( tol );
}

void QgsSimplifyDialog::okClicked()
{
mTool->storeSimplified();
}

void QgsSimplifyDialog::onFinished()
{
mTool->removeRubberBand();
}


////////////////////////////////////////////////////////////////////////////


QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas* canvas )
: QgsMapToolEdit( canvas ), mRubberBand( 0 )
{
mSimplifyDialog = new QgsSimplifyDialog( canvas->topLevelWidget() );
connect( mSimplifyDialog, SIGNAL( toleranceChanged( int ) ),
this, SLOT( toleranceChanged( int ) ) );
connect( mSimplifyDialog, SIGNAL( storeSimplified() ),
this, SLOT( storeSimplified() ) );
connect( mSimplifyDialog, SIGNAL( finished( int ) ),
this, SLOT( removeRubberBand() ) );
mSimplifyDialog = new QgsSimplifyDialog( this, canvas->topLevelWidget() );
}

QgsMapToolSimplify::~QgsMapToolSimplify()
Expand All @@ -81,13 +83,12 @@ QgsMapToolSimplify::~QgsMapToolSimplify()
}


void QgsMapToolSimplify::toleranceChanged( int tolerance )
void QgsMapToolSimplify::setTolerance( int tolerance )
{
mTolerance = double( tolerance ) / toleranceDivider;
mTolerance = double( tolerance ) / mToleranceDivider;

// create a copy of selected feature and do the simplification
QgsFeature f = mSelectedFeature;
//QgsSimplifyFeature::simplifyLine(f, mTolerance);
if ( mTolerance > 0 )
{
if ( mSelectedFeature.geometry()->type() == QGis::Line )
Expand Down Expand Up @@ -243,10 +244,10 @@ bool QgsMapToolSimplify::calculateSliderBoudaries()
}
}
}
toleranceDivider = calculateDivider( minTolerance, maxTolerance );
mToleranceDivider = calculateDivider( minTolerance, maxTolerance );
// set min and max
mSimplifyDialog->setRange( int( minTolerance * toleranceDivider ),
int( maxTolerance * toleranceDivider ) );
mSimplifyDialog->setRange( int( minTolerance * mToleranceDivider ),
int( maxTolerance * mToleranceDivider ) );
return true;
}

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


////////////////////////////////////////////////////////////////////////////


bool QgsSimplifyFeature::simplifyLine( QgsFeature& lineFeature, double tolerance )
{
Expand Down
37 changes: 17 additions & 20 deletions src/app/qgsmaptoolsimplify.h
Expand Up @@ -23,38 +23,37 @@
#include "qgsfeature.h"

class QgsRubberBand;

class QgsMapToolSimplify;

class APP_EXPORT QgsSimplifyDialog : public QDialog, private Ui::SimplifyLineDialog
{
Q_OBJECT

public:

QgsSimplifyDialog( QWidget* parent = NULL );
QgsSimplifyDialog( QgsMapToolSimplify* tool, QWidget* parent = NULL );

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

signals:
private:
QgsMapToolSimplify* mTool;

private slots:

/** Signal when slidebar is moved */
void toleranceChanged( int tol );

/** Signal to accept changes */
void storeSimplified();
void okClicked();

void onFinished();

private slots:
/** Internal signal when value is changed */
void valueChanged( int value );
/** Internal signal to store simplified feature */
void simplify();
};


/** Map tool to simplify line/polygon features */
class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
{
Q_OBJECT

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

public slots:
/** slot to change display when slidebar is moved */
void setTolerance( int tolerance );

/** slot to store feture after simplification */
void storeSimplified();

void removeRubberBand();

private:
Expand All @@ -89,18 +93,11 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
QgsFeature mSelectedFeature;

/** tolerance divider is value which tells with which delete value from sidebar */
long toleranceDivider;
long mToleranceDivider;

/** real value of tolerance */
double mTolerance;

private slots:
/** slot to change display when slidebar is moved */
void toleranceChanged( int tolerance );

/** slot to store feture after simplification */
void storeSimplified();

};

/**
Expand Down

0 comments on commit e93c713

Please sign in to comment.