Skip to content
Permalink
Browse files

[composer] Also re-evaluate current features filename so that filenam…

…e expressions take effect immediately
  • Loading branch information
nyalldawson committed Jan 1, 2014
1 parent 8b60d8f commit 21a85c6894d8c086d70334e1cc141e2dd0d4e2b0
Showing with 27 additions and 11 deletions.
  1. +24 −11 src/core/composer/qgsatlascomposition.cpp
  2. +3 −0 src/core/composer/qgsatlascomposition.h
@@ -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
@@ -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();
}
}


@@ -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;

0 comments on commit 21a85c6

Please sign in to comment.
You can’t perform that action at this time.