QgsRasterFileWriterTask class

QgsTask task which performs a QgsRasterFileWriter layer saving operation as a background task.

This can be used to save a raster layer out to a file without blocking the QGIS interface.

Base classes

class QgsTask
Abstract base class for long running background tasks.

Constructors, destructors, conversion operators

QgsRasterFileWriterTask(const QgsRasterFileWriter& writer, QgsRasterPipe* pipe, int columns, int rows, const QgsRectangle& outputExtent, const QgsCoordinateReferenceSystem& crs)
Constructor for QgsRasterFileWriterTask.

Public functions

void cancel() override
Notifies the task that it should terminate.

Signals

void errorOccurred(int error)
Emitted when an error occurs which prevented the file being written (or if the task is canceled).
void writeComplete(const QString& outputUrl)
Emitted when writing the layer is successfully completed.

Protected functions

void finished(bool result) override
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination).
auto run() -> bool override
Performs the task's operation.

Function documentation

QgsRasterFileWriterTask::QgsRasterFileWriterTask(const QgsRasterFileWriter& writer, QgsRasterPipe* pipe, int columns, int rows, const QgsRectangle& outputExtent, const QgsCoordinateReferenceSystem& crs)

Constructor for QgsRasterFileWriterTask.

Takes a source writer, columns, rows, outputExtent and destination crs. Ownership of the pipe is transferred to the writer task, and will be deleted when the task completes.

void QgsRasterFileWriterTask::cancel() override

Notifies the task that it should terminate.

Calling this is not guaranteed to immediately end the task, rather it sets the isCanceled() flag which task subclasses can check and terminate their operations at an appropriate time. Any subtasks owned by this task will also be canceled. Derived classes must ensure that the base class implementation is called from any overridden version.

void QgsRasterFileWriterTask::errorOccurred(int error) signal

Emitted when an error occurs which prevented the file being written (or if the task is canceled).

The writing error will be reported.

void QgsRasterFileWriterTask::writeComplete(const QString& outputUrl) signal

Emitted when writing the layer is successfully completed.

The outputUrl parameter indicates the file path for the written file(s).

void QgsRasterFileWriterTask::finished(bool result) override protected

If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether through successful completion or via early termination).

The result argument reflects whether the task was successfully completed or not. This method is always called from the main thread, so it is safe to create widgets and perform other operations which require the main thread. However, the GUI will be blocked for the duration of this method so tasks should avoid performing any lengthy operations here.

bool QgsRasterFileWriterTask::run() override protected

Performs the task's operation.

This method will be called when the task commences (ie via calling start() ), and subclasses should implement the operation they wish to perform in the background within this method.

A task must return a boolean value to indicate whether the task was completed successfully or terminated before completion.