Skip to content
Permalink
Browse files

Allow QgsVectorFileWriter to report approx progress

  • Loading branch information
nyalldawson committed Feb 12, 2017
1 parent 8182ec2 commit c42f1ec7f53711e5c033fd8ea1f4c2e2bf35aadf
Showing with 17 additions and 0 deletions.
  1. +15 −0 src/core/qgsvectorfilewriter.cpp
  2. +2 −0 src/core/qgsvectorfilewritertask.cpp
@@ -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() )
@@ -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
@@ -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;

0 comments on commit c42f1ec

Please sign in to comment.
You can’t perform that action at this time.