@@ -67,11 +67,16 @@ struct QgsAtlasRendering::QgsAtlasRenderingImpl
67
67
68
68
QgsAtlasRendering::QgsAtlasRendering ( QgsComposition* composition )
69
69
{
70
- impl = std::auto_ptr<QgsAtlasRendering::QgsAtlasRenderingImpl>( new QgsAtlasRendering::QgsAtlasRenderingImpl () );
70
+ impl = new QgsAtlasRendering::QgsAtlasRenderingImpl ();
71
71
impl->composition = composition;
72
72
impl->nFeatures = 0 ;
73
73
}
74
74
75
+ QgsAtlasRendering::~QgsAtlasRendering ()
76
+ {
77
+ delete impl;
78
+ }
79
+
75
80
void QgsAtlasRendering::begin ( const QString& filenamePattern )
76
81
{
77
82
if ( !impl->composition || !impl->composition ->atlasMap () || !impl->composition ->atlasMap ()->atlasCoverageLayer () )
@@ -131,7 +136,7 @@ void QgsAtlasRendering::begin( const QString& filenamePattern )
131
136
}
132
137
133
138
// special columns for expressions
134
- QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant ( ( int )impl->nFeatures ) );
139
+ QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant (( int )impl->nFeatures ) );
135
140
}
136
141
137
142
void QgsAtlasRendering::prepareForFeature ( size_t featureI )
@@ -140,24 +145,24 @@ void QgsAtlasRendering::prepareForFeature( size_t featureI )
140
145
return ;
141
146
142
147
QgsFeature* fit = &impl->features [featureI];
143
-
148
+
144
149
if ( impl->filenamePattern .size () > 0 )
145
150
{
146
- QgsExpression::setSpecialColumn ( " $feature" , QVariant ( ( int )featureI + 1 ) );
151
+ QgsExpression::setSpecialColumn ( " $feature" , QVariant (( int )featureI + 1 ) );
147
152
QVariant filenameRes = impl->filenameExpr ->evaluate ( &*fit );
148
153
if ( impl->filenameExpr ->hasEvalError () )
149
154
{
150
155
throw std::runtime_error ( " Filename eval error: " + impl->filenameExpr ->evalErrorString ().toStdString () );
151
156
}
152
-
157
+
153
158
impl->currentFilename = filenameRes.toString ();
154
159
}
155
-
160
+
156
161
//
157
162
// compute the new extent
158
163
// keep the original aspect ratio
159
164
// and apply a margin
160
-
165
+
161
166
// QgsGeometry::boundingBox is expressed in the geometry"s native CRS
162
167
// We have to transform the grometry to the destination CRS and ask for the bounding box
163
168
// Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
@@ -171,63 +176,63 @@ void QgsAtlasRendering::prepareForFeature( size_t featureI )
171
176
double ya1 = geom_rect.yMinimum ();
172
177
double ya2 = geom_rect.yMaximum ();
173
178
QgsRectangle new_extent = geom_rect;
174
-
179
+
175
180
// restore the original extent
176
181
// (successive calls to setNewExtent tend to deform the original rectangle)
177
182
impl->composition ->atlasMap ()->setNewExtent ( impl->origExtent );
178
-
183
+
179
184
if ( impl->composition ->atlasMap ()->atlasFixedScale () )
180
185
{
181
186
// only translate, keep the original scale (i.e. width x height)
182
-
183
- double geom_center_x = (xa1 + xa2) / 2.0 ;
184
- double geom_center_y = (ya1 + ya2) / 2.0 ;
187
+
188
+ double geom_center_x = ( xa1 + xa2 ) / 2.0 ;
189
+ double geom_center_y = ( ya1 + ya2 ) / 2.0 ;
185
190
double xx = geom_center_x - impl->origExtent .width () / 2.0 ;
186
191
double yy = geom_center_y - impl->origExtent .height () / 2.0 ;
187
192
new_extent = QgsRectangle ( xx,
188
- yy,
189
- xx + impl->origExtent .width (),
190
- yy + impl->origExtent .height () );
193
+ yy,
194
+ xx + impl->origExtent .width (),
195
+ yy + impl->origExtent .height () );
191
196
}
192
197
else
193
198
{
194
199
// auto scale
195
-
200
+
196
201
double geom_ratio = geom_rect.width () / geom_rect.height ();
197
202
double map_ratio = impl->origExtent .width () / impl->origExtent .height ();
198
-
203
+
199
204
// geometry height is too big
200
205
if ( geom_ratio < map_ratio )
201
206
{
202
- new_extent = QgsRectangle ( ( xa1 + xa2 + map_ratio * (ya1 - ya2) ) / 2.0 ,
203
- ya1,
204
- xa1 + map_ratio * (ya2 - ya1),
205
- ya2);
207
+ new_extent = QgsRectangle (( xa1 + xa2 + map_ratio * ( ya1 - ya2 ) ) / 2.0 ,
208
+ ya1,
209
+ xa1 + map_ratio * ( ya2 - ya1 ),
210
+ ya2 );
206
211
}
207
212
// geometry width is too big
208
213
else if ( geom_ratio > map_ratio )
209
214
{
210
215
new_extent = QgsRectangle ( xa1,
211
- ( ya1 + ya2 + (xa1 - xa2) / map_ratio) / 2.0 ,
212
- xa2,
213
- ya1 + (xa2 - xa1) / map_ratio);
216
+ ( ya1 + ya2 + ( xa1 - xa2 ) / map_ratio ) / 2.0 ,
217
+ xa2,
218
+ ya1 + ( xa2 - xa1 ) / map_ratio );
214
219
}
215
220
if ( impl->composition ->atlasMap ()->atlasMargin () > 0.0 )
216
221
{
217
222
new_extent.scale ( 1 + impl->composition ->atlasMap ()->atlasMargin () );
218
223
}
219
224
}
220
-
225
+
221
226
// evaluate label expressions
222
227
QList<QgsComposerLabel*> labels;
223
228
impl->composition ->composerItems ( labels );
224
- QgsExpression::setSpecialColumn ( " $feature" , QVariant ( ( int )featureI + 1 ) );
225
-
229
+ QgsExpression::setSpecialColumn ( " $feature" , QVariant (( int )featureI + 1 ) );
230
+
226
231
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin (); lit != labels.end (); ++lit )
227
232
{
228
- (*lit)->setExpressionContext ( fit, impl->composition ->atlasMap ()->atlasCoverageLayer () );
233
+ ( *lit )->setExpressionContext ( fit, impl->composition ->atlasMap ()->atlasCoverageLayer () );
229
234
}
230
-
235
+
231
236
// set the new extent (and render)
232
237
impl->composition ->atlasMap ()->setNewExtent ( new_extent );
233
238
}
@@ -252,7 +257,7 @@ void QgsAtlasRendering::end()
252
257
impl->composition ->composerItems ( labels );
253
258
for ( QList<QgsComposerLabel*>::iterator lit = labels.begin (); lit != labels.end (); ++lit )
254
259
{
255
- (*lit)->setExpressionContext ( 0 , 0 );
260
+ ( *lit )->setExpressionContext ( 0 , 0 );
256
261
}
257
262
258
263
// restore the coverage visibility
@@ -269,9 +274,9 @@ void QgsAtlasRendering::end()
269
274
}
270
275
271
276
QgsComposition::QgsComposition ( QgsMapRenderer* mapRenderer ) :
272
- QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
273
- mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
274
- mAtlasMap( 0 )
277
+ QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
278
+ mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
279
+ mAtlasMap( 0 )
275
280
{
276
281
setBackgroundBrush ( Qt::gray );
277
282
addPaperItem ();
@@ -280,23 +285,23 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ) :
280
285
loadSettings ();
281
286
282
287
// declare special columns with a default value
283
- QgsExpression::setSpecialColumn ( " $page" , QVariant ((int ) 0 ) );
284
- QgsExpression::setSpecialColumn ( " $feature" , QVariant ((int ) 0 ) );
285
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ((int ) 0 ) );
286
- QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant ((int ) 0 ) );
288
+ QgsExpression::setSpecialColumn ( " $page" , QVariant (( int ) 0 ) );
289
+ QgsExpression::setSpecialColumn ( " $feature" , QVariant (( int ) 0 ) );
290
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int ) 0 ) );
291
+ QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant (( int ) 0 ) );
287
292
}
288
293
289
294
QgsComposition::QgsComposition ():
290
- QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
291
- mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
292
- mAtlasMap( 0 )
295
+ QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
296
+ mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
297
+ mAtlasMap( 0 )
293
298
{
294
299
loadSettings ();
295
300
296
- QgsExpression::setSpecialColumn ( " $page" , QVariant ((int ) 0 ) );
297
- QgsExpression::setSpecialColumn ( " $feature" , QVariant ((int ) 0 ) );
298
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ((int ) 0 ) );
299
- QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant ((int ) 0 ) );
301
+ QgsExpression::setSpecialColumn ( " $page" , QVariant (( int ) 0 ) );
302
+ QgsExpression::setSpecialColumn ( " $feature" , QVariant (( int ) 0 ) );
303
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int ) 0 ) );
304
+ QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant (( int ) 0 ) );
300
305
}
301
306
302
307
QgsComposition::~QgsComposition ()
@@ -356,7 +361,7 @@ void QgsComposition::setNumPages( int pages )
356
361
}
357
362
358
363
// update the corresponding variable
359
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ((int )numPages ()) );
364
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int )numPages () ) );
360
365
361
366
emit nPagesChanged ();
362
367
}
@@ -394,12 +399,12 @@ QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
394
399
395
400
int QgsComposition::pageNumberAt ( const QPointF& position ) const
396
401
{
397
- return position.y () / (paperHeight () + spaceBetweenPages () );
402
+ return position.y () / ( paperHeight () + spaceBetweenPages () );
398
403
}
399
404
400
405
int QgsComposition::itemPageNumber ( const QgsComposerItem* item ) const
401
406
{
402
- return pageNumberAt ( QPointF ( item->transform ().dx (), item->transform ().dy ()) );
407
+ return pageNumberAt ( QPointF ( item->transform ().dx (), item->transform ().dy () ) );
403
408
}
404
409
405
410
QList<QgsComposerItem*> QgsComposition::selectedComposerItems ()
@@ -1715,7 +1720,7 @@ void QgsComposition::addPaperItem()
1715
1720
paperItem->setZValue ( 0 );
1716
1721
mPages .push_back ( paperItem );
1717
1722
1718
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ((int )mPages .size ()) );
1723
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int )mPages .size () ) );
1719
1724
}
1720
1725
1721
1726
void QgsComposition::removePaperItems ()
@@ -1725,7 +1730,7 @@ void QgsComposition::removePaperItems()
1725
1730
delete mPages .at ( i );
1726
1731
}
1727
1732
mPages .clear ();
1728
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ((int ) 0 ) );
1733
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int ) 0 ) );
1729
1734
}
1730
1735
1731
1736
void QgsComposition::deleteAndRemoveMultiFrames ()
@@ -1756,7 +1761,7 @@ void QgsComposition::exportAsPDF( const QString& file )
1756
1761
1757
1762
void QgsComposition::doPrint ( QPrinter& printer, QPainter& p )
1758
1763
{
1759
- // QgsComposition starts page numbering at 0
1764
+ // QgsComposition starts page numbering at 0
1760
1765
int fromPage = ( printer.fromPage () < 1 ) ? 0 : printer.fromPage () - 1 ;
1761
1766
int toPage = ( printer.toPage () < 1 ) ? numPages () - 1 : printer.toPage () - 1 ;
1762
1767
@@ -1859,11 +1864,11 @@ void QgsComposition::setAtlasMap( QgsComposerMap* map )
1859
1864
mAtlasMap = map;
1860
1865
if ( map != 0 )
1861
1866
{
1862
- QObject::connect ( map, SIGNAL ( atlasCoverageLayerChanged ( QgsVectorLayer* )), this , SLOT ( onAtlasCoverageChanged ( QgsVectorLayer* ) ) );
1867
+ QObject::connect ( map, SIGNAL ( atlasCoverageLayerChanged ( QgsVectorLayer* ) ), this , SLOT ( onAtlasCoverageChanged ( QgsVectorLayer* ) ) );
1863
1868
}
1864
1869
else
1865
1870
{
1866
- QObject::disconnect ( map, SIGNAL ( atlasCoverageLayerChanged ( QgsVectorLayer* )), this , SLOT ( onAtlasCoverageChanged ( QgsVectorLayer* ) ) );
1871
+ QObject::disconnect ( map, SIGNAL ( atlasCoverageLayerChanged ( QgsVectorLayer* ) ), this , SLOT ( onAtlasCoverageChanged ( QgsVectorLayer* ) ) );
1867
1872
}
1868
1873
}
1869
1874
@@ -1873,14 +1878,14 @@ void QgsComposition::onAtlasCoverageChanged( QgsVectorLayer* )
1873
1878
if ( mAtlasMap != 0 && mAtlasMap ->atlasCoverageLayer () != 0 )
1874
1879
{
1875
1880
QgsVectorDataProvider* provider = mAtlasMap ->atlasCoverageLayer ()->dataProvider ();
1876
- QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant ( ( int )provider->featureCount () ) );
1881
+ QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant (( int )provider->featureCount () ) );
1877
1882
}
1878
1883
else
1879
1884
{
1880
- QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant ( ( int )0 ) );
1885
+ QgsExpression::setSpecialColumn ( " $numfeatures" , QVariant (( int )0 ) );
1881
1886
}
1882
- //
1883
- QgsExpression::setSpecialColumn ( " $numpages" , QVariant ( ( int )numPages () ) );
1887
+ //
1888
+ QgsExpression::setSpecialColumn ( " $numpages" , QVariant (( int )numPages () ) );
1884
1889
}
1885
1890
1886
1891
QString QgsComposition::encodeStringForXML ( const QString& str )
0 commit comments