Skip to content

Commit

Permalink
[composer] Also re-evaluate current features filename so that filenam…
Browse files Browse the repository at this point in the history
…e expressions take effect immediately
  • Loading branch information
nyalldawson committed Jan 1, 2014
1 parent 8b60d8f commit 21a85c6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/core/composer/qgsatlascomposition.cpp
Expand Up @@ -297,17 +297,8 @@ void QgsAtlasComposition::prepareForFeature( int featureI )
QgsExpression::setSpecialColumn( "$atlasfeatureid", mCurrentFeature.id() );
QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( *mCurrentFeature.geometry() ) );

if ( !mSingleFile && mFilenamePattern.size() > 0 )
{
QgsExpression::setSpecialColumn( "$feature", QVariant(( int )featureI + 1 ) );
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
if ( mFilenameExpr->hasEvalError() )
{
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
}

mCurrentFilename = filenameRes.toString();
}
// generate filename for current feature
evalFeatureFilename();

//
// compute the new extent
Expand Down Expand Up @@ -548,6 +539,28 @@ void QgsAtlasComposition::updateFilenameExpression()
// prepare the filename expression
mFilenameExpr->prepare( fields );
}

//if atlas preview is currently enabled, regenerate filename for current feature
if ( mComposition->atlasPreviewEnabled() )
{
evalFeatureFilename();
}

}

void QgsAtlasComposition::evalFeatureFilename()
{
//generate filename for current atlas feature
if ( !mSingleFile && mFilenamePattern.size() > 0 )
{
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
if ( mFilenameExpr->hasEvalError() )
{
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
}

mCurrentFilename = filenameRes.toString();
}
}


3 changes: 3 additions & 0 deletions src/core/composer/qgsatlascomposition.h
Expand Up @@ -124,6 +124,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
/**Updates the filename expression*/
void updateFilenameExpression();

/**Evaluates filename for current feature*/
void evalFeatureFilename();

QgsComposition* mComposition;

bool mEnabled;
Expand Down

0 comments on commit 21a85c6

Please sign in to comment.