@@ -57,27 +57,31 @@ void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
57
57
// Private class only used for the sorting of features
58
58
class FieldSorter
59
59
{
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 ;
81
85
};
82
86
83
87
void QgsAtlasComposition::beginRender ()
@@ -102,7 +106,7 @@ void QgsAtlasComposition::beginRender()
102
106
// test for evaluation errors
103
107
if ( mFilenameExpr ->hasParserError () )
104
108
{
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 () );
106
110
}
107
111
108
112
// prepare the filename expression
@@ -113,12 +117,13 @@ void QgsAtlasComposition::beginRender()
113
117
QgsFeatureIterator fit = mCoverageLayer ->getFeatures ();
114
118
115
119
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
+ }
122
127
}
123
128
124
129
// We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
@@ -128,29 +133,33 @@ void QgsAtlasComposition::beginRender()
128
133
mFeatureKeys .clear ();
129
134
while ( fit.nextFeature ( feat ) )
130
135
{
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
+ }
148
156
}
149
157
150
158
// 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 );
154
163
}
155
164
156
165
mOrigExtent = mComposerMap ->extent ();
@@ -221,7 +230,7 @@ void QgsAtlasComposition::prepareForFeature( size_t featureI )
221
230
QVariant filenameRes = mFilenameExpr ->evaluate ( &mCurrentFeature );
222
231
if ( mFilenameExpr ->hasEvalError () )
223
232
{
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 () );
225
234
}
226
235
227
236
mCurrentFilename = filenameRes.toString ();
@@ -345,9 +354,10 @@ void QgsAtlasComposition::writeXML( QDomElement& elem, QDomDocument& doc ) const
345
354
atlasElem.setAttribute ( " filenamePattern" , mFilenamePattern );
346
355
347
356
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" );
351
361
}
352
362
atlasElem.setAttribute ( " featureFilter" , mFeatureFilter );
353
363
@@ -392,9 +402,10 @@ void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocum
392
402
mFilenamePattern = atlasElem.attribute ( " filenamePattern" , " " );
393
403
394
404
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 ;
398
409
}
399
410
mFeatureFilter = atlasElem.attribute ( " featureFilter" , " " );
400
411
0 commit comments