QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 #include "qgsvectorlayerref.h"
23 
24 #include <memory>
25 #include <QString>
26 #include <QDomElement>
27 #include <QDomDocument>
28 #include <QStringList>
29 
30 class QgsComposerMap;
31 class QgsComposition;
32 class QgsVectorLayer;
33 class QgsExpression;
35 
44 class CORE_EXPORT QgsAtlasComposition : public QObject
45 {
46  Q_OBJECT
47  public:
48  QgsAtlasComposition( QgsComposition* composition );
50 
55  bool enabled() const { return mEnabled; }
56 
61  void setEnabled( bool enabled );
62 
67  bool hideCoverage() const { return mHideCoverage; }
68 
73  void setHideCoverage( bool hide );
74 
82  QString filenamePattern() const { return mFilenamePattern; }
83 
92  bool setFilenamePattern( const QString& pattern );
93 
99  QString filenamePatternErrorString() const { return mFilenameParserError; }
100 
105  QgsVectorLayer* coverageLayer() const { return mCoverageLayer.get(); }
106 
111  void setCoverageLayer( QgsVectorLayer* layer );
112 
119  QString pageNameExpression() const { return mPageNameExpression; }
120 
126  void setPageNameExpression( const QString& pageNameExpression ) { mPageNameExpression = pageNameExpression; }
127 
134  QString nameForPage( int pageNumber ) const;
135 
142  bool singleFile() const { return mSingleFile; }
143 
150  void setSingleFile( bool single ) { mSingleFile = single; }
151 
152  bool sortFeatures() const { return mSortFeatures; }
153  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
154 
155  bool sortAscending() const { return mSortAscending; }
156  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
157 
158  bool filterFeatures() const { return mFilterFeatures; }
159  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
160 
161  QString featureFilter() const { return mFeatureFilter; }
162  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
163 
169  QString featureFilterErrorString() const { return mFilterParserError; }
170 
171  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
172  void setSortKeyAttributeName( const QString& fieldName ) { mSortKeyAttributeName = fieldName; }
173 
180  const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
181 
188  void setPredefinedScales( const QVector<qreal>& scales );
189 
192  bool beginRender();
194  void endRender();
195 
197  int numFeatures() const;
198 
204  bool prepareForFeature( const int i, const bool updateMaps = true );
205 
209  bool prepareForFeature( const QgsFeature *feat );
210 
212  QString currentFilename() const;
213 
214  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
215 
222  void readXML( const QDomElement& elem, const QDomDocument& doc );
223 
231  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
232 
233  QgsComposition* composition() { return mComposition; }
234 
238  int updateFeatures();
239 
243  QgsFeature feature() const { return mCurrentFeature; }
244 
248  QString currentPageName() const;
249 
253  int currentFeatureNumber() const { return mCurrentFeatureNo; }
254 
256  void prepareMap( QgsComposerMap* map );
257 
258 
259  //deprecated methods
260 
264  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
265 
269  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
270 
274  Q_DECL_DEPRECATED bool fixedScale() const;
275 
279  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
280 
284  Q_DECL_DEPRECATED float margin() const;
285 
289  Q_DECL_DEPRECATED void setMargin( float margin );
290 
292  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
294  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
295 
299  Q_DECL_DEPRECATED QgsFeature* currentFeature() { return &mCurrentFeature; }
300 
302  QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem& projectedTo = QgsCoordinateReferenceSystem() ) const;
303 
304  public slots:
305 
309  void refreshFeature();
310 
311  void nextFeature();
312  void prevFeature();
313  void lastFeature();
314  void firstFeature();
315 
316  signals:
318  void parameterChanged();
319 
321  void toggled( bool );
322 
324  void statusMsgChanged( const QString& message );
325 
327  void coverageLayerChanged( QgsVectorLayer* layer );
328 
330  void renderBegun();
331 
333  void renderEnded();
334 
336  void featureChanged( QgsFeature* feature );
337 
341  void numberFeaturesChanged( int numFeatures );
342 
343  private:
347  bool updateFilenameExpression();
348 
352  bool evalFeatureFilename( const QgsExpressionContext &context );
353 
354  QgsComposition* mComposition;
355 
356  bool mEnabled;
357  bool mHideCoverage;
358  QString mFilenamePattern;
359  QgsVectorLayerRef mCoverageLayer;
360  bool mSingleFile;
361 
362  QString mCurrentFilename;
363  // feature ordering
364  bool mSortFeatures;
365  // sort direction
366  bool mSortAscending;
367 
368  // current atlas feature number
369  int mCurrentFeatureNo;
370 
371  public:
373 
374  private slots:
375  void removeLayers( const QStringList& layers );
376 
377  private:
378  // value of field that is used for ordering of features
379  SorterKeys mFeatureKeys;
380  // key (attribute index) used for ordering
381  QString mSortKeyAttributeName;
382 
383  QString mPageNameExpression;
384 
385  // feature filtering
386  bool mFilterFeatures;
387  // feature expression filter
388  QString mFeatureFilter;
389 
390  // id of each iterated feature (after filtering and sorting) paired with atlas page name
392 
393  QgsFeature mCurrentFeature;
394 
395  QScopedPointer<QgsExpression> mFilenameExpr;
396 
397  // bounding box of the current feature transformed into map crs
398  QgsRectangle mTransformedFeatureBounds;
399 
400  QString mFilenameParserError;
401  QString mFilterParserError;
402 
403  //forces all atlas enabled maps to redraw
404  void updateAtlasMaps();
405 
406  //computes the extent of the current feature, in the crs of the specified map
407  void computeExtent( QgsComposerMap *map );
408 
409  QgsExpressionContext createExpressionContext();
410 
411  //list of predefined scales
412  QVector<qreal> mPredefinedScales;
413 
414  // projected geometry cache
415  mutable QMap<long, QgsGeometry> mGeometryCache;
416 };
417 
418 #endif
419 
420 
421 
Class for parsing and evaluation of expressions (formerly called "search strings").
QString sortKeyAttributeName() const
QMap< QgsFeatureId, QVariant > SorterKeys
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setSortFeatures(bool doSort)
QString filenamePatternErrorString() const
Returns an error string from parsing the filename expression.
QgsComposition * composition()
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
QString pageNameExpression() const
Returns the expression used for calculating the page name.
void setSortKeyAttributeName(const QString &fieldName)
void setSortAscending(bool ascending)
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...
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
QString featureFilter() const
Graphics scene for map printing.
Object representing map window.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
void setFilterFeatures(bool doFilter)
void setFeatureFilter(const QString &expression)
const QVector< qreal > & predefinedScales() const
Returns the current list of predefined scales for the atlas.
void setSingleFile(bool single)
Sets whether the atlas should be exported to a single file.
Class for storing a coordinate reference system (CRS)
QString filenamePattern() const
Returns the filename expression used for generating output filenames for each atlas page...
Class used to render an Atlas, iterating over geometry features.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QgsFeature feature() const
Returns the current atlas feature.
QString featureFilterErrorString() const
Returns an error string from parsing the feature filter expression.
Q_DECL_DEPRECATED QgsFeature * currentFeature()
Returns the current atlas feature.
Represents a vector layer which manages a vector based data sets.
bool enabled() const
Returns whether the atlas generation is enabled.
bool singleFile() const
Returns whether the atlas will be exported to a single file.