QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  void readXML( const QDomElement& elem, const QDomDocument& doc );
220 
221  QgsComposition* composition() { return mComposition; }
222 
225  int updateFeatures();
226 
227  void nextFeature();
228  void prevFeature();
229  void lastFeature();
230  void firstFeature();
231 
233  QgsFeature* currentFeature() { return &mCurrentFeature; }
234 
236  void prepareMap( QgsComposerMap* map );
237 
238  signals:
240  void parameterChanged();
241 
243  void toggled( bool );
244 
246  void statusMsgChanged( QString message );
247 
249  void coverageLayerChanged( QgsVectorLayer* layer );
250 
252  void renderBegun();
253 
255  void renderEnded();
256 
258  void featureChanged( QgsFeature* feature );
259 
260  private:
264  bool updateFilenameExpression();
265 
269  bool evalFeatureFilename();
270 
272 
273  bool mEnabled;
278 
281  // feature ordering
283  // sort direction
285 
286  // current atlas feature number
288 
289  public:
290  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
291 
292  private:
293  // value of field that is used for ordering of features
295  // key (attribute index) used for ordering
297 
298  // feature filtering
300  // feature expression filter
301  QString mFeatureFilter;
302 
303  // id of each iterated feature (after filtering and sorting)
304  QVector<QgsFeatureId> mFeatureIds;
305 
307 
308  std::auto_ptr<QgsExpression> mFilenameExpr;
309 
310  // bounding box of the current feature transformed into map crs
312 
315 
316  //forces all atlas enabled maps to redraw
317  void updateAtlasMaps();
318 
319  //computes the extent of the current feature, in the crs of the specified map
320  void computeExtent( QgsComposerMap *map );
321 
322  //list of predefined scales
323  QVector<double> mPredefinedScales;
324 };
325 
326 #endif
327 
328 
329 
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.