Skip to content
Permalink
Browse files

Drop redundant vertex count method, update code style

  • Loading branch information
nyalldawson authored and 3nids committed Feb 26, 2018
1 parent 3a1c567 commit c0b8fbfbf61a2d9a42f05ba6b0d8ef76c4c1699b
Showing with 9 additions and 55 deletions.
  1. +3 −47 src/app/qgsmaptoolsimplify.cpp
  2. +6 −8 src/app/qgsmaptoolsimplify.h
@@ -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();
@@ -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
@@ -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();
@@ -192,8 +149,6 @@ void QgsMapToolSimplify::storeSimplified()
vlayer->triggerRepaint();
}



void QgsMapToolSimplify::canvasPressEvent( QgsMapMouseEvent *e )
{
if ( e->button() != Qt::LeftButton )
@@ -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 ) );
@@ -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;
@@ -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.
You can’t perform that action at this time.