QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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"
24 #include <QObject>
25 
26 class QgsLayout;
27 
42 {
43  Q_OBJECT
44  public:
45 
50 
51  QString stringType() const override;
52  QgsLayout *layout() override;
53 
58  const QgsLayout *layout() const SIP_SKIP;
59 
60  bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const override;
61  bool readXml( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
62 
67  bool enabled() const { return mEnabled; }
68 
73  void setEnabled( bool enabled );
74 
79  bool hideCoverage() const { return mHideCoverage; }
80 
85  void setHideCoverage( bool hide );
86 
93  QString filenameExpression() const { return mFilenameExpressionString; }
94 
103  bool setFilenameExpression( const QString &expression, QString &errorString SIP_OUT );
104 
110  QString currentFilename() const;
111 
116  QgsVectorLayer *coverageLayer() const { return mCoverageLayer.get(); }
117 
122  void setCoverageLayer( QgsVectorLayer *layer );
123 
129  QString pageNameExpression() const { return mPageNameExpression; }
130 
135  void setPageNameExpression( const QString &expression );
136 
141  QString nameForPage( int page ) const;
142 
149  bool sortFeatures() const { return mSortFeatures; }
150 
157  void setSortFeatures( bool enabled );
158 
168  bool sortAscending() const { return mSortAscending; }
169 
179  void setSortAscending( bool ascending );
180 
190  QString sortExpression() const { return mSortExpression; }
191 
201  void setSortExpression( const QString &expression );
202 
208  bool filterFeatures() const { return mFilterFeatures; }
209 
215  void setFilterFeatures( bool filtered );
216 
225  QString filterExpression() const { return mFilterExpression; }
226 
238  bool setFilterExpression( const QString &expression, QString &errorString SIP_OUT );
239 
244  int updateFeatures();
245 
246  bool beginRender() override;
247  bool endRender() override;
248  int count() const override;
249  QString filePath( const QString &baseFilePath, const QString &extension ) override;
250 
254  int currentFeatureNumber() const { return mCurrentFeatureNo; }
255 
257 
258  public slots:
259 
260  bool next() override;
261 
269  bool previous();
270 
278  bool last();
279 
287  bool first();
288 
296  bool seekTo( int feature );
297 
305  bool seekTo( const QgsFeature &feature );
306 
310  void refreshCurrentFeature();
311 
312  signals:
313 
315  void changed();
316 
318  void toggled( bool );
319 
321  void coverageLayerChanged( QgsVectorLayer *layer );
322 
324  void messagePushed( const QString &message );
325 
329  void numberFeaturesChanged( int numFeatures );
330 
332  void featureChanged( const QgsFeature &feature );
333 
335  void renderBegun();
336 
338  void renderEnded();
339 
340  private slots:
341  void removeLayers( const QStringList &layers );
342 
343  private:
344 
349  bool updateFilenameExpression( QString &error );
350 
355  bool evalFeatureFilename( const QgsExpressionContext &context );
356 
362  bool prepareForFeature( int i );
363 
364  QPointer< QgsLayout > mLayout;
365 
366  bool mEnabled = false;
367  bool mHideCoverage = false;
368  QString mFilenameExpressionString;
369  QString mFilenameExpressionError;
370 
371  QgsVectorLayerRef mCoverageLayer;
372 
373  QString mCurrentFilename;
374  bool mSortFeatures = false;
375  bool mSortAscending = true;
376 
377  typedef QMap< QgsFeatureId, QVariant > SorterKeys;
378  // value of field that is used for ordering of features
379  SorterKeys mFeatureKeys;
380 
381  QString mSortExpression;
382 
383  QString mPageNameExpression;
384 
385  bool mFilterFeatures = false;
386  QString mFilterExpression;
387 
388  QString mFilterParserError;
389 
390  // id of each iterated feature (after filtering and sorting) paired with atlas page name
391  QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
392  // current atlas feature number
393  int mCurrentFeatureNo = -1;
394  QgsFeature mCurrentFeature;
395 
396 
397  friend class AtlasFeatureSorter;
398 };
399 
400 #endif //QGSLAYOUTATLAS_H
401 
402 
403 
QgsAbstractLayoutIterator::count
virtual int count() const =0
Returns the number of features to iterate over.
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:406
QgsAbstractLayoutIterator::next
virtual bool next()=0
Iterates to next feature, returning false if no more features exist to iterate over.
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:34
QgsLayoutAtlas::pageNameExpression
QString pageNameExpression() const
Returns the expression (or field name) used for calculating the page name.
Definition: qgslayoutatlas.h:129
QgsLayoutAtlas::sortExpression
QString sortExpression() const
Returns the expression (or field name) to use for sorting features.
Definition: qgslayoutatlas.h:190
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsLayoutAtlas::sortAscending
bool sortAscending() const
Returns true if features should be sorted in an ascending order.
Definition: qgslayoutatlas.h:168
QgsLayoutAtlas::hideCoverage
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
Definition: qgslayoutatlas.h:79
QgsLayoutAtlas::filterExpression
QString filterExpression() const
Returns the expression used for filtering features in the coverage layer.
Definition: qgslayoutatlas.h:225
QgsLayoutAtlas::filterFeatures
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
Definition: qgslayoutatlas.h:208
qgslayoutserializableobject.h
QgsAbstractLayoutIterator
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
Definition: qgsabstractlayoutiterator.h:30
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayoutAtlas::enabled
bool enabled() const
Returns whether the atlas generation is enabled.
Definition: qgslayoutatlas.h:67
QgsAbstractLayoutIterator::layout
virtual QgsLayout * layout()=0
Returns the layout associated with the iterator.
qgsabstractlayoutiterator.h
QgsAbstractLayoutIterator::endRender
virtual bool endRender()=0
Ends the render, performing any required cleanup tasks.
QgsLayoutAtlas::coverageLayer
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
Definition: qgslayoutatlas.h:116
QgsExpressionContextGenerator::createExpressionContext
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QgsLayoutSerializableObject::writeXml
virtual bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const =0
Stores the objects's state in a DOM element.
QgsLayoutAtlas::filenameExpression
QString filenameExpression() const
Returns the filename expression used for generating output filenames for each atlas page.
Definition: qgslayoutatlas.h:93
QgsLayoutSerializableObject::readXml
virtual bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)=0
Sets the objects's state from a DOM element.
QgsLayoutAtlas::currentFeatureNumber
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
Definition: qgslayoutatlas.h:254
qgsexpressioncontextgenerator.h
QgsLayoutSerializableObject
An interface for layout objects which can be stored and read from DOM elements.
Definition: qgslayoutserializableobject.h:35
qgsvectorlayerref.h
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsAbstractLayoutIterator::beginRender
virtual bool beginRender()=0
Called when rendering begins, before iteration commences.
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
_LayerRef< QgsVectorLayer >
QgsAbstractLayoutIterator::filePath
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.
QgsExpressionContextGenerator
Abstract interface for generating an expression context.
Definition: qgsexpressioncontextgenerator.h:36
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsLayoutAtlas
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
Definition: qgslayoutatlas.h:41
QgsLayoutSerializableObject::stringType
virtual QString stringType() const =0
Returns the object type as a string.
QgsLayoutAtlas::sortFeatures
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
Definition: qgslayoutatlas.h:149