QGIS API Documentation  2.99.0-Master (08ee180)
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 "qgsfeature.h"
20 #include "qgsgeometry.h"
21 #include "qgsrectangle.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 
258  QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem& projectedTo = QgsCoordinateReferenceSystem() ) const;
259 
260  public slots:
261 
265  void refreshFeature();
266 
267  void nextFeature();
268  void prevFeature();
269  void lastFeature();
270  void firstFeature();
271 
272  signals:
274  void parameterChanged();
275 
277  void toggled( bool );
278 
280  void statusMsgChanged( const QString& message );
281 
283  void coverageLayerChanged( QgsVectorLayer* layer );
284 
286  void renderBegun();
287 
289  void renderEnded();
290 
292  void featureChanged( QgsFeature* feature );
293 
297  void numberFeaturesChanged( int numFeatures );
298 
299  private:
300 
304  bool updateFilenameExpression();
305 
309  bool evalFeatureFilename( const QgsExpressionContext &context );
310 
311  QgsComposition* mComposition;
312 
313  bool mEnabled;
314  bool mHideCoverage;
315  QString mFilenamePattern;
316  QgsVectorLayer* mCoverageLayer;
317  bool mSingleFile;
318 
319  QString mCurrentFilename;
320  // feature ordering
321  bool mSortFeatures;
322  // sort direction
323  bool mSortAscending;
324 
325  // current atlas feature number
326  int mCurrentFeatureNo;
327 
328  public:
329  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
330 
331  private slots:
332  void removeLayers( const QStringList& layers );
333 
334  private:
335  // value of field that is used for ordering of features
336  SorterKeys mFeatureKeys;
337  // key (attribute index) used for ordering
338  QString mSortKeyAttributeName;
339 
340  QString mPageNameExpression;
341 
342  // feature filtering
343  bool mFilterFeatures;
344  // feature expression filter
345  QString mFeatureFilter;
346 
347  // id of each iterated feature (after filtering and sorting) paired with atlas page name
348  QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
349 
350  QgsFeature mCurrentFeature;
351 
352  QScopedPointer<QgsExpression> mFilenameExpr;
353 
354  // bounding box of the current feature transformed into map crs
355  QgsRectangle mTransformedFeatureBounds;
356 
357  QString mFilenameParserError;
358  QString mFilterParserError;
359 
360  //forces all atlas enabled maps to redraw
361  void updateAtlasMaps();
362 
363  //computes the extent of the current feature, in the crs of the specified map
364  void computeExtent( QgsComposerMap *map );
365 
366  QgsExpressionContext createExpressionContext();
367 
368  //list of predefined scales
369  QVector<qreal> mPredefinedScales;
370 
371  // projected geometry cache
372  mutable QMap<long, QgsGeometry> mGeometryCache;
373 };
374 
375 #endif
376 
377 
378 
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:78
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:135
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.
This class represents 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.
Represents a vector layer which manages a vector based data sets.