QGIS API Documentation  3.0.2-Girona (307d082)
qgslayoutatlas.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutatlas.h
3  ----------------
4  begin : December 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail 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 QGSLAYOUTATLAS_H
17 #define QGSLAYOUTATLAS_H
18 
19 #include "qgis_core.h"
20 #include "qgsvectorlayerref.h"
23 #include <QObject>
24 
25 class QgsLayout;
26 
37 class CORE_EXPORT QgsLayoutAtlas : public QObject, public QgsAbstractLayoutIterator, public QgsLayoutSerializableObject
38 {
39  Q_OBJECT
40  public:
41 
46 
47  QString stringType() const override;
48  QgsLayout *layout() override;
49 
54  const QgsLayout *layout() const SIP_SKIP;
55 
56  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
57  bool readXml( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
58 
63  bool enabled() const { return mEnabled; }
64 
69  void setEnabled( bool enabled );
70 
75  bool hideCoverage() const { return mHideCoverage; }
76 
81  void setHideCoverage( bool hide );
82 
89  QString filenameExpression() const { return mFilenameExpressionString; }
90 
99  bool setFilenameExpression( const QString &expression, QString &errorString SIP_OUT );
100 
106  QString currentFilename() const;
107 
112  QgsVectorLayer *coverageLayer() const { return mCoverageLayer.get(); }
113 
118  void setCoverageLayer( QgsVectorLayer *layer );
119 
125  QString pageNameExpression() const { return mPageNameExpression; }
126 
131  void setPageNameExpression( const QString &expression ) { mPageNameExpression = expression; }
132 
137  QString nameForPage( int page ) const;
138 
145  bool sortFeatures() const { return mSortFeatures; }
146 
153  void setSortFeatures( bool enabled ) { mSortFeatures = enabled; }
154 
164  bool sortAscending() const { return mSortAscending; }
165 
175  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
176 
186  QString sortExpression() const { return mSortExpression; }
187 
197  void setSortExpression( const QString &expression ) { mSortExpression = expression; }
198 
204  bool filterFeatures() const { return mFilterFeatures; }
205 
211  void setFilterFeatures( bool filtered ) { mFilterFeatures = filtered; }
212 
221  QString filterExpression() const { return mFilterExpression; }
222 
234  bool setFilterExpression( const QString &expression, QString &errorString SIP_OUT );
235 
240  int updateFeatures();
241 
242  bool beginRender() override;
243  bool endRender() override;
244  int count() override;
245  QString filePath( const QString &baseFilePath, const QString &extension ) override;
246 
250  int currentFeatureNumber() const { return mCurrentFeatureNo; }
251 
252  public slots:
253 
254  bool next() override;
255 
263  bool previous();
264 
272  bool last();
273 
281  bool first();
282 
290  bool seekTo( int feature );
291 
299  bool seekTo( const QgsFeature &feature );
300 
304  void refreshCurrentFeature();
305 
306  signals:
307 
309  void changed();
310 
312  void toggled( bool );
313 
315  void coverageLayerChanged( QgsVectorLayer *layer );
316 
318  void messagePushed( const QString &message );
319 
323  void numberFeaturesChanged( int numFeatures );
324 
326  void featureChanged( const QgsFeature &feature );
327 
329  void renderBegun();
330 
332  void renderEnded();
333 
334  private slots:
335  void removeLayers( const QStringList &layers );
336 
337  private:
338 
343  bool updateFilenameExpression( QString &error );
344 
349  bool evalFeatureFilename( const QgsExpressionContext &context );
350 
356  bool prepareForFeature( int i );
357 
358  QPointer< QgsLayout > mLayout;
359 
360  bool mEnabled = false;
361  bool mHideCoverage = false;
362  QString mFilenameExpressionString;
363 
364  QgsExpression mFilenameExpression;
365  QgsVectorLayerRef mCoverageLayer;
366 
367  QString mCurrentFilename;
368  bool mSortFeatures = false;
369  bool mSortAscending = true;
370 
371  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
372  // value of field that is used for ordering of features
373  SorterKeys mFeatureKeys;
374 
375  QString mSortExpression;
376 
377  QString mPageNameExpression;
378 
379  bool mFilterFeatures = false;
380  QString mFilterExpression;
381 
382  QString mFilterParserError;
383 
384  // id of each iterated feature (after filtering and sorting) paired with atlas page name
385  QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
386  // current atlas feature number
387  int mCurrentFeatureNo = -1;
388  QgsFeature mCurrentFeature;
389 
390  QgsExpressionContext createExpressionContext();
391 
392  friend class AtlasFeatureSorter;
393 };
394 
395 #endif //QGSLAYOUTATLAS_H
396 
397 
398 
The class is used as a container of context for various read/write operations on other objects...
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
virtual bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const =0
Stores the objects&#39;s state in a DOM element.
virtual bool endRender()=0
Ends the render, performing any required cleanup tasks.
QString sortExpression() const
Returns the expression (or field name) to use for sorting features.
void setSortAscending(bool ascending)
Sets whether features should be sorted in an ascending order.
virtual bool next()=0
Iterates to next feature, returning false if no more features exist to iterate over.
void setFilterFeatures(bool filtered)
Sets whether features should be filtered in the coverage layer.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
void setSortExpression(const QString &expression)
Sets the expression (or field name) to use for sorting features.
QString pageNameExpression() const
Returns the expression (or field name) used for calculating the page name.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
#define SIP_SKIP
Definition: qgis_sip.h:119
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class used to render an Atlas, iterating over geometry features.
virtual QString stringType() const =0
Return the object type as a string.
virtual int count()=0
Returns the number of features to iterate over.
virtual QgsLayout * layout()=0
Returns the layout associated with the iterator.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
QString filterExpression() const
Returns the expression used for filtering features in the coverage layer.
bool sortAscending() const
Returns true if features should be sorted in an ascending order.
#define SIP_OUT
Definition: qgis_sip.h:51
An interface for layout objects which can be stored and read from DOM elements.
bool enabled() const
Returns whether the atlas generation is enabled.
QString filenameExpression() const
Returns the filename expression used for generating output filenames for each atlas page...
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
virtual bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)=0
Sets the objects&#39;s state from a DOM element.
void setSortFeatures(bool enabled)
Sets whether features should be sorted in the atlas.
void setPageNameExpression(const QString &expression)
Sets the expression (or field name) used for calculating the page name.
Represents a vector layer which manages a vector based data sets.
virtual bool beginRender()=0
Called when rendering begins, before iteration commences.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
virtual QString filePath(const QString &baseFilePath, const QString &extension)=0
Returns the file path for the current feature, based on a specified base file path and extension...