Skip to content

Commit

Permalink
Drop redundant vertex count method, update code style
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and 3nids committed Feb 26, 2018
1 parent 3a1c567 commit c0b8fbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 55 deletions.
50 changes: 3 additions & 47 deletions src/app/qgsmaptoolsimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ void QgsSimplifyDialog::closeEvent( QCloseEvent *e )

QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas *canvas )
: QgsMapToolEdit( canvas )
, mDragging( false )
, mOriginalVertexCount( 0 )
, mReducedVertexCount( 0 )
, mReducedHasErrors( false )
{
QgsSettings settings;
mTolerance = settings.value( QStringLiteral( "digitizing/simplify_tolerance" ), 1 ).toDouble();
Expand Down Expand Up @@ -120,7 +116,7 @@ void QgsMapToolSimplify::updateSimplificationPreview()
QgsGeometry g = fSel.geometry().simplify( layerTolerance );
if ( !g.isNull() )
{
mReducedVertexCount += vertexCount( g );
mReducedVertexCount += g.constGet()->nCoordinates();
mRubberBands.at( i )->setToGeometry( g, vl );
}
else
Expand All @@ -132,45 +128,6 @@ void QgsMapToolSimplify::updateSimplificationPreview()
mSimplifyDialog->enableOkButton( !mReducedHasErrors );
}


int QgsMapToolSimplify::vertexCount( const QgsGeometry &g ) const
{
switch ( g.type() )
{
case QgsWkbTypes::LineGeometry:
{
int count = 0;
if ( g.isMultipart() )
{
Q_FOREACH ( const QgsPolylineXY &polyline, g.asMultiPolyline() )
count += polyline.count();
}
else
count = g.asPolyline().count();
return count;
}
case QgsWkbTypes::PolygonGeometry:
{
int count = 0;
if ( g.isMultipart() )
{
Q_FOREACH ( const QgsPolygonXY &polygon, g.asMultiPolygon() )
Q_FOREACH ( const QgsPolylineXY &ring, polygon )
count += ring.count();
}
else
{
Q_FOREACH ( const QgsPolylineXY &ring, g.asPolygon() )
count += ring.count();
}
return count;
}
default:
return 0;
}
}


void QgsMapToolSimplify::storeSimplified()
{
QgsVectorLayer *vlayer = currentVectorLayer();
Expand All @@ -192,8 +149,6 @@ void QgsMapToolSimplify::storeSimplified()
vlayer->triggerRepaint();
}



void QgsMapToolSimplify::canvasPressEvent( QgsMapMouseEvent *e )
{
if ( e->button() != Qt::LeftButton )
Expand Down Expand Up @@ -274,7 +229,8 @@ void QgsMapToolSimplify::canvasReleaseEvent( QgsMapMouseEvent *e )
mOriginalVertexCount = 0;
Q_FOREACH ( const QgsFeature &f, mSelectedFeatures )
{
mOriginalVertexCount += vertexCount( f.geometry() );
if ( f.hasGeometry() )
mOriginalVertexCount += f.geometry().constGet()->nCoordinates();

QgsRubberBand *rb = new QgsRubberBand( mCanvas );
rb->setColor( QColor( 255, 0, 0, 65 ) );
Expand Down
14 changes: 6 additions & 8 deletions src/app/qgsmaptoolsimplify.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit

void updateSimplificationPreview();

int vertexCount( const QgsGeometry &g ) const;

// data
//! Dialog with slider to set correct tolerance value
QgsSimplifyDialog *mSimplifyDialog = nullptr;
Expand All @@ -101,20 +99,20 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
QList<QgsFeature> mSelectedFeatures;

//! Real value of tolerance
double mTolerance;
double mTolerance = 1.0;

QgsTolerance::UnitType mToleranceUnits;
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;
bool mDragging = false;

int mOriginalVertexCount;
int mReducedVertexCount;
bool mReducedHasErrors;
int mOriginalVertexCount = 0;
int mReducedVertexCount = 0;
bool mReducedHasErrors = false;
};

#endif

0 comments on commit c0b8fbf

Please sign in to comment.