31 #include <QRegularExpression> 
   35   const QMap<QString, QgsMapLayer *> mapLayers = project->
mapLayers();
 
   39   for ( 
auto it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
 
   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 );
 
   58   const QMap<QString, QgsMapLayer *> mapLayers = project->
mapLayers();
 
   60   QList< QgsDateTimeRange > ranges;
 
   61   for ( 
auto it = mapLayers.constBegin(); it != mapLayers.constEnd(); ++it )
 
   71   return QgsDateTimeRange::mergeRanges( ranges );
 
   78     error = QObject::tr( 
"Filename template is empty" );
 
   81   const int numberOfDigits = settings.
fileNameTemplate.count( QLatin1Char( 
'#' ) );
 
   82   if ( numberOfDigits < 0 )
 
   84     error = QObject::tr( 
"Wrong filename template format (must contain #)" );
 
   87   const QString token( numberOfDigits, QLatin1Char( 
'#' ) );
 
   90     error = QObject::tr( 
"Filename template must contain all # placeholders in one continuous group." );
 
   95     error = QObject::tr( 
"Output directory creation failure." );
 
  106   long long currentFrame = 0;
 
  108   while ( currentFrame < totalFrames )
 
  114         error = QObject::tr( 
"Export canceled" );
 
  117       feedback->
setProgress( currentFrame / 
static_cast<double>( totalFrames ) * 100 );
 
  131     const QString frameNoPaddedLeft( QStringLiteral( 
"%1" ).arg( currentFrame, numberOfDigits, 10, QChar( 
'0' ) ) ); 
 
  132     fileName.replace( token, frameNoPaddedLeft );
 
  133     const QString path = QDir( settings.
outputDirectory ).filePath( fileName );
 
  136     img.setDotsPerMeterX( 1000 * ms.
outputDpi() / 25.4 );
 
  137     img.setDotsPerMeterY( 1000 * ms.
outputDpi() / 25.4 );
 
  148     const auto constMDecorations = settings.
decorations;
 
  151       decoration->render( ms, context );
 
  171   if ( isFractional || interval.
originalUnit() == QgsUnitTypes::TemporalUnit::TemporalUnknownUnit )
 
  173     const double duration = interval.
seconds();
 
  174     return start.addMSecs( frame * duration * 1000 );
 
  180       case QgsUnitTypes::TemporalUnit::TemporalMilliseconds:
 
  182       case QgsUnitTypes::TemporalUnit::TemporalSeconds:
 
  184       case QgsUnitTypes::TemporalUnit::TemporalMinutes:
 
  186       case QgsUnitTypes::TemporalUnit::TemporalHours:
 
  188       case QgsUnitTypes::TemporalUnit::TemporalDays:
 
  190       case QgsUnitTypes::TemporalUnit::TemporalWeeks:
 
  192       case QgsUnitTypes::TemporalUnit::TemporalMonths:
 
  194       case QgsUnitTypes::TemporalUnit::TemporalYears:
 
  196       case QgsUnitTypes::TemporalUnit::TemporalDecades:
 
  198       case QgsUnitTypes::TemporalUnit::TemporalCenturies:
 
  200       case QgsUnitTypes::TemporalUnit::TemporalUnknownUnit:
 
  203       case QgsUnitTypes::TemporalUnit::TemporalIrregularStep:
 
  218   if ( timeDuration.
years == 0 && timeDuration.
months == 0 && timeDuration.
weeks == 0 && timeDuration.
days == 0
 
  229   QList<QDateTime> res;
 
  230   QDateTime current = start;
 
  231   maxValuesExceeded = 
false;
 
  232   while ( current <= end )
 
  236     if ( maxValues >= 0 && res.size() > maxValues )
 
  238       maxValuesExceeded = 
true;
 
  242     if ( timeDuration.
years )
 
  243       current = current.addYears( timeDuration.
years );
 
  244     if ( timeDuration.
months )
 
  245       current = current.addMonths( timeDuration.
months );
 
  246     if ( timeDuration.
weeks || timeDuration.
days )
 
  247       current = current.addDays( timeDuration.
weeks * 7 + timeDuration.
days );
 
  249       current = current.addSecs( timeDuration.
hours * 60LL * 60 + timeDuration.
minutes * 60 + timeDuration.
seconds );
 
  257   maxValuesExceeded = 
false;
 
  258   const QStringList parts = 
string.split( 
'/' );
 
  259   if ( parts.length() != 3 )
 
  264   const QDateTime start = QDateTime::fromString( parts.at( 0 ), Qt::ISODate );
 
  265   if ( !start.isValid() )
 
  267   const QDateTime end = QDateTime::fromString( parts.at( 1 ), Qt::ISODate );
 
  268   if ( !end.isValid() )
 
  289     text.append( QString::number( 
years ) );
 
  294     text.append( QString::number( 
months ) );
 
  299     text.append( QString::number( 
days ) );
 
  305     if ( !text.contains( 
'T' ) )
 
  307     text.append( QString::number( 
hours ) );
 
  312     if ( !text.contains( 
'T' ) )
 
  314     text.append( QString::number( 
minutes ) );
 
  319     if ( !text.contains( 
'T' ) )
 
  321     text.append( QString::number( 
seconds ) );
 
  329   long long secs = 0.0;
 
  349   QDateTime resultDateTime = dateTime;
 
  352     resultDateTime = resultDateTime.addYears( 
years );
 
  354     resultDateTime = resultDateTime.addMonths( 
months );
 
  356     resultDateTime = resultDateTime.addDays( 
weeks * 7 + 
days );
 
  360   return resultDateTime;
 
  366   thread_local 
const QRegularExpression sRx( QStringLiteral( R
"(P(?:([\d]+)Y)?(?:([\d]+)M)?(?:([\d]+)W)?(?:([\d]+)D)?(?:T(?:([\d]+)H)?(?:([\d]+)M)?(?:([\d\.]+)S)?)?$)" ) ); 
  368   const QRegularExpressionMatch match = sRx.match( 
string );
 
  370   if ( match.hasMatch() )
 
  373     duration.
years = match.captured( 1 ).toInt();
 
  374     duration.
months = match.captured( 2 ).toInt();
 
  375     duration.
weeks = match.captured( 3 ).toInt();
 
  376     duration.
days = match.captured( 4 ).toInt();
 
  377     duration.
hours = match.captured( 5 ).toInt();
 
  378     duration.
minutes = match.captured( 6 ).toInt();
 
  379     duration.
seconds = match.captured( 7 ).toDouble();
 
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 SIP_HOLDGIL
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.
static const int MINUTE
Seconds per minute.
double originalDuration() const
Returns the original interval duration.
static const int MONTHS
Seconds per month, based on 30 day month.
double seconds() const
Returns the interval duration in seconds.
static const int HOUR
Seconds per hour.
static const int DAY
Seconds per day.
static const int YEARS
Seconds per year (average)
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...
virtual QList< QgsDateTimeRange > allTemporalRanges(QgsMapLayer *layer) const
Attempts to calculate the overall list of all temporal extents which are contained in the specified l...
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()
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.
void setFrameDuration(const QgsInterval &duration)
Sets the frame duration, which dictates the temporal length of each frame in the animation.
QgsExpressionContextScope * createExpressionContextScope() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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 QList< QDateTime > calculateDateTimesUsingDuration(const QDateTime &start, const QDateTime &end, const QString &duration, bool &ok, bool &maxValuesExceeded, int maxValues=-1)
Calculates a complete list of datetimes between start and end, using the specified ISO8601 duration s...
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.
static QList< QgsDateTimeRange > usedTemporalRangesForProject(QgsProject *project)
Calculates all temporal ranges which are in use for a project.
static QDateTime calculateFrameTime(const QDateTime &start, const long long frame, const QgsInterval &interval)
Calculates the frame time for an animation.
static QList< QDateTime > calculateDateTimesFromISO8601(const QString &string, bool &ok, bool &maxValuesExceeded, int maxValues=-1)
Calculates a complete list of datetimes from a ISO8601 string containing a duration (eg "2021-03-23T0...
Contains utility methods for working with temporal layers and projects.
long long toSeconds() const
Returns the total duration in seconds.
QString toString() const
Converts the duration to an ISO8601 duration string.
static QgsTimeDuration fromString(const QString &string, bool &ok)
Creates a QgsTimeDuration from a string value.
QDateTime addToDateTime(const QDateTime &dateTime)
Adds this duration to a starting dateTime value.
QgsInterval toInterval() const
Converts the duration to an interval value.
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.