Skip to content

Commit 1924ecc

Browse files
committedFeb 13, 2013
fix windows build
1 parent f29b558 commit 1924ecc

File tree

1 file changed

+66
-55
lines changed

1 file changed

+66
-55
lines changed
 

‎src/core/composer/qgsatlascomposition.cpp

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,31 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
5757
// Private class only used for the sorting of features
5858
class FieldSorter
5959
{
60-
public:
61-
FieldSorter( QgsAtlasComposition::SorterKeys& keys, bool ascending = true ) : mKeys( keys ), mAscending( ascending ) {}
62-
63-
bool operator()( const QgsFeatureId& id1, const QgsFeatureId& id2 )
64-
{
65-
bool result;
66-
if ( mKeys[ id1 ].type() == QVariant::Int ) {
67-
result = mKeys[ id1 ].toInt() < mKeys[ id2 ].toInt();
68-
}
69-
else if ( mKeys[ id1 ].type() == QVariant::Double ) {
70-
result = mKeys[ id1 ].toDouble() < mKeys[ id2 ].toDouble();
71-
}
72-
else if ( mKeys[ id1 ].type() == QVariant::String ) {
73-
result = (QString::localeAwareCompare(mKeys[ id1 ].toString(), mKeys[ id2 ].toString()) < 0);
74-
}
75-
76-
return mAscending ? result : !result;
77-
}
78-
private:
79-
QgsAtlasComposition::SorterKeys& mKeys;
80-
bool mAscending;
60+
public:
61+
FieldSorter( QgsAtlasComposition::SorterKeys& keys, bool ascending = true ) : mKeys( keys ), mAscending( ascending ) {}
62+
63+
bool operator()( const QgsFeatureId& id1, const QgsFeatureId& id2 )
64+
{
65+
bool result = true;
66+
67+
if ( mKeys[ id1 ].type() == QVariant::Int )
68+
{
69+
result = mKeys[ id1 ].toInt() < mKeys[ id2 ].toInt();
70+
}
71+
else if ( mKeys[ id1 ].type() == QVariant::Double )
72+
{
73+
result = mKeys[ id1 ].toDouble() < mKeys[ id2 ].toDouble();
74+
}
75+
else if ( mKeys[ id1 ].type() == QVariant::String )
76+
{
77+
result = ( QString::localeAwareCompare( mKeys[ id1 ].toString(), mKeys[ id2 ].toString() ) < 0 );
78+
}
79+
80+
return mAscending ? result : !result;
81+
}
82+
private:
83+
QgsAtlasComposition::SorterKeys& mKeys;
84+
bool mAscending;
8185
};
8286

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

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

115119
std::auto_ptr<QgsExpression> filterExpression;
116-
if ( mFeatureFilter.size() > 0 ) {
117-
filterExpression = std::auto_ptr<QgsExpression>(new QgsExpression( mFeatureFilter ));
118-
if ( filterExpression->hasParserError() )
119-
{
120-
throw std::runtime_error( tr("Feature filter parser error: %1").arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
121-
}
120+
if ( mFeatureFilter.size() > 0 )
121+
{
122+
filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
123+
if ( filterExpression->hasParserError() )
124+
{
125+
throw std::runtime_error( tr( "Feature filter parser error: %1" ).arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
126+
}
122127
}
123128

124129
// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
@@ -128,29 +133,33 @@ void QgsAtlasComposition::beginRender()
128133
mFeatureKeys.clear();
129134
while ( fit.nextFeature( feat ) )
130135
{
131-
if ( mFeatureFilter.size() > 0 ) {
132-
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
133-
if ( filterExpression->hasEvalError() )
134-
{
135-
throw std::runtime_error( tr("Feature filter eval error: %1").arg( filterExpression->evalErrorString()).toLocal8Bit().data() );
136-
}
137-
138-
// skip this feature if the filter evaluation if false
139-
if ( !result.toBool() ) {
140-
continue;
141-
}
142-
}
143-
mFeatureIds.push_back( feat.id() );
144-
145-
if ( mSortFeatures ) {
146-
mFeatureKeys.insert( std::make_pair( feat.id(), feat.attributes()[ mSortKeyAttributeIdx ] ) );
147-
}
136+
if ( mFeatureFilter.size() > 0 )
137+
{
138+
QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
139+
if ( filterExpression->hasEvalError() )
140+
{
141+
throw std::runtime_error( tr( "Feature filter eval error: %1" ).arg( filterExpression->evalErrorString() ).toLocal8Bit().data() );
142+
}
143+
144+
// skip this feature if the filter evaluation if false
145+
if ( !result.toBool() )
146+
{
147+
continue;
148+
}
149+
}
150+
mFeatureIds.push_back( feat.id() );
151+
152+
if ( mSortFeatures )
153+
{
154+
mFeatureKeys.insert( std::make_pair( feat.id(), feat.attributes()[ mSortKeyAttributeIdx ] ) );
155+
}
148156
}
149157

150158
// sort features, if asked for
151-
if ( mSortFeatures ) {
152-
FieldSorter sorter( mFeatureKeys, mSortAscending );
153-
std::sort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
159+
if ( mSortFeatures )
160+
{
161+
FieldSorter sorter( mFeatureKeys, mSortAscending );
162+
qSort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
154163
}
155164

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

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

347356
atlasElem.setAttribute( "sortFeatures", mSortFeatures ? "true" : "false" );
348-
if ( mSortFeatures ) {
349-
atlasElem.setAttribute( "sortKey", QString::number(mSortKeyAttributeIdx) );
350-
atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
357+
if ( mSortFeatures )
358+
{
359+
atlasElem.setAttribute( "sortKey", QString::number( mSortKeyAttributeIdx ) );
360+
atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
351361
}
352362
atlasElem.setAttribute( "featureFilter", mFeatureFilter );
353363

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

394404
mSortFeatures = atlasElem.attribute( "sortFeatures", "false" ) == "true" ? true : false;
395-
if ( mSortFeatures ) {
396-
mSortKeyAttributeIdx = atlasElem.attribute( "sortKey", "0" ).toInt();
397-
mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
405+
if ( mSortFeatures )
406+
{
407+
mSortKeyAttributeIdx = atlasElem.attribute( "sortKey", "0" ).toInt();
408+
mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
398409
}
399410
mFeatureFilter = atlasElem.attribute( "featureFilter", "" );
400411

0 commit comments

Comments
 (0)
Please sign in to comment.