QGIS API Documentation  2.12.0-Lyon
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 
22 #include <memory>
23 #include <QString>
24 #include <QDomElement>
25 #include <QDomDocument>
26 #include <QStringList>
27 
28 class QgsComposerMap;
29 class QgsComposition;
30 class QgsVectorLayer;
31 class QgsExpression;
33 
42 class CORE_EXPORT QgsAtlasComposition : public QObject
43 {
44  Q_OBJECT
45  public:
46  QgsAtlasComposition( QgsComposition* composition );
48 
53  bool enabled() const { return mEnabled; }
54 
59  void setEnabled( bool enabled );
60 
65  bool hideCoverage() const { return mHideCoverage; }
66 
71  void setHideCoverage( bool hide );
72 
80  QString filenamePattern() const { return mFilenamePattern; }
81 
90  bool setFilenamePattern( const QString& pattern );
91 
97  QString filenamePatternErrorString() const { return mFilenameParserError; }
98 
103  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
104 
109  void setCoverageLayer( QgsVectorLayer* layer );
110 
117  QString pageNameExpression() const { return mPageNameExpression; }
118 
124  void setPageNameExpression( const QString& pageNameExpression ) { mPageNameExpression = pageNameExpression; }
125 
132  QString nameForPage( int pageNumber ) const;
133 
140  bool singleFile() const { return mSingleFile; }
141 
148  void setSingleFile( bool single ) { mSingleFile = single; }
149 
150  bool sortFeatures() const { return mSortFeatures; }
151  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
152 
153  bool sortAscending() const { return mSortAscending; }
154  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
155 
156  bool filterFeatures() const { return mFilterFeatures; }
157  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
158 
159  QString featureFilter() const { return mFeatureFilter; }
160  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
161 
167  QString featureFilterErrorString() const { return mFilterParserError; }
168 
169  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
170  void setSortKeyAttributeName( const QString& fieldName ) { mSortKeyAttributeName = fieldName; }
171 
178  const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
179 
186  void setPredefinedScales( const QVector<qreal>& scales );
187 
190  bool beginRender();
192  void endRender();
193 
195  int numFeatures() const;
196 
202  bool prepareForFeature( const int i, const bool updateMaps = true );
203 
207  bool prepareForFeature( const QgsFeature *feat );
208 
210  const QString& currentFilename() const;
211 
212  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
213 
220  void readXML( const QDomElement& elem, const QDomDocument& doc );
221 
229  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
230 
231  QgsComposition* composition() { return mComposition; }
232 
235  int updateFeatures();
236 
240  QgsFeature feature() const { return mCurrentFeature; }
241 
245  QString currentPageName() const;
246 
250  int currentFeatureNumber() const { return mCurrentFeatureNo; }
251 
253  void prepareMap( QgsComposerMap* map );
254 
255 
256  //deprecated methods
257 
261  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
262 
266  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
267 
271  Q_DECL_DEPRECATED bool fixedScale() const;
272 
276  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
277 
281  Q_DECL_DEPRECATED float margin() const;
282 
286  Q_DECL_DEPRECATED void setMargin( float margin );
287 
288  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
289  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
290 
292  Q_DECL_DEPRECATED QgsFeature* currentFeature() { return &mCurrentFeature; }
293 
294  public slots:
295 
299  void refreshFeature();
300 
301  void nextFeature();
302  void prevFeature();
303  void lastFeature();
304  void firstFeature();
305 
306  signals:
308  void parameterChanged();
309 
311  void toggled( bool );
312 
314  void statusMsgChanged( QString message );
315 
317  void coverageLayerChanged( QgsVectorLayer* layer );
318 
320  void renderBegun();
321 
323  void renderEnded();
324 
326  void featureChanged( QgsFeature* feature );
327 
331  void numberFeaturesChanged( int numFeatures );
332 
333  private:
337  bool updateFilenameExpression();
338 
342  bool evalFeatureFilename( const QgsExpressionContext &context );
343 
344  QgsComposition* mComposition;
345 
346  bool mEnabled;
347  bool mHideCoverage;
348  QString mFilenamePattern;
349  QgsVectorLayer* mCoverageLayer;
350  bool mSingleFile;
351 
352  QgsCoordinateTransform mTransform;
353  QString mCurrentFilename;
354  // feature ordering
355  bool mSortFeatures;
356  // sort direction
357  bool mSortAscending;
358 
359  // current atlas feature number
360  int mCurrentFeatureNo;
361 
362  public:
364 
365  private slots:
366  void removeLayers( const QStringList& layers );
367 
368  private:
369  // value of field that is used for ordering of features
370  SorterKeys mFeatureKeys;
371  // key (attribute index) used for ordering
372  QString mSortKeyAttributeName;
373 
374  QString mPageNameExpression;
375 
376  // feature filtering
377  bool mFilterFeatures;
378  // feature expression filter
379  QString mFeatureFilter;
380 
381  // id of each iterated feature (after filtering and sorting) paired with atlas page name
383 
384  QgsFeature mCurrentFeature;
385 
386  QScopedPointer<QgsExpression> mFilenameExpr;
387 
388  // bounding box of the current feature transformed into map crs
389  QgsRectangle mTransformedFeatureBounds;
390 
391  QString mFilenameParserError;
392  QString mFilterParserError;
393 
394  //forces all atlas enabled maps to redraw
395  void updateAtlasMaps();
396 
397  //computes the extent of the current feature, in the crs of the specified map
398  void computeExtent( QgsComposerMap *map );
399 
400  QgsExpressionContext createExpressionContext();
401 
402  //list of predefined scales
403  QVector<qreal> mPredefinedScales;
404 };
405 
406 #endif
407 
408 
409 
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:92
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.
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:176
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.
QString featureFilter() const
Class for doing transforms between two map coordinate systems.
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.