QGIS API Documentation  2.11.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 
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;
32 
41 class CORE_EXPORT QgsAtlasComposition : public QObject
42 {
43  Q_OBJECT
44  public:
45  QgsAtlasComposition( QgsComposition* composition );
47 
52  bool enabled() const { return mEnabled; }
53 
58  void setEnabled( bool enabled );
59 
63  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
64 
68  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
69 
74  bool hideCoverage() const { return mHideCoverage; }
75 
80  void setHideCoverage( bool hide );
81 
85  Q_DECL_DEPRECATED bool fixedScale() const;
86 
90  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
91 
95  Q_DECL_DEPRECATED float margin() const;
96 
100  Q_DECL_DEPRECATED void setMargin( float margin );
101 
109  QString filenamePattern() const { return mFilenamePattern; }
110 
119  bool setFilenamePattern( const QString& pattern );
120 
126  QString filenamePatternErrorString() const { return mFilenameParserError; }
127 
132  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
133 
138  void setCoverageLayer( QgsVectorLayer* layer );
139 
146  bool singleFile() const { return mSingleFile; }
147 
154  void setSingleFile( bool single ) { mSingleFile = single; }
155 
156  bool sortFeatures() const { return mSortFeatures; }
157  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
158 
159  bool sortAscending() const { return mSortAscending; }
160  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
161 
162  bool filterFeatures() const { return mFilterFeatures; }
163  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
164 
165  QString featureFilter() const { return mFeatureFilter; }
166  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
167 
173  QString featureFilterErrorString() const { return mFilterParserError; }
174 
175  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
176  void setSortKeyAttributeName( QString fieldName ) { mSortKeyAttributeName = fieldName; }
177 
178  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
179  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
180 
187  const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
188 
195  void setPredefinedScales( const QVector<qreal>& scales );
196 
199  bool beginRender();
201  void endRender();
202 
204  int numFeatures() const;
205 
211  bool prepareForFeature( const int i, const bool updateMaps = true );
212 
216  bool prepareForFeature( const QgsFeature *feat );
217 
219  const QString& currentFilename() const;
220 
221  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
222 
229  void readXML( const QDomElement& elem, const QDomDocument& doc );
230 
238  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
239 
240  QgsComposition* composition() { return mComposition; }
241 
244  int updateFeatures();
245 
247  QgsFeature* currentFeature() { return &mCurrentFeature; }
248 
252  int currentFeatureNumber() const { return mCurrentFeatureNo; }
253 
255  void prepareMap( QgsComposerMap* map );
256 
257  public slots:
258 
262  void refreshFeature();
263 
264  void nextFeature();
265  void prevFeature();
266  void lastFeature();
267  void firstFeature();
268 
269  signals:
271  void parameterChanged();
272 
274  void toggled( bool );
275 
277  void statusMsgChanged( QString message );
278 
280  void coverageLayerChanged( QgsVectorLayer* layer );
281 
283  void renderBegun();
284 
286  void renderEnded();
287 
289  void featureChanged( QgsFeature* feature );
290 
294  void numberFeaturesChanged( int numFeatures );
295 
296  private:
300  bool updateFilenameExpression();
301 
305  bool evalFeatureFilename();
306 
307  QgsComposition* mComposition;
308 
309  bool mEnabled;
310  bool mHideCoverage;
311  QString mFilenamePattern;
312  QgsVectorLayer* mCoverageLayer;
313  bool mSingleFile;
314 
315  QgsCoordinateTransform mTransform;
316  QString mCurrentFilename;
317  // feature ordering
318  bool mSortFeatures;
319  // sort direction
320  bool mSortAscending;
321 
322  // current atlas feature number
323  int mCurrentFeatureNo;
324 
325  public:
327 
328  private slots:
329  void removeLayers( QStringList layers );
330 
331  private:
332  // value of field that is used for ordering of features
333  SorterKeys mFeatureKeys;
334  // key (attribute index) used for ordering
335  QString mSortKeyAttributeName;
336 
337  // feature filtering
338  bool mFilterFeatures;
339  // feature expression filter
340  QString mFeatureFilter;
341 
342  // id of each iterated feature (after filtering and sorting)
343  QVector<QgsFeatureId> mFeatureIds;
344 
345  QgsFeature mCurrentFeature;
346 
347  QScopedPointer<QgsExpression> mFilenameExpr;
348 
349  // bounding box of the current feature transformed into map crs
350  QgsRectangle mTransformedFeatureBounds;
351 
352  QString mFilenameParserError;
353  QString mFilterParserError;
354 
355  //forces all atlas enabled maps to redraw
356  void updateAtlasMaps();
357 
358  //computes the extent of the current feature, in the crs of the specified map
359  void computeExtent( QgsComposerMap *map );
360 
361  //list of predefined scales
362  QVector<qreal> mPredefinedScales;
363 };
364 
365 #endif
366 
367 
368 
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:86
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)
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.
void setSortKeyAttributeName(QString fieldName)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
bool filterFeatures() const
QString featureFilterErrorString() const
Returns an error string from parsing the feature filter expression.
QString sortKeyAttributeName() const
void setSortAscending(bool ascending)
bool singleFile() const
Returns whether the atlas will be exported to a single file.
QString filenamePatternErrorString() const
Returns an error string from parsing the filename expression.
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
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.
Represents a vector layer which manages a vector based data sets.