Skip to content
Permalink
Browse files

Don't store a long-term expression for atlas file name

  • Loading branch information
nyalldawson committed Feb 11, 2021
1 parent 2e1fea6 commit e90ebb7de219af7ac0a25baf70fb04d5db6aed81
Showing with 14 additions and 10 deletions.
  1. +13 −9 src/core/layout/qgslayoutatlas.cpp
  2. +1 −1 src/core/layout/qgslayoutatlas.h
@@ -536,17 +536,17 @@ bool QgsLayoutAtlas::updateFilenameExpression( QString &error )

if ( !mFilenameExpressionString.isEmpty() )
{
mFilenameExpression = QgsExpression( mFilenameExpressionString );
QgsExpression filenameExpression( mFilenameExpressionString );
// expression used to evaluate each filename
// test for evaluation errors
if ( mFilenameExpression.hasParserError() )
if ( filenameExpression.hasParserError() )
{
error = mFilenameExpression.parserErrorString();
error = filenameExpression.parserErrorString();
return false;
}

// prepare the filename expression
evalResult = mFilenameExpression.prepare( &expressionContext );
evalResult = filenameExpression.prepare( &expressionContext );
}

// regenerate current filename
@@ -557,7 +557,7 @@ bool QgsLayoutAtlas::updateFilenameExpression( QString &error )

if ( ! evalResult )
{
error = mFilenameExpression.evalErrorString();
error = mFilenameExpressionError;
}

return evalResult;
@@ -566,12 +566,16 @@ bool QgsLayoutAtlas::updateFilenameExpression( QString &error )
bool QgsLayoutAtlas::evalFeatureFilename( const QgsExpressionContext &context )
{
//generate filename for current atlas feature
if ( !mFilenameExpressionString.isEmpty() && mFilenameExpression.isValid() )
mFilenameExpressionError.clear();
if ( !mFilenameExpressionString.isEmpty() )
{
QVariant filenameRes = mFilenameExpression.evaluate( &context );
if ( mFilenameExpression.hasEvalError() )
QgsExpression filenameExpression( mFilenameExpressionString );
filenameExpression.prepare( &context );
QVariant filenameRes = filenameExpression.evaluate( &context );
if ( filenameExpression.hasEvalError() )
{
QgsMessageLog::logMessage( tr( "Atlas filename evaluation error: %1" ).arg( mFilenameExpression.evalErrorString() ), tr( "Layout" ) );
mFilenameExpressionError = filenameExpression.evalErrorString();
QgsMessageLog::logMessage( tr( "Atlas filename evaluation error: %1" ).arg( filenameExpression.evalErrorString() ), tr( "Layout" ) );
return false;
}

@@ -366,8 +366,8 @@ class CORE_EXPORT QgsLayoutAtlas : public QObject, public QgsAbstractLayoutItera
bool mEnabled = false;
bool mHideCoverage = false;
QString mFilenameExpressionString;
QString mFilenameExpressionError;

QgsExpression mFilenameExpression;
QgsVectorLayerRef mCoverageLayer;

QString mCurrentFilename;

0 comments on commit e90ebb7

Please sign in to comment.