QGIS API Documentation  2.17.0-Master (872e6d2)
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 
237  int updateFeatures();
238 
242  QgsFeature feature() const { return mCurrentFeature; }
243 
247  QString currentPageName() const;
248 
252  int currentFeatureNumber() const { return mCurrentFeatureNo; }
253 
255  void prepareMap( QgsComposerMap* map );
256 
257 
258  //deprecated methods
259 
263  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
264 
268  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
269 
273  Q_DECL_DEPRECATED bool fixedScale() const;
274 
278  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
279 
283  Q_DECL_DEPRECATED float margin() const;
284 
288  Q_DECL_DEPRECATED void setMargin( float margin );
289 
291  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
293  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
294 
298  Q_DECL_DEPRECATED QgsFeature* currentFeature() { return &mCurrentFeature; }
299 
301  QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem& projectedTo = QgsCoordinateReferenceSystem() ) const;
302 
303  public slots:
304 
308  void refreshFeature();
309 
310  void nextFeature();
311  void prevFeature();
312  void lastFeature();
313  void firstFeature();
314 
315  signals:
317  void parameterChanged();
318 
320  void toggled( bool );
321 
323  void statusMsgChanged( const QString& message );
324 
326  void coverageLayerChanged( QgsVectorLayer* layer );
327 
329  void renderBegun();
330 
332  void renderEnded();
333 
335  void featureChanged( QgsFeature* feature );
336 
340  void numberFeaturesChanged( int numFeatures );
341 
342  private:
346  bool updateFilenameExpression();
347 
351  bool evalFeatureFilename( const QgsExpressionContext &context );
352 
353  QgsComposition* mComposition;
354 
355  bool mEnabled;
356  bool mHideCoverage;
357  QString mFilenamePattern;
358  QgsVectorLayer* mCoverageLayer;
359  bool mSingleFile;
360 
361  QString mCurrentFilename;
362  // feature ordering
363  bool mSortFeatures;
364  // sort direction
365  bool mSortAscending;
366 
367  // current atlas feature number
368  int mCurrentFeatureNo;
369 
370  public:
372 
373  private slots:
374  void removeLayers( const QStringList& layers );
375 
376  private:
377  // value of field that is used for ordering of features
378  SorterKeys mFeatureKeys;
379  // key (attribute index) used for ordering
380  QString mSortKeyAttributeName;
381 
382  QString mPageNameExpression;
383 
384  // feature filtering
385  bool mFilterFeatures;
386  // feature expression filter
387  QString mFeatureFilter;
388 
389  // id of each iterated feature (after filtering and sorting) paired with atlas page name
391 
392  QgsFeature mCurrentFeature;
393 
394  QScopedPointer<QgsExpression> mFilenameExpr;
395 
396  // bounding box of the current feature transformed into map crs
397  QgsRectangle mTransformedFeatureBounds;
398 
399  QString mFilenameParserError;
400  QString mFilterParserError;
401 
402  //forces all atlas enabled maps to redraw
403  void updateAtlasMaps();
404 
405  //computes the extent of the current feature, in the crs of the specified map
406  void computeExtent( QgsComposerMap *map );
407 
408  QgsExpressionContext createExpressionContext();
409 
410  //list of predefined scales
411  QVector<qreal> mPredefinedScales;
412 
413  // projected geometry cache
414  mutable QMap<long, QgsGeometry> mGeometryCache;
415 };
416 
417 #endif
418 
419 
420 
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.