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 
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 
250  void prepareMap( QgsComposerMap* map );
251 
252  public slots:
253 
257  void refreshFeature();
258 
259  void nextFeature();
260  void prevFeature();
261  void lastFeature();
262  void firstFeature();
263 
264  signals:
266  void parameterChanged();
267 
269  void toggled( bool );
270 
272  void statusMsgChanged( QString message );
273 
275  void coverageLayerChanged( QgsVectorLayer* layer );
276 
278  void renderBegun();
279 
281  void renderEnded();
282 
284  void featureChanged( QgsFeature* feature );
285 
286  private:
290  bool updateFilenameExpression();
291 
295  bool evalFeatureFilename();
296 
297  QgsComposition* mComposition;
298 
299  bool mEnabled;
300  bool mHideCoverage;
301  QString mFilenamePattern;
302  QgsVectorLayer* mCoverageLayer;
303  bool mSingleFile;
304 
305  QgsCoordinateTransform mTransform;
306  QString mCurrentFilename;
307  // feature ordering
308  bool mSortFeatures;
309  // sort direction
310  bool mSortAscending;
311 
312  // current atlas feature number
313  int mCurrentFeatureNo;
314 
315  public:
316  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
317 
318  private slots:
319  void removeLayers( QStringList layers );
320 
321  private:
322  // value of field that is used for ordering of features
323  SorterKeys mFeatureKeys;
324  // key (attribute index) used for ordering
325  QString mSortKeyAttributeName;
326 
327  // feature filtering
328  bool mFilterFeatures;
329  // feature expression filter
330  QString mFeatureFilter;
331 
332  // id of each iterated feature (after filtering and sorting)
333  QVector<QgsFeatureId> mFeatureIds;
334 
335  QgsFeature mCurrentFeature;
336 
337  std::auto_ptr<QgsExpression> mFilenameExpr;
338 
339  // bounding box of the current feature transformed into map crs
340  QgsRectangle mTransformedFeatureBounds;
341 
342  QString mFilenameParserError;
343  QString mFilterParserError;
344 
345  //forces all atlas enabled maps to redraw
346  void updateAtlasMaps();
347 
348  //computes the extent of the current feature, in the crs of the specified map
349  void computeExtent( QgsComposerMap *map );
350 
351  //list of predefined scales
352  QVector<qreal> mPredefinedScales;
353 };
354 
355 #endif
356 
357 
358 
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QMap< QgsFeatureId, QVariant > SorterKeys
Definition: qgsatlascomposition.h:316
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:240
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:247
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