QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 
27 class QgsComposerMap;
28 class QgsComposition;
29 class QgsVectorLayer;
30 class QgsExpression;
31 
40 class CORE_EXPORT QgsAtlasComposition : public QObject
41 {
42  Q_OBJECT
43  public:
44  QgsAtlasComposition( QgsComposition* composition );
46 
51  bool enabled() const { return mEnabled; }
52 
57  void setEnabled( bool enabled );
58 
62  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
63 
67  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
68 
73  bool hideCoverage() const { return mHideCoverage; }
74 
79  void setHideCoverage( bool hide );
80 
84  Q_DECL_DEPRECATED bool fixedScale() const;
85 
89  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
90 
94  Q_DECL_DEPRECATED float margin() const;
95 
99  Q_DECL_DEPRECATED void setMargin( float margin );
100 
108  QString filenamePattern() const { return mFilenamePattern; }
109 
118  bool setFilenamePattern( const QString& pattern );
119 
125  QString filenamePatternErrorString() const { return mFilenameParserError; }
126 
131  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
132 
137  void setCoverageLayer( QgsVectorLayer* layer );
138 
145  bool singleFile() const { return mSingleFile; }
146 
153  void setSingleFile( bool single ) { mSingleFile = single; }
154 
155  bool sortFeatures() const { return mSortFeatures; }
156  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
157 
158  bool sortAscending() const { return mSortAscending; }
159  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
160 
161  bool filterFeatures() const { return mFilterFeatures; }
162  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
163 
164  QString featureFilter() const { return mFeatureFilter; }
165  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
166 
172  QString featureFilterErrorString() const { return mFilterParserError; }
173 
174  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
175  void setSortKeyAttributeName( QString fieldName ) { mSortKeyAttributeName = fieldName; }
176 
177  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
178  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
179 
186  const QVector<double>& predefinedScales() const { return mPredefinedScales; }
187 
194  void setPredefinedScales( const QVector<double>& scales );
195 
198  bool beginRender();
200  void endRender();
201 
203  int numFeatures() const;
204 
208  bool prepareForFeature( int i );
209 
213  bool prepareForFeature( QgsFeature * feat );
214 
216  const QString& currentFilename() const;
217 
218  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
219 
226  void readXML( const QDomElement& elem, const QDomDocument& doc );
227 
235  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
236 
237  QgsComposition* composition() { return mComposition; }
238 
241  int updateFeatures();
242 
243  void nextFeature();
244  void prevFeature();
245  void lastFeature();
246  void firstFeature();
247 
249  QgsFeature* currentFeature() { return &mCurrentFeature; }
250 
252  void prepareMap( QgsComposerMap* map );
253 
254  signals:
256  void parameterChanged();
257 
259  void toggled( bool );
260 
262  void statusMsgChanged( QString message );
263 
265  void coverageLayerChanged( QgsVectorLayer* layer );
266 
268  void renderBegun();
269 
271  void renderEnded();
272 
274  void featureChanged( QgsFeature* feature );
275 
276  private:
280  bool updateFilenameExpression();
281 
285  bool evalFeatureFilename();
286 
288 
289  bool mEnabled;
294 
297  // feature ordering
299  // sort direction
301 
302  // current atlas feature number
304 
305  public:
306  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
307 
308  private:
309  // value of field that is used for ordering of features
310  SorterKeys mFeatureKeys;
311  // key (attribute index) used for ordering
313 
314  // feature filtering
316  // feature expression filter
317  QString mFeatureFilter;
318 
319  // id of each iterated feature (after filtering and sorting)
320  QVector<QgsFeatureId> mFeatureIds;
321 
323 
324  std::auto_ptr<QgsExpression> mFilenameExpr;
325 
326  // bounding box of the current feature transformed into map crs
328 
331 
332  //forces all atlas enabled maps to redraw
333  void updateAtlasMaps();
334 
335  //computes the extent of the current feature, in the crs of the specified map
336  void computeExtent( QgsComposerMap *map );
337 
338  //list of predefined scales
339  QVector<double> mPredefinedScales;
340 };
341 
342 #endif
343 
344 
345 
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QMap< QgsFeatureId, QVariant > SorterKeys
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setSortFeatures(bool doSort)
QgsVectorLayer * mCoverageLayer
QVector< QgsFeatureId > mFeatureIds
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
QVector< double > mPredefinedScales
QgsComposition * composition()
bool enabled() const
Returns whether the atlas generation is enabled.
void setSortKeyAttributeName(QString fieldName)
QgsCoordinateTransform mTransform
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
bool filterFeatures() const
QString featureFilterErrorString() const
Returns an error string from parsing the feature filter expression.
QgsRectangle mTransformedFeatureBounds
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.
QgsComposition * mComposition
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...
const QVector< double > & 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.
QString featureFilter() const
Class for doing transforms between two map coordinate systems.
Class used to render an Atlas, iterating over geometry features.
std::auto_ptr< QgsExpression > mFilenameExpr
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
Represents a vector layer which manages a vector based data sets.