Skip to content

Commit 21a85c6

Browse files
committed
[composer] Also re-evaluate current features filename so that filename expressions take effect immediately
1 parent 8b60d8f commit 21a85c6

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/core/composer/qgsatlascomposition.cpp

+24-11
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,8 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
297297
QgsExpression::setSpecialColumn( "$atlasfeatureid", mCurrentFeature.id() );
298298
QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( *mCurrentFeature.geometry() ) );
299299

300-
if ( !mSingleFile && mFilenamePattern.size() > 0 )
301-
{
302-
QgsExpression::setSpecialColumn( "$feature", QVariant(( int )featureI + 1 ) );
303-
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
304-
if ( mFilenameExpr->hasEvalError() )
305-
{
306-
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
307-
}
308-
309-
mCurrentFilename = filenameRes.toString();
310-
}
300+
// generate filename for current feature
301+
evalFeatureFilename();
311302

312303
//
313304
// compute the new extent
@@ -548,6 +539,28 @@ void QgsAtlasComposition::updateFilenameExpression()
548539
// prepare the filename expression
549540
mFilenameExpr->prepare( fields );
550541
}
542+
543+
//if atlas preview is currently enabled, regenerate filename for current feature
544+
if ( mComposition->atlasPreviewEnabled() )
545+
{
546+
evalFeatureFilename();
547+
}
548+
549+
}
550+
551+
void QgsAtlasComposition::evalFeatureFilename()
552+
{
553+
//generate filename for current atlas feature
554+
if ( !mSingleFile && mFilenamePattern.size() > 0 )
555+
{
556+
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
557+
if ( mFilenameExpr->hasEvalError() )
558+
{
559+
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
560+
}
561+
562+
mCurrentFilename = filenameRes.toString();
563+
}
551564
}
552565

553566

src/core/composer/qgsatlascomposition.h

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
124124
/**Updates the filename expression*/
125125
void updateFilenameExpression();
126126

127+
/**Evaluates filename for current feature*/
128+
void evalFeatureFilename();
129+
127130
QgsComposition* mComposition;
128131

129132
bool mEnabled;

0 commit comments

Comments
 (0)