QGIS API Documentation  2.2.0-Valmiera
 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 
37 class CORE_EXPORT QgsAtlasComposition : public QObject
38 {
39  Q_OBJECT
40  public:
41  QgsAtlasComposition( QgsComposition* composition );
43 
45  bool enabled() const { return mEnabled; }
46  void setEnabled( bool e );
47 
51  QgsComposerMap* composerMap() const;
55  void setComposerMap( QgsComposerMap* map );
56 
57  bool hideCoverage() const { return mHideCoverage; }
58  void setHideCoverage( bool hide );
59 
63  bool fixedScale() const;
67  void setFixedScale( bool fixed );
68 
72  float margin() const;
76  void setMargin( float margin );
77 
78  QString filenamePattern() const { return mFilenamePattern; }
79  void setFilenamePattern( const QString& pattern );
80 
81  QgsVectorLayer* coverageLayer() const { return mCoverageLayer; }
82  void setCoverageLayer( QgsVectorLayer* lmap );
83 
84  bool singleFile() const { return mSingleFile; }
85  void setSingleFile( bool single ) { mSingleFile = single; }
86 
87  bool sortFeatures() const { return mSortFeatures; }
88  void setSortFeatures( bool doSort ) { mSortFeatures = doSort; }
89 
90  bool sortAscending() const { return mSortAscending; }
91  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
92 
93  bool filterFeatures() const { return mFilterFeatures; }
94  void setFilterFeatures( bool doFilter ) { mFilterFeatures = doFilter; }
95 
96  QString featureFilter() const { return mFeatureFilter; }
97  void setFeatureFilter( const QString& expression ) { mFeatureFilter = expression; }
98 
99  int sortKeyAttributeIndex() const { return mSortKeyAttributeIdx; }
100  void setSortKeyAttributeIndex( int idx ) { mSortKeyAttributeIdx = idx; }
101 
104  bool beginRender();
106  void endRender();
107 
109  int numFeatures() const;
110 
112  void prepareForFeature( int i );
113 
115  void prepareForFeature( QgsFeature * feat );
116 
118  const QString& currentFilename() const;
119 
120  void writeXML( QDomElement& elem, QDomDocument& doc ) const;
121  void readXML( const QDomElement& elem, const QDomDocument& doc );
122 
123  QgsComposition* composition() { return mComposition; }
124 
127  int updateFeatures();
128 
129  void nextFeature();
130  void prevFeature();
131  void lastFeature();
132  void firstFeature();
133 
135  QgsFeature* currentFeature() { return &mCurrentFeature; }
136 
138  void prepareMap( QgsComposerMap* map );
139 
140  signals:
142  void parameterChanged();
143 
145  void toggled( bool );
146 
148  void statusMsgChanged( QString message );
149 
151  void coverageLayerChanged( QgsVectorLayer* layer );
152 
153  private:
155  void updateFilenameExpression();
156 
158  void evalFeatureFilename();
159 
161 
162  bool mEnabled;
167 
170  // feature ordering
172  // sort direction
174 
175  // current atlas feature number
177 
178  public:
179  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
180 
181  private:
182  // value of field that is used for ordering of features
184  // key (attribute index) used for ordering
186 
187  // feature filtering
189  // feature expression filter
190  QString mFeatureFilter;
191 
192  // id of each iterated feature (after filtering and sorting)
193  QVector<QgsFeatureId> mFeatureIds;
194 
196 
197  std::auto_ptr<QgsExpression> mFilenameExpr;
198 
199  // bounding box of the current feature transformed into map crs
201 
202  //forces all atlas enabled maps to redraw
203  void updateAtlasMaps();
204 
205  //computes the extent of the current feature, in the crs of the specified map
206  void computeExtent( QgsComposerMap *map );
207 };
208 
209 #endif
210 
211 
212