Skip to content

Commit

Permalink
Allow QgsVectorFileWriter to report approx progress
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 12, 2017
1 parent 8182ec2 commit c42f1ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,9 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
writer->mFields = layer->fields();

// write all features
long saved = 0;
long total = options.onlySelectedFeatures ? layer->selectedFeatureCount() : layer->featureCount();
int lastProgressReport = 0;
while ( fit.nextFeature( fet ) )
{
if ( options.feedback && options.feedback->isCanceled() )
Expand All @@ -2432,6 +2435,18 @@ QgsVectorFileWriter::writeAsVectorFormat( QgsVectorLayer* layer,
return Canceled;
}

saved++;
if ( options.feedback )
{
//avoid spamming progress reports
int newProgress = ( 100.0 * saved ) / total;
if ( newProgress < 100 && newProgress != lastProgressReport )
{
lastProgressReport = newProgress;
options.feedback->setProgress( lastProgressReport );
}
}

if ( shallTransform )
{
try
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorfilewritertask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ bool QgsVectorFileWriterTask::run()
if ( !mLayer )
return false;

connect( mOptions.feedback, &QgsFeedback::progressChanged, this, &QgsVectorFileWriterTask::setProgress );

mError = QgsVectorFileWriter::writeAsVectorFormat(
mLayer, mDestFileName, mOptions, &mNewFilename, &mErrorMessage );
return mError == QgsVectorFileWriter::NoError;
Expand Down

0 comments on commit c42f1ec

Please sign in to comment.