QGIS API Documentation  2.11.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 #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 
64  bool hideCoverage() const { return mHideCoverage; }
65 
70  void setHideCoverage( bool hide );
71 
79  QString filenamePattern() const { return mFilenamePattern; }
80 
89  bool setFilenamePattern( const QString& pattern );
90 
96  QString filenamePatternErrorString() const { return mFilenameParserError; }
97 
102  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
103 
108  void setCoverageLayer( QgsVectorLayer* layer );
109 
116  QString pageNameExpression() const { return mPageNameExpression; }
117 
123  void setPageNameExpression( const QString& pageNameExpression ) { mPageNameExpression = pageNameExpression; }
124 
131  QString nameForPage( int pageNumber ) const;
132 
139  bool singleFile() const { return mSingleFile; }
140 
147  void setSingleFile( bool single ) { mSingleFile = single; }
148 
149  bool sortFeatures() const { return mSortFeatures; }
150  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
151 
152  bool sortAscending() const { return mSortAscending; }
153  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
154 
155  bool filterFeatures() const { return mFilterFeatures; }
156  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
157 
158  QString featureFilter() const { return mFeatureFilter; }
159  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
160 
166  QString featureFilterErrorString() const { return mFilterParserError; }
167 
168  QString sortKeyAttributeName() const { return mSortKeyAttributeName; }
169  void setSortKeyAttributeName( QString fieldName ) { mSortKeyAttributeName = fieldName; }
170 
177  const QVector<qreal>& predefinedScales() const { return mPredefinedScales; }
178 
185  void setPredefinedScales( const QVector<qreal>& scales );
186 
189  bool beginRender();
191  void endRender();
192 
194  int numFeatures() const;
195 
201  bool prepareForFeature( const int i, const bool updateMaps = true );
202 
206  bool prepareForFeature( const QgsFeature *feat );
207 
209  const QString& currentFilename() const;
210 
211  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
212 
219  void readXML( const QDomElement& elem, const QDomDocument& doc );
220 
228  void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
229 
230  QgsComposition* composition() { return mComposition; }
231 
234  int updateFeatures();
235 
237  QgsFeature* currentFeature() { return &mCurrentFeature; }
238 
242  int currentFeatureNumber() const { return mCurrentFeatureNo; }
243 
245  void prepareMap( QgsComposerMap* map );
246 
247 
248  //deprecated methods
249 
253  Q_DECL_DEPRECATED QgsComposerMap* composerMap() const;
254 
258  Q_DECL_DEPRECATED void setComposerMap( QgsComposerMap* map );
259 
263  Q_DECL_DEPRECATED bool fixedScale() const;
264 
268  Q_DECL_DEPRECATED void setFixedScale( bool fixed );
269 
273  Q_DECL_DEPRECATED float margin() const;
274 
278  Q_DECL_DEPRECATED void setMargin( float margin );
279 
280  Q_DECL_DEPRECATED int sortKeyAttributeIndex() const;
281  Q_DECL_DEPRECATED void setSortKeyAttributeIndex( int idx );
282 
283  public slots:
284 
288  void refreshFeature();
289 
290  void nextFeature();
291  void prevFeature();
292  void lastFeature();
293  void firstFeature();
294 
295  signals:
297  void parameterChanged();
298 
300  void toggled( bool );
301 
303  void statusMsgChanged( QString message );
304 
306  void coverageLayerChanged( QgsVectorLayer* layer );
307 
309  void renderBegun();
310 
312  void renderEnded();
313 
315  void featureChanged( QgsFeature* feature );
316 
320  void numberFeaturesChanged( int numFeatures );
321 
322  private:
326  bool updateFilenameExpression();
327 
331  bool evalFeatureFilename();
332 
333  QgsComposition* mComposition;
334 
335  bool mEnabled;
336  bool mHideCoverage;
337  QString mFilenamePattern;
338  QgsVectorLayer* mCoverageLayer;
339  bool mSingleFile;
340 
341  QgsCoordinateTransform mTransform;
342  QString mCurrentFilename;
343  // feature ordering
344  bool mSortFeatures;
345  // sort direction
346  bool mSortAscending;
347 
348  // current atlas feature number
349  int mCurrentFeatureNo;
350 
351  public:
353 
354  private slots:
355  void removeLayers( QStringList layers );
356 
357  private:
358  // value of field that is used for ordering of features
359  SorterKeys mFeatureKeys;
360  // key (attribute index) used for ordering
361  QString mSortKeyAttributeName;
362 
363  QString mPageNameExpression;
364 
365  // feature filtering
366  bool mFilterFeatures;
367  // feature expression filter
368  QString mFeatureFilter;
369 
370  // id of each iterated feature (after filtering and sorting) paired with atlas page name
372 
373  QgsFeature mCurrentFeature;
374 
375  QScopedPointer<QgsExpression> mFilenameExpr;
376 
377  // bounding box of the current feature transformed into map crs
378  QgsRectangle mTransformedFeatureBounds;
379 
380  QString mFilenameParserError;
381  QString mFilterParserError;
382 
383  //forces all atlas enabled maps to redraw
384  void updateAtlasMaps();
385 
386  //computes the extent of the current feature, in the crs of the specified map
387  void computeExtent( QgsComposerMap *map );
388 
389  //list of predefined scales
390  QVector<qreal> mPredefinedScales;
391 };
392 
393 #endif
394 
395 
396 
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)
QString pageNameExpression() const
Returns the expression used for calculating the page name.
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.
void setPageNameExpression(const QString &pageNameExpression)
Sets the expression used for calculating the page name.
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.