QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
40 class CORE_EXPORT QgsLayoutAtlas : public QObject, public QgsAbstractLayoutIterator, public QgsLayoutSerializableObject
41 {
42  Q_OBJECT
43  public:
44 
49 
50  QString stringType() const override;
51  QgsLayout *layout() override;
52 
57  const QgsLayout *layout() const SIP_SKIP;
58 
59  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
60  bool readXml( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
61 
66  bool enabled() const { return mEnabled; }
67 
72  void setEnabled( bool enabled );
73 
78  bool hideCoverage() const { return mHideCoverage; }
79 
84  void setHideCoverage( bool hide );
85 
92  QString filenameExpression() const { return mFilenameExpressionString; }
93 
102  bool setFilenameExpression( const QString &expression, QString &errorString SIP_OUT );
103 
109  QString currentFilename() const;
110 
115  QgsVectorLayer *coverageLayer() const { return mCoverageLayer.get(); }
116 
121  void setCoverageLayer( QgsVectorLayer *layer );
122 
128  QString pageNameExpression() const { return mPageNameExpression; }
129 
134  void setPageNameExpression( const QString &expression ) { mPageNameExpression = expression; }
135 
140  QString nameForPage( int page ) const;
141 
148  bool sortFeatures() const { return mSortFeatures; }
149 
156  void setSortFeatures( bool enabled ) { mSortFeatures = enabled; }
157 
167  bool sortAscending() const { return mSortAscending; }
168 
178  void setSortAscending( bool ascending ) { mSortAscending = ascending; }
179 
189  QString sortExpression() const { return mSortExpression; }
190 
200  void setSortExpression( const QString &expression ) { mSortExpression = expression; }
201 
207  bool filterFeatures() const { return mFilterFeatures; }
208 
214  void setFilterFeatures( bool filtered ) { mFilterFeatures = filtered; }
215 
224  QString filterExpression() const { return mFilterExpression; }
225 
237  bool setFilterExpression( const QString &expression, QString &errorString SIP_OUT );
238 
243  int updateFeatures();
244 
245  bool beginRender() override;
246  bool endRender() override;
247  int count() override;
248  QString filePath( const QString &baseFilePath, const QString &extension ) override;
249 
253  int currentFeatureNumber() const { return mCurrentFeatureNo; }
254 
255  public slots:
256 
257  bool next() override;
258 
266  bool previous();
267 
275  bool last();
276 
284  bool first();
285 
293  bool seekTo( int feature );
294 
302  bool seekTo( const QgsFeature &feature );
303 
307  void refreshCurrentFeature();
308 
309  signals:
310 
312  void changed();
313 
315  void toggled( bool );
316 
318  void coverageLayerChanged( QgsVectorLayer *layer );
319 
321  void messagePushed( const QString &message );
322 
326  void numberFeaturesChanged( int numFeatures );
327 
329  void featureChanged( const QgsFeature &feature );
330 
332  void renderBegun();
333 
335  void renderEnded();
336 
337  private slots:
338  void removeLayers( const QStringList &layers );
339 
340  private:
341 
346  bool updateFilenameExpression( QString &error );
347 
352  bool evalFeatureFilename( const QgsExpressionContext &context );
353 
359  bool prepareForFeature( int i );
360 
361  QPointer< QgsLayout > mLayout;
362 
363  bool mEnabled = false;
364  bool mHideCoverage = false;
365  QString mFilenameExpressionString;
366 
367  QgsExpression mFilenameExpression;
368  QgsVectorLayerRef mCoverageLayer;
369 
370  QString mCurrentFilename;
371  bool mSortFeatures = false;
372  bool mSortAscending = true;
373 
374  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
375  // value of field that is used for ordering of features
376  SorterKeys mFeatureKeys;
377 
378  QString mSortExpression;
379 
380  QString mPageNameExpression;
381 
382  bool mFilterFeatures = false;
383  QString mFilterExpression;
384 
385  QString mFilterParserError;
386 
387  // id of each iterated feature (after filtering and sorting) paired with atlas page name
388  QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
389  // current atlas feature number
390  int mCurrentFeatureNo = -1;
391  QgsFeature mCurrentFeature;
392 
393  QgsExpressionContext createExpressionContext();
394 
395  friend class AtlasFeatureSorter;
396 };
397 
398 #endif //QGSLAYOUTATLAS_H
399 
400 
401 
Class for parsing and evaluation of expressions (formerly called "search strings").
The class is used as a container of context for various read/write operations on other objects...
QString pageNameExpression() const
Returns the expression (or field name) used for calculating the page name.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
#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.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
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.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
QString filenameExpression() const
Returns the filename expression used for generating output filenames for each atlas page...
void setSortExpression(const QString &expression)
Sets the expression (or field name) to use for sorting features.
QString filterExpression() const
Returns the expression used for filtering features in 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
bool enabled() const
Returns whether the atlas generation is enabled.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
virtual QString stringType() const =0
Returns 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
bool hideCoverage() const
Returns true if the atlas is set to hide 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.
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.
QString sortExpression() const
Returns the expression (or field name) to use for sorting features.
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.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
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...