QGIS API Documentation  2.13.0-Master
qgsatlascomposition.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsatlascomposermap.h
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  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSATLASCOMPOSITION_H
17 #define QGSATLASCOMPOSITION_H
18 
19 #include "qgscoordinatetransform.h"
20 #include "qgsfeature.h"
21 #include "qgsgeometry.h"
22 
23 #include <memory>
24 #include <QString>
25 #include <QDomElement>
26 #include <QDomDocument>
27 #include <QStringList>
28 
29 class QgsComposerMap;
30 class QgsComposition;
31 class QgsVectorLayer;
32 class QgsExpression;
34 
43 class CORE_EXPORT QgsAtlasComposition : public QObject
44 {
45  Q_OBJECT
46  public:
47  QgsAtlasComposition( QgsComposition* composition );
49 
54  bool enabled() const { return mEnabled; }
55 
60  void setEnabled( bool enabled );
61 
66  bool hideCoverage() const { return mHideCoverage; }
67 
72  void setHideCoverage( bool hide );
73 
81  QString filenamePattern() const { return mFilenamePattern; }
82 
91  bool setFilenamePattern( const QString& pattern );
92 
98  QString filenamePatternErrorString() const { return mFilenameParserError; }
99 
104  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
105 
110  void setCoverageLayer( QgsVectorLayer* layer );
111 
118  QString pageNameExpression() const { return mPageNameExpression; }
119 
125  void setPageNameExpression( const QString& pageNameExpression ) { mPageNameExpression = pageNameExpression; }
126 
133  QString nameForPage( int pageNumber ) const;
134 
141  bool singleFile() const { return mSingleFile; }
142 
149  void setSingleFile( bool single ) { mSingleFile = single; }
150 
151  bool sortFeatures() const { return mSortFeatures; }
152  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
153 
154  bool sortAscending() const { return mSortAscending; }
155  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
156 
157  bool filterFeatures() const { return mFilterFeatures; }
158  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
159 
160  QString featureFilter() const { return mFeatureFilter; }
161  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
162 
168  QString featureFilterErrorString() const { return mFilterParserError; }
169 
170  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
171  void setSortKeyAttributeName( const QString& fieldName ) { mSortKeyAttributeName = fieldName; }
172 
179  const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
180 
187  void setPredefinedScales( const QVector<qreal>& scales );
188 
191  bool beginRender();
193  void endRender();
194 
196  int numFeatures() const;
197 
203  bool prepareForFeature( const int i, const bool updateMaps = true );
204 
208  bool prepareForFeature( const QgsFeature *feat );
209 
211  QString currentFilename() const;
212 
213  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
214 
221  void readXML( const QDomElement& elem, const QDomDocument& doc );
222 
230  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
231 
232  QgsComposition* composition() { return mComposition; }
233 
236  int updateFeatures();
237 
241  QgsFeature feature() const { return mCurrentFeature; }
242 
246  QString currentPageName() const;
247 
251  int currentFeatureNumber() const { return mCurrentFeatureNo; }
252 
254  void prepareMap( QgsComposerMap* map );
255 
256 
257  //deprecated methods
258 
262  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
263 
267  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
268 
272  Q_DECL_DEPRECATED bool fixedScale() const;
273 
277  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
278 
282  Q_DECL_DEPRECATED float margin() const;
283 
287  Q_DECL_DEPRECATED void setMargin( float margin );
288 
290  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
292  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
293 
297  Q_DECL_DEPRECATED QgsFeature* currentFeature() { return &mCurrentFeature; }
298 
300  QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem& projectedTo = QgsCoordinateReferenceSystem() ) const;
301 
302  public slots:
303 
307  void refreshFeature();
308 
309  void nextFeature();
310  void prevFeature();
311  void lastFeature();
312  void firstFeature();
313 
314  signals:
316  void parameterChanged();
317 
319  void toggled( bool );
320 
322  void statusMsgChanged( const QString& message );
323 
325  void coverageLayerChanged( QgsVectorLayer* layer );
326 
328  void renderBegun();
329 
331  void renderEnded();
332 
334  void featureChanged( QgsFeature* feature );
335 
339  void numberFeaturesChanged( int numFeatures );
340 
341  private:
345  bool updateFilenameExpression();
346 
350  bool evalFeatureFilename( const QgsExpressionContext &context );
351 
352  QgsComposition* mComposition;
353 
354  bool mEnabled;
355  bool mHideCoverage;
356  QString mFilenamePattern;
357  QgsVectorLayer* mCoverageLayer;
358  bool mSingleFile;
359 
360  QString mCurrentFilename;
361  // feature ordering
362  bool mSortFeatures;
363  // sort direction
364  bool mSortAscending;
365 
366  // current atlas feature number
367  int mCurrentFeatureNo;
368 
369  public:
371 
372  private slots:
373  void removeLayers( const QStringList& layers );
374 
375  private:
376  // value of field that is used for ordering of features
377  SorterKeys mFeatureKeys;
378  // key (attribute index) used for ordering
379  QString mSortKeyAttributeName;
380 
381  QString mPageNameExpression;
382 
383  // feature filtering
384  bool mFilterFeatures;
385  // feature expression filter
386  QString mFeatureFilter;
387 
388  // id of each iterated feature (after filtering and sorting) paired with atlas page name
390 
391  QgsFeature mCurrentFeature;
392 
393  QScopedPointer<QgsExpression> mFilenameExpr;
394 
395  // bounding box of the current feature transformed into map crs
396  QgsRectangle mTransformedFeatureBounds;
397 
398  QString mFilenameParserError;
399  QString mFilterParserError;
400 
401  //forces all atlas enabled maps to redraw
402  void updateAtlasMaps();
403 
404  //computes the extent of the current feature, in the crs of the specified map
405  void computeExtent( QgsComposerMap *map );
406 
407  QgsExpressionContext createExpressionContext();
408 
409  //list of predefined scales
410  QVector<qreal> mPredefinedScales;
411 
412  // projected geometry cache
413  mutable QMap<long, QgsGeometry> mGeometryCache;
414 };
415 
416 #endif
417 
418 
419 
Class for parsing and evaluation of expressions (formerly called "search strings").
QMap< QgsFeatureId, QVariant > SorterKeys
const QVector< qreal > & predefinedScales() const
Returns the current list of predefined scales for the atlas.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setSortFeatures(bool doSort)
QString pageNameExpression() const
Returns the expression used for calculating the page name.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
QgsComposition * composition()
bool enabled() const
Returns whether the atlas generation is enabled.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
QgsFeature feature() const
Returns the current atlas feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
bool filterFeatures() const
QString featureFilterErrorString() const
Returns an error string from parsing the feature filter expression.
void setSortKeyAttributeName(const QString &fieldName)
QString sortKeyAttributeName() const
void setSortAscending(bool ascending)
bool singleFile() const
Returns whether the atlas will be exported to a single file.
void setPageNameExpression(const QString &pageNameExpression)
Sets the expression used for calculating the page name.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString filenamePatternErrorString() const
Returns an error string from parsing the filename expression.
Graphics scene for map printing.
Object representing map window.
void setFilterFeatures(bool doFilter)
void setFeatureFilter(const QString &expression)
QString filenamePattern() const
Returns the filename expression used for generating output filenames for each atlas page...
void setSingleFile(bool single)
Sets whether the atlas should be exported to a single file.
Class for storing a coordinate reference system (CRS)
QString featureFilter() const
Class used to render an Atlas, iterating over geometry features.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
Q_DECL_DEPRECATED QgsFeature * currentFeature()
Returns the current atlas feature.
Represents a vector layer which manages a vector based data sets.