QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
209  bool prepareForFeature( const int i );
210 
214  bool prepareForFeature( const QgsFeature *feat );
215 
217  const QString& currentFilename() const;
218 
219  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
220 
227  void readXML( const QDomElement& elem, const QDomDocument& doc );
228 
236  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
237 
238  QgsComposition* composition() { return mComposition; }
239 
242  int updateFeatures();
243 
244  void nextFeature();
245  void prevFeature();
246  void lastFeature();
247  void firstFeature();
248 
250  QgsFeature* currentFeature() { return &mCurrentFeature; }
251 
253  void prepareMap( QgsComposerMap* map );
254 
255  signals:
257  void parameterChanged();
258 
260  void toggled( bool );
261 
263  void statusMsgChanged( QString message );
264 
266  void coverageLayerChanged( QgsVectorLayer* layer );
267 
269  void renderBegun();
270 
272  void renderEnded();
273 
275  void featureChanged( QgsFeature* feature );
276 
277  private:
281  bool updateFilenameExpression();
282 
286  bool evalFeatureFilename();
287 
288  QgsComposition* mComposition;
289 
290  bool mEnabled;
291  bool mHideCoverage;
292  QString mFilenamePattern;
293  QgsVectorLayer* mCoverageLayer;
294  bool mSingleFile;
295 
296  QgsCoordinateTransform mTransform;
297  QString mCurrentFilename;
298  // feature ordering
299  bool mSortFeatures;
300  // sort direction
301  bool mSortAscending;
302 
303  // current atlas feature number
304  int mCurrentFeatureNo;
305 
306  public:
307  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
308 
309  private slots:
310  void removeLayers( QStringList layers );
311 
312  private:
313  // value of field that is used for ordering of features
314  SorterKeys mFeatureKeys;
315  // key (attribute index) used for ordering
316  QString mSortKeyAttributeName;
317 
318  // feature filtering
319  bool mFilterFeatures;
320  // feature expression filter
321  QString mFeatureFilter;
322 
323  // id of each iterated feature (after filtering and sorting)
324  QVector<QgsFeatureId> mFeatureIds;
325 
326  QgsFeature mCurrentFeature;
327 
328  std::auto_ptr<QgsExpression> mFilenameExpr;
329 
330  // bounding box of the current feature transformed into map crs
331  QgsRectangle mTransformedFeatureBounds;
332 
333  QString mFilenameParserError;
334  QString mFilterParserError;
335 
336  //forces all atlas enabled maps to redraw
337  void updateAtlasMaps();
338 
339  //computes the extent of the current feature, in the crs of the specified map
340  void computeExtent( QgsComposerMap *map );
341 
342  //list of predefined scales
343  QVector<qreal> mPredefinedScales;
344 };
345 
346 #endif
347 
348 
349 
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QMap< QgsFeatureId, QVariant > SorterKeys
Definition: qgsatlascomposition.h:307
const QVector< qreal > & predefinedScales() const
Returns the current list of predefined scales for the atlas.
Definition: qgsatlascomposition.h:187
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setSortFeatures(bool doSort)
Definition: qgsatlascomposition.h:157
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
Definition: qgsatlascomposition.h:74
QgsComposition * composition()
Definition: qgsatlascomposition.h:238
bool enabled() const
Returns whether the atlas generation is enabled.
Definition: qgsatlascomposition.h:52
void setSortKeyAttributeName(QString fieldName)
Definition: qgsatlascomposition.h:176
bool sortAscending() const
Definition: qgsatlascomposition.h:159
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
bool filterFeatures() const
Definition: qgsatlascomposition.h:162
QString featureFilterErrorString() const
Returns an error string from parsing the feature filter expression.
Definition: qgsatlascomposition.h:173
QString sortKeyAttributeName() const
Definition: qgsatlascomposition.h:175
void setSortAscending(bool ascending)
Definition: qgsatlascomposition.h:160
bool singleFile() const
Returns whether the atlas will be exported to a single file.
Definition: qgsatlascomposition.h:146
QString filenamePatternErrorString() const
Returns an error string from parsing the filename expression.
Definition: qgsatlascomposition.h:126
Graphics scene for map printing.
Definition: qgscomposition.h:72
QgsFeature * currentFeature()
Returns the current atlas feature.
Definition: qgsatlascomposition.h:250
Object representing map window.
Definition: qgscomposermap.h:46
void setFilterFeatures(bool doFilter)
Definition: qgsatlascomposition.h:163
void setFeatureFilter(const QString &expression)
Definition: qgsatlascomposition.h:166
bool sortFeatures() const
Definition: qgsatlascomposition.h:156
QString filenamePattern() const
Returns the filename expression used for generating output filenames for each atlas page...
Definition: qgsatlascomposition.h:109
void setSingleFile(bool single)
Sets whether the atlas should be exported to a single file.
Definition: qgsatlascomposition.h:154
QString featureFilter() const
Definition: qgsatlascomposition.h:165
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:52
Class used to render an Atlas, iterating over geometry features.
Definition: qgsatlascomposition.h:41
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
Definition: qgsatlascomposition.h:132
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470