Skip to content

Commit c0b8fbf

Browse files
nyalldawson3nids
authored andcommittedFeb 26, 2018
Drop redundant vertex count method, update code style
1 parent 3a1c567 commit c0b8fbf

File tree

2 files changed

+9
-55
lines changed

2 files changed

+9
-55
lines changed
 

‎src/app/qgsmaptoolsimplify.cpp

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ void QgsSimplifyDialog::closeEvent( QCloseEvent *e )
6666

6767
QgsMapToolSimplify::QgsMapToolSimplify( QgsMapCanvas *canvas )
6868
: QgsMapToolEdit( canvas )
69-
, mDragging( false )
70-
, mOriginalVertexCount( 0 )
71-
, mReducedVertexCount( 0 )
72-
, mReducedHasErrors( false )
7369
{
7470
QgsSettings settings;
7571
mTolerance = settings.value( QStringLiteral( "digitizing/simplify_tolerance" ), 1 ).toDouble();
@@ -120,7 +116,7 @@ void QgsMapToolSimplify::updateSimplificationPreview()
120116
QgsGeometry g = fSel.geometry().simplify( layerTolerance );
121117
if ( !g.isNull() )
122118
{
123-
mReducedVertexCount += vertexCount( g );
119+
mReducedVertexCount += g.constGet()->nCoordinates();
124120
mRubberBands.at( i )->setToGeometry( g, vl );
125121
}
126122
else
@@ -132,45 +128,6 @@ void QgsMapToolSimplify::updateSimplificationPreview()
132128
mSimplifyDialog->enableOkButton( !mReducedHasErrors );
133129
}
134130

135-
136-
int QgsMapToolSimplify::vertexCount( const QgsGeometry &g ) const
137-
{
138-
switch ( g.type() )
139-
{
140-
case QgsWkbTypes::LineGeometry:
141-
{
142-
int count = 0;
143-
if ( g.isMultipart() )
144-
{
145-
Q_FOREACH ( const QgsPolylineXY &polyline, g.asMultiPolyline() )
146-
count += polyline.count();
147-
}
148-
else
149-
count = g.asPolyline().count();
150-
return count;
151-
}
152-
case QgsWkbTypes::PolygonGeometry:
153-
{
154-
int count = 0;
155-
if ( g.isMultipart() )
156-
{
157-
Q_FOREACH ( const QgsPolygonXY &polygon, g.asMultiPolygon() )
158-
Q_FOREACH ( const QgsPolylineXY &ring, polygon )
159-
count += ring.count();
160-
}
161-
else
162-
{
163-
Q_FOREACH ( const QgsPolylineXY &ring, g.asPolygon() )
164-
count += ring.count();
165-
}
166-
return count;
167-
}
168-
default:
169-
return 0;
170-
}
171-
}
172-
173-
174131
void QgsMapToolSimplify::storeSimplified()
175132
{
176133
QgsVectorLayer *vlayer = currentVectorLayer();
@@ -192,8 +149,6 @@ void QgsMapToolSimplify::storeSimplified()
192149
vlayer->triggerRepaint();
193150
}
194151

195-
196-
197152
void QgsMapToolSimplify::canvasPressEvent( QgsMapMouseEvent *e )
198153
{
199154
if ( e->button() != Qt::LeftButton )
@@ -274,7 +229,8 @@ void QgsMapToolSimplify::canvasReleaseEvent( QgsMapMouseEvent *e )
274229
mOriginalVertexCount = 0;
275230
Q_FOREACH ( const QgsFeature &f, mSelectedFeatures )
276231
{
277-
mOriginalVertexCount += vertexCount( f.geometry() );
232+
if ( f.hasGeometry() )
233+
mOriginalVertexCount += f.geometry().constGet()->nCoordinates();
278234

279235
QgsRubberBand *rb = new QgsRubberBand( mCanvas );
280236
rb->setColor( QColor( 255, 0, 0, 65 ) );

‎src/app/qgsmaptoolsimplify.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
8989

9090
void updateSimplificationPreview();
9191

92-
int vertexCount( const QgsGeometry &g ) const;
93-
9492
// data
9593
//! Dialog with slider to set correct tolerance value
9694
QgsSimplifyDialog *mSimplifyDialog = nullptr;
@@ -101,20 +99,20 @@ class APP_EXPORT QgsMapToolSimplify: public QgsMapToolEdit
10199
QList<QgsFeature> mSelectedFeatures;
102100

103101
//! Real value of tolerance
104-
double mTolerance;
102+
double mTolerance = 1.0;
105103

106-
QgsTolerance::UnitType mToleranceUnits;
104+
QgsTolerance::UnitType mToleranceUnits = QgsTolerance::LayerUnits;
107105

108106
//! stores actual selection rect
109107
QRect mSelectionRect;
110108
//! shows actual selection rect
111109
QgsRubberBand *mSelectionRubberBand = nullptr;
112110
//! Flag to indicate a map canvas drag operation is taking place
113-
bool mDragging;
111+
bool mDragging = false;
114112

115-
int mOriginalVertexCount;
116-
int mReducedVertexCount;
117-
bool mReducedHasErrors;
113+
int mOriginalVertexCount = 0;
114+
int mReducedVertexCount = 0;
115+
bool mReducedHasErrors = false;
118116
};
119117

120118
#endif

0 commit comments

Comments
 (0)