Skip to content
Permalink
Browse files
fix windows build
  • Loading branch information
jef-n committed Feb 13, 2013
1 parent f29b558 commit 1924ecce13bc4ca38853ef7762d74d10aee947ea
Showing with 66 additions and 55 deletions.
  1. +66 −55 src/core/composer/qgsatlascomposition.cpp
@@ -57,27 +57,31 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
// Private class only used for the sorting of features
class FieldSorter
{
public:
FieldSorter( QgsAtlasComposition::SorterKeys& keys, bool ascending = true ) : mKeys( keys ), mAscending( ascending ) {}

bool operator()( const QgsFeatureId& id1, const QgsFeatureId& id2 )
{
bool result;
if ( mKeys[ id1 ].type() == QVariant::Int ) {
result = mKeys[ id1 ].toInt() < mKeys[ id2 ].toInt();
}
else if ( mKeys[ id1 ].type() == QVariant::Double ) {
result = mKeys[ id1 ].toDouble() < mKeys[ id2 ].toDouble();
}
else if ( mKeys[ id1 ].type() == QVariant::String ) {
result = (QString::localeAwareCompare(mKeys[ id1 ].toString(), mKeys[ id2 ].toString()) < 0);
}

return mAscending ? result : !result;
}
private:
QgsAtlasComposition::SorterKeys& mKeys;
bool mAscending;
public:
FieldSorter( QgsAtlasComposition::SorterKeys& keys, bool ascending = true ) : mKeys( keys ), mAscending( ascending ) {}

bool operator()( const QgsFeatureId& id1, const QgsFeatureId& id2 )
{
bool result = true;

if ( mKeys[ id1 ].type() == QVariant::Int )
{
result = mKeys[ id1 ].toInt() < mKeys[ id2 ].toInt();
}
else if ( mKeys[ id1 ].type() == QVariant::Double )
{
result = mKeys[ id1 ].toDouble() < mKeys[ id2 ].toDouble();
}
else if ( mKeys[ id1 ].type() == QVariant::String )
{
result = ( QString::localeAwareCompare( mKeys[ id1 ].toString(), mKeys[ id2 ].toString() ) < 0 );
}

return mAscending ? result : !result;
}
private:
QgsAtlasComposition::SorterKeys& mKeys;
bool mAscending;
};

void QgsAtlasComposition::beginRender()
@@ -102,7 +106,7 @@ void QgsAtlasComposition::beginRender()
// test for evaluation errors
if ( mFilenameExpr->hasParserError() )
{
throw std::runtime_error( tr("Filename parsing error: %1").arg(mFilenameExpr->parserErrorString()).toLocal8Bit().data() );
throw std::runtime_error( tr( "Filename parsing error: %1" ).arg( mFilenameExpr->parserErrorString() ).toLocal8Bit().data() );
}

// prepare the filename expression
@@ -113,12 +117,13 @@ void QgsAtlasComposition::beginRender()
QgsFeatureIterator fit = mCoverageLayer->getFeatures();

std::auto_ptr<QgsExpression> filterExpression;
if ( mFeatureFilter.size() > 0 ) {
filterExpression = std::auto_ptr<QgsExpression>(new QgsExpression( mFeatureFilter ));
if ( filterExpression->hasParserError() )
{
throw std::runtime_error( tr("Feature filter parser error: %1").arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
}
if ( mFeatureFilter.size() > 0 )
{
filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
if ( filterExpression->hasParserError() )
{
throw std::runtime_error( tr( "Feature filter parser error: %1" ).arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
}
}

// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
@@ -128,29 +133,33 @@ void QgsAtlasComposition::beginRender()
mFeatureKeys.clear();
while ( fit.nextFeature( feat ) )
{
if ( mFeatureFilter.size() > 0 ) {
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
if ( filterExpression->hasEvalError() )
{
throw std::runtime_error( tr("Feature filter eval error: %1").arg( filterExpression->evalErrorString()).toLocal8Bit().data() );
}

// skip this feature if the filter evaluation if false
if ( !result.toBool() ) {
continue;
}
}
mFeatureIds.push_back( feat.id() );

if ( mSortFeatures ) {
mFeatureKeys.insert( std::make_pair( feat.id(), feat.attributes()[ mSortKeyAttributeIdx ] ) );
}
if ( mFeatureFilter.size() > 0 )
{
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
if ( filterExpression->hasEvalError() )
{
throw std::runtime_error( tr( "Feature filter eval error: %1" ).arg( filterExpression->evalErrorString() ).toLocal8Bit().data() );
}

// skip this feature if the filter evaluation if false
if ( !result.toBool() )
{
continue;
}
}
mFeatureIds.push_back( feat.id() );

if ( mSortFeatures )
{
mFeatureKeys.insert( std::make_pair( feat.id(), feat.attributes()[ mSortKeyAttributeIdx ] ) );
}
}

// sort features, if asked for
if ( mSortFeatures ) {
FieldSorter sorter( mFeatureKeys, mSortAscending );
std::sort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
if ( mSortFeatures )
{
FieldSorter sorter( mFeatureKeys, mSortAscending );
qSort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
}

mOrigExtent = mComposerMap->extent();
@@ -221,7 +230,7 @@ void QgsAtlasComposition::prepareForFeature( size_t featureI )
QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature );
if ( mFilenameExpr->hasEvalError() )
{
throw std::runtime_error( tr("Filename eval error: %1").arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
}

mCurrentFilename = filenameRes.toString();
@@ -345,9 +354,10 @@ void QgsAtlasComposition::writeXML( QDomElement& elem, QDomDocument& doc ) const
atlasElem.setAttribute( "filenamePattern", mFilenamePattern );

atlasElem.setAttribute( "sortFeatures", mSortFeatures ? "true" : "false" );
if ( mSortFeatures ) {
atlasElem.setAttribute( "sortKey", QString::number(mSortKeyAttributeIdx) );
atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
if ( mSortFeatures )
{
atlasElem.setAttribute( "sortKey", QString::number( mSortKeyAttributeIdx ) );
atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
}
atlasElem.setAttribute( "featureFilter", mFeatureFilter );

@@ -392,9 +402,10 @@ void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocum
mFilenamePattern = atlasElem.attribute( "filenamePattern", "" );

mSortFeatures = atlasElem.attribute( "sortFeatures", "false" ) == "true" ? true : false;
if ( mSortFeatures ) {
mSortKeyAttributeIdx = atlasElem.attribute( "sortKey", "0" ).toInt();
mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
if ( mSortFeatures )
{
mSortKeyAttributeIdx = atlasElem.attribute( "sortKey", "0" ).toInt();
mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
}
mFeatureFilter = atlasElem.attribute( "featureFilter", "" );

0 comments on commit 1924ecc

Please sign in to comment.