QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsatlascomposition.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsatlascomposition.cpp
3  -----------------------
4  begin : October 2012
5  copyright : (C) 2005 by Hugo Mercier
6  email : hugo dot mercier at oslandia dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <stdexcept>
18 
19 #include "qgsatlascomposition.h"
20 #include "qgsvectorlayer.h"
21 #include "qgscomposermap.h"
22 #include "qgscomposition.h"
23 #include "qgsvectordataprovider.h"
24 #include "qgsexpression.h"
25 #include "qgsgeometry.h"
26 #include "qgscomposerlabel.h"
27 #include "qgscomposershape.h"
28 #include "qgspaperitem.h"
29 #include "qgsmaplayerregistry.h"
30 
32  mComposition( composition ),
33  mEnabled( false ),
34  mHideCoverage( false ), mFilenamePattern( "'output_'||$feature" ),
35  mCoverageLayer( 0 ), mSingleFile( false ),
36  mSortFeatures( false ), mSortAscending( true ), mCurrentFeatureNo( 0 ),
37  mFilterFeatures( false ), mFeatureFilter( "" )
38 {
39 
40  // declare special columns with a default value
41  QgsExpression::setSpecialColumn( "$page", QVariant(( int )1 ) );
42  QgsExpression::setSpecialColumn( "$feature", QVariant(( int )0 ) );
43  QgsExpression::setSpecialColumn( "$numpages", QVariant(( int )1 ) );
44  QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )0 ) );
45  QgsExpression::setSpecialColumn( "$atlasfeatureid", QVariant(( int )0 ) );
46  QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( QgsGeometry() ) );
47 }
48 
50 {
51 }
52 
54 {
55  mEnabled = e;
57  emit toggled( e );
58 }
59 
61 {
62  mCoverageLayer = layer;
63 
64  // update the number of features
65  QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
66 
67  // Grab the first feature so that user can use it to test the style in rules.
68  if ( layer )
69  {
70  QgsFeature fet;
71  layer->getFeatures().nextFeature( fet );
72  QgsExpression::setSpecialColumn( "$atlasfeatureid", fet.id() );
73  QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( *fet.geometry() ) );
74  }
75 
76  emit coverageLayerChanged( layer );
77 }
78 
80 {
81  //deprecated method. Until removed just return the first atlas-enabled composer map
82 
83  //build a list of composer maps
84  QList<QgsComposerMap*> maps;
85  mComposition->composerItems( maps );
86  for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
87  {
88  QgsComposerMap* currentMap = ( *mit );
89  if ( currentMap->atlasDriven() )
90  {
91  return currentMap;
92  }
93  }
94 
95  return 0;
96 }
97 
99 {
100  //deprecated
101 
102  if ( !map )
103  {
104  return;
105  }
106 
107  map->setAtlasDriven( true );
108 }
109 
111 {
112  //deprecated method. Until removed just return the property for the first atlas-enabled composer map
113  QgsComposerMap * map = composerMap();
114  if ( !map )
115  {
116  return false;
117  }
118 
119  return map->atlasFixedScale();
120 }
121 
123 {
124  //deprecated method. Until removed just set the property for the first atlas-enabled composer map
125  QgsComposerMap * map = composerMap();
126  if ( !map )
127  {
128  return;
129  }
130 
131  map->setAtlasFixedScale( fixed );
132 }
133 
135 {
136  //deprecated method. Until removed just return the property for the first atlas-enabled composer map
137  QgsComposerMap * map = composerMap();
138  if ( !map )
139  {
140  return 0;
141  }
142 
143  return map->atlasMargin();
144 }
145 
146 void QgsAtlasComposition::setMargin( float margin )
147 {
148  //deprecated method. Until removed just set the property for the first atlas-enabled composer map
149  QgsComposerMap * map = composerMap();
150  if ( !map )
151  {
152  return;
153  }
154 
155  map->setAtlasMargin(( double ) margin );
156 }
157 
159 {
160  if ( !mCoverageLayer )
161  {
162  return -1;
163  }
165 }
166 
168 {
169  if ( mCoverageLayer )
170  {
171  const QgsFields fields = mCoverageLayer->pendingFields();
172  if ( idx >= 0 && idx < fields.count() )
173  {
174  mSortKeyAttributeName = fields[idx].name();
175  return;
176  }
177  }
179 }
180 
181 //
182 // Private class only used for the sorting of features
184 {
185  public:
186  FieldSorter( QgsAtlasComposition::SorterKeys& keys, bool ascending = true ) : mKeys( keys ), mAscending( ascending ) {}
187 
188  bool operator()( const QgsFeatureId& id1, const QgsFeatureId& id2 )
189  {
190  bool result = true;
191 
192  if ( mKeys[ id1 ].type() == QVariant::Int )
193  {
194  result = mKeys[ id1 ].toInt() < mKeys[ id2 ].toInt();
195  }
196  else if ( mKeys[ id1 ].type() == QVariant::Double )
197  {
198  result = mKeys[ id1 ].toDouble() < mKeys[ id2 ].toDouble();
199  }
200  else if ( mKeys[ id1 ].type() == QVariant::String )
201  {
202  result = ( QString::localeAwareCompare( mKeys[ id1 ].toString(), mKeys[ id2 ].toString() ) < 0 );
203  }
204 
205  return mAscending ? result : !result;
206  }
207  private:
210 };
211 
213 {
214  //needs to be called when layer, filter, sort changes
215 
216  if ( !mCoverageLayer )
217  {
218  return 0;
219  }
220 
222 
223  // select all features with all attributes
225 
226  std::auto_ptr<QgsExpression> filterExpression;
227  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
228  {
229  filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
230  if ( filterExpression->hasParserError() )
231  {
232  throw std::runtime_error( tr( "Feature filter parser error: %1" ).arg( filterExpression->parserErrorString() ).toLocal8Bit().data() );
233  }
234  }
235 
236  // We cannot use nextFeature() directly since the feature pointer is rewinded by the rendering process
237  // We thus store the feature ids for future extraction
238  QgsFeature feat;
239  mFeatureIds.clear();
240  mFeatureKeys.clear();
242  while ( fit.nextFeature( feat ) )
243  {
244  if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
245  {
246  QVariant result = filterExpression->evaluate( &feat, mCoverageLayer->pendingFields() );
247  if ( filterExpression->hasEvalError() )
248  {
249  throw std::runtime_error( tr( "Feature filter eval error: %1" ).arg( filterExpression->evalErrorString() ).toLocal8Bit().data() );
250  }
251 
252  // skip this feature if the filter evaluation if false
253  if ( !result.toBool() )
254  {
255  continue;
256  }
257  }
258  mFeatureIds.push_back( feat.id() );
259 
260  if ( mSortFeatures && sortIdx != -1 )
261  {
262  mFeatureKeys.insert( feat.id(), feat.attributes()[ sortIdx ] );
263  }
264  }
265 
266  // sort features, if asked for
267  if ( mFeatureKeys.count() )
268  {
270  qSort( mFeatureIds.begin(), mFeatureIds.end(), sorter );
271  }
272 
273  QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
274 
275  //jump to first feature if currently using an atlas preview
276  //need to do this in case filtering/layer change has altered matching features
278  {
279  firstFeature();
280  }
281 
282  return mFeatureIds.size();
283 }
284 
285 
287 {
288  if ( !mCoverageLayer )
289  {
290  return false;
291  }
292 
293  emit renderBegun();
294 
295  bool featuresUpdated = updateFeatures();
296  if ( !featuresUpdated )
297  {
298  //no matching features found
299  return false;
300  }
301 
302  // special columns for expressions
303  QgsExpression::setSpecialColumn( "$numpages", QVariant( mComposition->numPages() ) );
304  QgsExpression::setSpecialColumn( "$numfeatures", QVariant(( int )mFeatureIds.size() ) );
305 
306  return true;
307 }
308 
310 {
311  if ( !mCoverageLayer )
312  {
313  return;
314  }
315 
316  // reset label expression contexts
317  QList<QgsComposerLabel*> labels;
318  mComposition->composerItems( labels );
319  for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
320  {
321  ( *lit )->setExpressionContext( 0, 0 );
322  }
323 
324  updateAtlasMaps();
325 
326  emit renderEnded();
327 }
328 
330 {
331  //update atlas-enabled composer maps
332  QList<QgsComposerMap*> maps;
333  mComposition->composerItems( maps );
334  for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
335  {
336  QgsComposerMap* currentMap = ( *mit );
337  if ( !currentMap->atlasDriven() )
338  {
339  continue;
340  }
341 
342  currentMap->cache();
343  }
344 }
345 
347 {
348  return mFeatureIds.size();
349 }
350 
352 {
353  int newFeatureNo = mCurrentFeatureNo + 1;
354  if ( newFeatureNo >= mFeatureIds.size() )
355  {
356  newFeatureNo = mFeatureIds.size() - 1;
357  }
358 
359  prepareForFeature( newFeatureNo );
360 }
361 
363 {
364  int newFeatureNo = mCurrentFeatureNo - 1;
365  if ( newFeatureNo < 0 )
366  {
367  newFeatureNo = 0;
368  }
369 
370  prepareForFeature( newFeatureNo );
371 }
372 
374 {
375  prepareForFeature( 0 );
376 }
377 
379 {
380  prepareForFeature( mFeatureIds.size() - 1 );
381 }
382 
384 {
385  int featureI = mFeatureIds.indexOf( feat->id() );
386  prepareForFeature( featureI );
387 }
388 
390 {
391  if ( !mCoverageLayer )
392  {
393  return;
394  }
395 
396  if ( mFeatureIds.size() == 0 )
397  {
398  emit statusMsgChanged( tr( "No matching atlas features" ) );
399  return;
400  }
401 
402  mCurrentFeatureNo = featureI;
403 
404  // retrieve the next feature, based on its id
406 
407  QgsExpression::setSpecialColumn( "$atlasfeatureid", mCurrentFeature.id() );
408  QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( *mCurrentFeature.geometry() ) );
409  QgsExpression::setSpecialColumn( "$feature", QVariant(( int )featureI + 1 ) );
410 
411  // generate filename for current feature
413 
414  // evaluate label expressions
415  QList<QgsComposerLabel*> labels;
416  mComposition->composerItems( labels );
417  for ( QList<QgsComposerLabel*>::iterator lit = labels.begin(); lit != labels.end(); ++lit )
418  {
419  ( *lit )->setExpressionContext( &mCurrentFeature, mCoverageLayer );
420  }
421 
422  // update shapes (in case they use data defined symbology with atlas properties)
423  QList<QgsComposerShape*> shapes;
424  mComposition->composerItems( shapes );
425  for ( QList<QgsComposerShape*>::iterator lit = shapes.begin(); lit != shapes.end(); ++lit )
426  {
427  ( *lit )->update();
428  }
429 
430  // update page background (in case it uses data defined symbology with atlas properties)
431  QList<QgsPaperItem*> pages;
432  mComposition->composerItems( pages );
433  for ( QList<QgsPaperItem*>::iterator pageIt = pages.begin(); pageIt != pages.end(); ++pageIt )
434  {
435  ( *pageIt )->update();
436  }
437 
438  emit statusMsgChanged( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );
439 
440  //update composer maps
441 
442  //build a list of atlas-enabled composer maps
443  QList<QgsComposerMap*> maps;
444  QList<QgsComposerMap*> atlasMaps;
445  mComposition->composerItems( maps );
446  for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
447  {
448  QgsComposerMap* currentMap = ( *mit );
449  if ( !currentMap->atlasDriven() )
450  {
451  continue;
452  }
453  atlasMaps << currentMap;
454  }
455 
456  //clear the transformed bounds of the previous feature
458 
459  if ( atlasMaps.isEmpty() )
460  {
461  //no atlas enabled maps
462  return;
463  }
464 
465  // compute extent of current feature in the map CRS. This should be set on a per-atlas map basis,
466  // but given that it's not currently possible to have maps with different CRSes we can just
467  // calculate it once based on the first atlas maps' CRS.
468  computeExtent( atlasMaps[0] );
469 
470  //update atlas bounds of every atlas enabled composer map
471  for ( QList<QgsComposerMap*>::iterator mit = atlasMaps.begin(); mit != atlasMaps.end(); ++mit )
472  {
473  prepareMap( *mit );
474  }
475 }
476 
478 {
479  // compute the extent of the current feature, in the crs of the specified map
480 
481  const QgsCoordinateReferenceSystem& coverage_crs = mCoverageLayer->crs();
482  // transformation needed for feature geometries
483  const QgsCoordinateReferenceSystem& destination_crs = map->composition()->mapSettings().destinationCrs();
484  mTransform.setSourceCrs( coverage_crs );
485  mTransform.setDestCRS( destination_crs );
486 
487  // QgsGeometry::boundingBox is expressed in the geometry"s native CRS
488  // We have to transform the grometry to the destination CRS and ask for the bounding box
489  // Note: we cannot directly take the transformation of the bounding box, since transformations are not linear
491  tgeom.transform( mTransform );
492  mTransformedFeatureBounds = tgeom.boundingBox();
493 }
494 
496 {
497  if ( !map->atlasDriven() )
498  {
499  return;
500  }
501 
503  {
504  //transformed extent of current feature hasn't been calculated yet. This can happen if
505  //a map has been set to be atlas controlled after prepare feature was called
506  computeExtent( map );
507  }
508 
509  double xa1 = mTransformedFeatureBounds.xMinimum();
510  double xa2 = mTransformedFeatureBounds.xMaximum();
511  double ya1 = mTransformedFeatureBounds.yMinimum();
512  double ya2 = mTransformedFeatureBounds.yMaximum();
514  QgsRectangle mOrigExtent = map->extent();
515 
516  if ( map->atlasFixedScale() )
517  {
518  // only translate, keep the original scale (i.e. width x height)
519 
520  double geom_center_x = ( xa1 + xa2 ) / 2.0;
521  double geom_center_y = ( ya1 + ya2 ) / 2.0;
522  double xx = geom_center_x - mOrigExtent.width() / 2.0;
523  double yy = geom_center_y - mOrigExtent.height() / 2.0;
524  new_extent = QgsRectangle( xx,
525  yy,
526  xx + mOrigExtent.width(),
527  yy + mOrigExtent.height() );
528  }
529  else
530  {
531  // auto scale
532 
534  double map_ratio = mOrigExtent.width() / mOrigExtent.height();
535 
536  // geometry height is too big
537  if ( geom_ratio < map_ratio )
538  {
539  // extent the bbox's width
540  double adj_width = ( map_ratio * mTransformedFeatureBounds.height() - mTransformedFeatureBounds.width() ) / 2.0;
541  xa1 -= adj_width;
542  xa2 += adj_width;
543  }
544  // geometry width is too big
545  else if ( geom_ratio > map_ratio )
546  {
547  // extent the bbox's height
548  double adj_height = ( mTransformedFeatureBounds.width() / map_ratio - mTransformedFeatureBounds.height() ) / 2.0;
549  ya1 -= adj_height;
550  ya2 += adj_height;
551  }
552  new_extent = QgsRectangle( xa1, ya1, xa2, ya2 );
553 
554  if ( map->atlasMargin() > 0.0 )
555  {
556  new_extent.scale( 1 + map->atlasMargin() );
557  }
558  }
559 
560  // set the new extent (and render)
561  map->setNewAtlasFeatureExtent( new_extent );
562 }
563 
565 {
566  return mCurrentFilename;
567 }
568 
569 void QgsAtlasComposition::writeXML( QDomElement& elem, QDomDocument& doc ) const
570 {
571  QDomElement atlasElem = doc.createElement( "Atlas" );
572  atlasElem.setAttribute( "enabled", mEnabled ? "true" : "false" );
573  if ( !mEnabled )
574  {
575  return;
576  }
577 
578  if ( mCoverageLayer )
579  {
580  atlasElem.setAttribute( "coverageLayer", mCoverageLayer->id() );
581  }
582  else
583  {
584  atlasElem.setAttribute( "coverageLayer", "" );
585  }
586 
587  atlasElem.setAttribute( "hideCoverage", mHideCoverage ? "true" : "false" );
588  atlasElem.setAttribute( "singleFile", mSingleFile ? "true" : "false" );
589  atlasElem.setAttribute( "filenamePattern", mFilenamePattern );
590 
591  atlasElem.setAttribute( "sortFeatures", mSortFeatures ? "true" : "false" );
592  if ( mSortFeatures )
593  {
594  atlasElem.setAttribute( "sortKey", mSortKeyAttributeName );
595  atlasElem.setAttribute( "sortAscending", mSortAscending ? "true" : "false" );
596  }
597  atlasElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
598  if ( mFilterFeatures )
599  {
600  atlasElem.setAttribute( "featureFilter", mFeatureFilter );
601  }
602 
603  elem.appendChild( atlasElem );
604 }
605 
606 void QgsAtlasComposition::readXML( const QDomElement& atlasElem, const QDomDocument& )
607 {
608  mEnabled = atlasElem.attribute( "enabled", "false" ) == "true" ? true : false;
609  emit toggled( mEnabled );
610  if ( !mEnabled )
611  {
612  emit parameterChanged();
613  return;
614  }
615 
616  // look for stored layer name
617  mCoverageLayer = 0;
618  QMap<QString, QgsMapLayer*> layers = QgsMapLayerRegistry::instance()->mapLayers();
619  for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it )
620  {
621  if ( it.key() == atlasElem.attribute( "coverageLayer" ) )
622  {
623  mCoverageLayer = dynamic_cast<QgsVectorLayer*>( it.value() );
624  break;
625  }
626  }
627  //look for stored composer map, to upgrade pre 2.1 projects
628  int composerMapNo = atlasElem.attribute( "composerMap", "-1" ).toInt();
630  if ( composerMapNo != -1 )
631  {
632  QList<QgsComposerMap*> maps;
633  mComposition->composerItems( maps );
634  for ( QList<QgsComposerMap*>::iterator it = maps.begin(); it != maps.end(); ++it )
635  {
636  if (( *it )->id() == composerMapNo )
637  {
638  composerMap = ( *it );
639  composerMap->setAtlasDriven( true );
640  break;
641  }
642  }
643  }
644  mHideCoverage = atlasElem.attribute( "hideCoverage", "false" ) == "true" ? true : false;
645 
646  //upgrade pre 2.1 projects
647  double margin = atlasElem.attribute( "margin", "0.0" ).toDouble();
648  if ( composerMap && margin != 0 )
649  {
650  composerMap->setAtlasMargin( margin );
651  }
652  bool fixedScale = atlasElem.attribute( "fixedScale", "false" ) == "true" ? true : false;
653  if ( composerMap && fixedScale )
654  {
655  composerMap->setAtlasFixedScale( true );
656  }
657 
658  mSingleFile = atlasElem.attribute( "singleFile", "false" ) == "true" ? true : false;
659  mFilenamePattern = atlasElem.attribute( "filenamePattern", "" );
660 
661  mSortFeatures = atlasElem.attribute( "sortFeatures", "false" ) == "true" ? true : false;
662  if ( mSortFeatures )
663  {
664  mSortKeyAttributeName = atlasElem.attribute( "sortKey", "" );
665  // since 2.3, the field name is saved instead of the field index
666  // following code keeps compatibility with version 2.2 projects
667  // to be removed in QGIS 3.0
668  bool isIndex;
669  int idx = mSortKeyAttributeName.toInt( &isIndex );
670  if ( isIndex && mCoverageLayer )
671  {
672  const QgsFields fields = mCoverageLayer->pendingFields();
673  if ( idx >= 0 && idx < fields.count() )
674  {
675  mSortKeyAttributeName = fields[idx].name();
676  }
677  }
678  mSortAscending = atlasElem.attribute( "sortAscending", "true" ) == "true" ? true : false;
679  }
680  mFilterFeatures = atlasElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
681  if ( mFilterFeatures )
682  {
683  mFeatureFilter = atlasElem.attribute( "featureFilter", "" );
684  }
685 
686  emit parameterChanged();
687 }
688 
690 {
691  mHideCoverage = hide;
692 
694  {
695  //an atlas preview is enabled, so reflect changes in coverage layer visibility immediately
696  updateAtlasMaps();
697  mComposition->update();
698  }
699 
700 }
701 
702 void QgsAtlasComposition::setFilenamePattern( const QString& pattern )
703 {
704  mFilenamePattern = pattern;
706 }
707 
709 {
710  if ( !mCoverageLayer )
711  return;
712 
713  const QgsFields& fields = mCoverageLayer->pendingFields();
714 
715  if ( !mSingleFile && mFilenamePattern.size() > 0 )
716  {
717  mFilenameExpr = std::auto_ptr<QgsExpression>( new QgsExpression( mFilenamePattern ) );
718  // expression used to evaluate each filename
719  // test for evaluation errors
720  if ( mFilenameExpr->hasParserError() )
721  {
722  throw std::runtime_error( tr( "Filename parsing error: %1" ).arg( mFilenameExpr->parserErrorString() ).toLocal8Bit().data() );
723  }
724 
725  // prepare the filename expression
726  mFilenameExpr->prepare( fields );
727  }
728 
729  //if atlas preview is currently enabled, regenerate filename for current feature
731  {
733  }
734 
735 }
736 
738 {
739  //generate filename for current atlas feature
740  if ( !mSingleFile && mFilenamePattern.size() > 0 )
741  {
742  QVariant filenameRes = mFilenameExpr->evaluate( &mCurrentFeature, mCoverageLayer->pendingFields() );
743  if ( mFilenameExpr->hasEvalError() )
744  {
745  throw std::runtime_error( tr( "Filename eval error: %1" ).arg( mFilenameExpr->evalErrorString() ).toLocal8Bit().data() );
746  }
747 
748  mCurrentFilename = filenameRes.toString();
749  }
750 }
751 
752 
QgsFeatureId id() const
Get the feature id for this feature.
Definition: qgsfeature.cpp:100
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QMap< QgsFeatureId, QVariant > SorterKeys
Wrapper for iterator of features from vector data provider or vector layer.
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool isEmpty() const
test if rectangle is empty
void renderEnded()
Is emitted when atlas rendering has ended.
QgsVectorLayer * mCoverageLayer
QVector< QgsFeatureId > mFeatureIds
Q_DECL_DEPRECATED int sortKeyAttributeIndex() const
void setNewAtlasFeatureExtent(const QgsRectangle &extent)
Sets new Extent for the current atlas preview and changes width, height (and implicitely also scale)...
QgsAtlasComposition(QgsComposition *composition)
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:189
double atlasMargin() const
Returns the margin size (percentage) used when the map is in atlas mode.
void setSourceCrs(const QgsCoordinateReferenceSystem &theCRS)
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void computeExtent(QgsComposerMap *map)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
Definition: qgsfeature.cpp:112
void cache()
Create cache image.
bool fixedScale() const
Returns whether the atlas map uses a fixed scale.
Container of fields for a vector layer.
Definition: qgsfield.h:164
QgsCoordinateTransform mTransform
void toggled(bool)
emitted when atlas is enabled or disabled
void setHideCoverage(bool hide)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
void evalFeatureFilename()
Evaluates filename for current feature.
int numPages() const
Note: added in version 1.9.
void endRender()
Ends the rendering.
void readXML(const QDomElement &elem, const QDomDocument &doc)
void setFixedScale(bool fixed)
Sets whether the atlas map should use a fixed scale.
float margin() const
Returns the margin for the atlas map.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
Q_DECL_DEPRECATED void setSortKeyAttributeIndex(int idx)
QgsRectangle mTransformedFeatureBounds
bool beginRender()
Begins the rendering.
void setComposerMap(QgsComposerMap *map)
Sets the map used by the atlas.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:194
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:179
void prepareMap(QgsComposerMap *map)
Recalculates the bounds of an atlas driven map.
void statusMsgChanged(QString message)
Is emitted when the atlas has an updated status bar message for the composer window.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
bool setAtlasMode(QgsComposition::AtlasMode mode)
Sets the current atlas mode of the composition.
void prepareForFeature(int i)
Prepare the atlas map for the given feature.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
int numFeatures() const
Returns the number of features in the coverage layer.
const QgsAttributes & attributes() const
Definition: qgsfeature.h:143
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:92
int count() const
Return number of items.
Definition: qgsfield.h:198
void updateFilenameExpression()
Updates the filename expression.
bool atlasFixedScale() const
Returns true if the map uses a fixed scale when in atlas mode.
void setCoverageLayer(QgsVectorLayer *lmap)
int updateFeatures()
Requeries the current atlas coverage layer and applies filtering and sorting.
void writeXML(QDomElement &elem, QDomDocument &doc) const
Graphics scene for map printing.
Object representing map window.
QgsComposition * mComposition
void coverageLayerChanged(QgsVectorLayer *layer)
Is emitted when the coverage layer for an atlas changes.
bool operator()(const QgsFeatureId &id1, const QgsFeatureId &id2)
void setDestCRS(const QgsCoordinateReferenceSystem &theCRS)
void renderBegun()
Is emitted when atlas rendering has begun.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsRectangle extent() const
FieldSorter(QgsAtlasComposition::SorterKeys &keys, bool ascending=true)
QgsComposerMap * composerMap() const
Returns the map used by the atlas.
void setMargin(float margin)
Sets the margin for the atlas map.
Class for storing a coordinate reference system (CRS)
const QgsComposition * composition() const
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
void parameterChanged()
emitted when one of the parameters changes
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTranasform ct.
void setFilenamePattern(const QString &pattern)
void setAtlasFixedScale(bool fixed)
Set to true if the map should use a fixed scale when in atlas mode.
qint64 QgsFeatureId
Definition: qgsfeature.h:30
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
const QString & currentFilename() const
Returns the current filename.
std::auto_ptr< QgsExpression > mFilenameExpr
bool atlasDriven() const
Returns true if the map extent is set to follow the current atlas feature.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
void setAtlasDriven(bool enabled)
Set to true if the map extents should be set by the current atlas feature.
bool nextFeature(QgsFeature &f)
void composerItems(QList< T * > &itemList)
Return composer items of a specific type.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:199
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:184
QgsAtlasComposition::SorterKeys & mKeys
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:204
#define tr(sourceText)
void scale(double scaleFactor, const QgsPoint *c=0)
Scale the rectangle around its center point.