33 const QMap<QString, QgsMapLayer *> &mapLayers = project->
mapLayers();
39 for ( QMap<QString, QgsMapLayer *>::const_iterator it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
41 currentLayer = it.value();
47 if ( layerRange.begin().isValid() && ( !minDate.isValid() || layerRange.begin() < minDate ) )
48 minDate = layerRange.begin();
49 if ( layerRange.end().isValid() && ( !maxDate.isValid() || layerRange.end() > maxDate ) )
50 maxDate = layerRange.end();
53 return QgsDateTimeRange( minDate, maxDate );
60 error = QObject::tr(
"Filename template is empty" );
64 if ( numberOfDigits < 0 )
66 error = QObject::tr(
"Wrong filename template format (must contain #)" );
69 const QString token( numberOfDigits, QLatin1Char(
'#' ) );
72 error = QObject::tr(
"Filename template must contain all # placeholders in one continuous group." );
77 error = QObject::tr(
"Output directory creation failure." );
88 long long currentFrame = 0;
90 while ( currentFrame < totalFrames )
96 error = QObject::tr(
"Export canceled" );
99 feedback->
setProgress( currentFrame /
static_cast<double>( totalFrames ) * 100 );
114 const QString frameNoPaddedLeft( QStringLiteral(
"%1" ).arg( currentFrame, numberOfDigits, 10, QChar(
'0' ) ) );
115 fileName.replace( token, frameNoPaddedLeft );
116 const QString path = QDir( settings.
outputDirectory ).filePath( fileName );
119 img.setDotsPerMeterX( 1000 * ms.
outputDpi() / 25.4 );
120 img.setDotsPerMeterY( 1000 * ms.
outputDpi() / 25.4 );
131 const auto constMDecorations = settings.
decorations;
134 decoration->render( ms, context );
152 if ( isFractional || interval.
originalUnit() == QgsUnitTypes::TemporalUnit::TemporalUnknownUnit )
154 return start + interval;
160 case QgsUnitTypes::TemporalUnit::TemporalMilliseconds:
163 case QgsUnitTypes::TemporalUnit::TemporalSeconds:
166 case QgsUnitTypes::TemporalUnit::TemporalMinutes:
169 case QgsUnitTypes::TemporalUnit::TemporalHours:
172 case QgsUnitTypes::TemporalUnit::TemporalDays:
175 case QgsUnitTypes::TemporalUnit::TemporalWeeks:
178 case QgsUnitTypes::TemporalUnit::TemporalMonths:
181 case QgsUnitTypes::TemporalUnit::TemporalYears:
184 case QgsUnitTypes::TemporalUnit::TemporalDecades:
187 case QgsUnitTypes::TemporalUnit::TemporalCenturies:
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A representation of the interval between two datetime values.
double originalDuration() const
Returns the original interval duration.
QgsUnitTypes::TemporalUnit originalUnit() const
Returns the original interval temporal unit.
Interface for map decorations.
virtual QgsDateTimeRange calculateTemporalExtent(QgsMapLayer *layer) const
Attempts to calculate the overall temporal extent for the specified layer, using the settings defined...
Base class for all map layer types.
virtual QgsMapLayerTemporalProperties * temporalProperties()
Returns the layer's temporal properties.
Job implementation that renders everything sequentially using a custom painter.
void waitForFinished() override
Block until the job has finished.
void start() override
Start the rendering job and immediately return.
The QgsMapSettings class contains configuration for rendering of the map.
QColor backgroundColor() const
Returns the background color of the map.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Contains information about the context of a rendering operation.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Implements a temporal controller based on a frame by frame navigation and animation.
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setFrameDuration(QgsInterval duration)
Sets the frame duration, which dictates the temporal length of each frame in the animation.
void setCurrentFrameNumber(long long frame)
Sets the current animation frame number.
long long totalFrameCount() const
Returns the total number of frames for the navigation.
QgsDateTimeRange dateTimeRangeForFrameNumber(long long frame) const
Calculates the temporal range associated with a particular animation frame.
void setTemporalExtents(const QgsDateTimeRange &extents)
Sets the navigation temporal extents, which dictate the earliest and latest date time possible in the...
bool isActive() const
Returns true if the temporal property is active.
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
static QDateTime calculateFrameTime(const QDateTime &start, const long long frame, const QgsInterval interval)
Calculates the frame time for an animation.
static QgsDateTimeRange calculateTemporalRangeForProject(QgsProject *project)
Calculates the temporal range for a project.
static bool exportAnimation(const QgsMapSettings &mapSettings, const AnimationExportSettings &settings, QString &error, QgsFeedback *feedback=nullptr)
Exports animation frames by rendering the map to multiple destination images.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Contains settings relating to exporting animations.
QgsDateTimeRange animationRange
Dictates the overall temporal range of the animation.
QgsInterval frameDuration
Duration of individual export frames.
QString fileNameTemplate
The filename template for exporting the frames.
QString outputDirectory
Destination directory for created image files.
QList< QgsMapDecoration * > decorations
List of decorations to draw onto exported frames.