Skip to content

Commit

Permalink
[Geometry snapper] Fix progress bar not working
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Jan 21, 2016
1 parent 7afdecd commit b00950b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/plugins/geometry_snapper/qgsgeometrysnapper.cpp
Expand Up @@ -49,11 +49,13 @@ QgsGeometrySnapper::QgsGeometrySnapper( QgsVectorLayer *adjustLayer, QgsVectorLa

QFuture<void> QgsGeometrySnapper::processFeatures()
{
emit progressRangeChanged( 0, mFeatures.size() );
return QtConcurrent::map( mFeatures, ProcessFeatureWrapper( this ) );
}

void QgsGeometrySnapper::processFeature( QgsFeatureId id )
{
emit progressStep();
// Get current feature
QgsFeature feature;
if ( !getFeature( mAdjustLayer, mAdjustLayerMutex, id, feature ) )
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/geometry_snapper/qgsgeometrysnapper.h
Expand Up @@ -35,6 +35,10 @@ class QgsGeometrySnapper : public QObject
QFuture<void> processFeatures();
const QStringList& getErrors() const { return mErrors; }

signals:
void progressRangeChanged( int min, int max );
void progressStep();

private:
struct ProcessFeatureWrapper
{
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/geometry_snapper/qgsgeometrysnapperdialog.cpp
Expand Up @@ -280,8 +280,6 @@ void QgsGeometrySnapperDialog::run()
/** Run **/
QEventLoop evLoop;
QFutureWatcher<void> futureWatcher;
connect( &futureWatcher, SIGNAL( progressRangeChanged( int, int ) ), progressBar, SLOT( setRange( int, int ) ) );
connect( &futureWatcher, SIGNAL( progressValueChanged( int ) ), progressBar, SLOT( setValue( int ) ) );
connect( &futureWatcher, SIGNAL( finished() ), &evLoop, SLOT( quit() ) );
connect( buttonBox->button( QDialogButtonBox::Abort ), SIGNAL( clicked() ), &futureWatcher, SLOT( cancel() ) );

Expand All @@ -294,6 +292,8 @@ void QgsGeometrySnapperDialog::run()
widgetInputs->setEnabled( false );

QgsGeometrySnapper snapper( layer, referenceLayer, selectedOnly, doubleSpinBoxMaxDistance->value(), &mIface->mapCanvas()->mapSettings() );
connect( &snapper, SIGNAL( progressRangeChanged( int, int ) ), progressBar, SLOT( setRange( int, int ) ) );
connect( &snapper, SIGNAL( progressStep() ), this, SLOT( progressStep() ) );
futureWatcher.setFuture( snapper.processFeatures() );
evLoop.exec();

Expand All @@ -317,3 +317,8 @@ void QgsGeometrySnapperDialog::run()
hide() ;
}

void QgsGeometrySnapperDialog::progressStep()
{
progressBar->setValue( progressBar->value() + 1 );
}

1 change: 1 addition & 0 deletions src/plugins/geometry_snapper/qgsgeometrysnapperdialog.h
Expand Up @@ -46,6 +46,7 @@ class QgsGeometrySnapperDialog: public QDialog, private Ui::QgsGeometrySnapperDi
void updateLayers();
void validateInput();
void selectOutputFile();
void progressStep();
};

#endif // QGS_GEOMETRY_SNAPPER_DIALOG_H
Expand Down

0 comments on commit b00950b

Please sign in to comment.