QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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"
23#include "qgsvectorlayerref.h"
24
25#include <QObject>
26
27class QgsLayout;
28
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; // cppcheck-suppress duplInheritedMember
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 bool limitCoverageLayerRenderToCurrentFeature() const { return mLimitCoverageLayerRenderToCurrentFeature; }
94
101 void setLimitCoverageLayerRenderToCurrentFeature( bool limit );
102
109 QString filenameExpression() const { return mFilenameExpressionString; }
110
119 bool setFilenameExpression( const QString &expression, QString &errorString SIP_OUT );
120
126 QString currentFilename() const;
127
132 QgsVectorLayer *coverageLayer() const { return mCoverageLayer.get(); }
133
138 void setCoverageLayer( QgsVectorLayer *layer );
139
145 QString pageNameExpression() const { return mPageNameExpression; }
146
151 void setPageNameExpression( const QString &expression );
152
157 QString nameForPage( int page ) const;
158
165 bool sortFeatures() const { return mSortFeatures; }
166
173 void setSortFeatures( bool enabled );
174
184 bool sortAscending() const { return mSortAscending; }
185
195 void setSortAscending( bool ascending );
196
206 QString sortExpression() const { return mSortExpression; }
207
217 void setSortExpression( const QString &expression );
218
224 bool filterFeatures() const { return mFilterFeatures; }
225
231 void setFilterFeatures( bool filtered );
232
241 QString filterExpression() const { return mFilterExpression; }
242
254 bool setFilterExpression( const QString &expression, QString &errorString SIP_OUT );
255
260 int updateFeatures();
261
262 bool beginRender() override;
263 bool endRender() override;
264 int count() const override;
265 QString filePath( const QString &baseFilePath, const QString &extension ) override;
266
270 int currentFeatureNumber() const { return mCurrentFeatureNo; }
271
273
274 public slots:
275
276 bool next() override;
277
285 bool previous();
286
294 bool last();
295
303 bool first();
304
312 bool seekTo( int feature );
313
321 bool seekTo( const QgsFeature &feature );
322
326 void refreshCurrentFeature();
327
328 signals:
329
331 void changed();
332
334 void toggled( bool enabled );
335
338
340 void messagePushed( const QString &message );
341
345 void numberFeaturesChanged( int numFeatures );
346
348 void featureChanged( const QgsFeature &feature );
349
352
355
356 private slots:
357 void removeLayers( const QStringList &layers );
358
359 private:
360
365 bool updateFilenameExpression( QString &error );
366
371 bool evalFeatureFilename( const QgsExpressionContext &context );
372
378 bool prepareForFeature( int i );
379
380 QPointer< QgsLayout > mLayout;
381
382 bool mEnabled = false;
383 bool mHideCoverage = false;
384 bool mLimitCoverageLayerRenderToCurrentFeature = false;
385 QString mFilenameExpressionString;
386 QString mFilenameExpressionError;
387
388 QgsVectorLayerRef mCoverageLayer;
389
390 QString mCurrentFilename;
391 bool mSortFeatures = false;
392 bool mSortAscending = true;
393
394 typedef QMap< QgsFeatureId, QVariant > SorterKeys;
395 // value of field that is used for ordering of features
396 SorterKeys mFeatureKeys;
397
398 QString mSortExpression;
399
400 QString mPageNameExpression;
401
402 bool mFilterFeatures = false;
403 QString mFilterExpression;
404
405 QString mFilterParserError;
406
407 // id of each iterated feature (after filtering and sorting) paired with atlas page name
408 QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
409 // current atlas feature number
410 int mCurrentFeatureNo = -1;
411 QgsFeature mCurrentFeature;
412
413
414 friend class AtlasFeatureSorter;
415};
416
417#endif //QGSLAYOUTATLAS_H
418
419
420
An abstract base class for QgsLayout based classes which can be exported by QgsLayoutExporter.
virtual bool endRender()=0
Ends the render, performing any required cleanup tasks.
virtual QgsLayout * layout()=0
Returns the layout associated with the iterator.
virtual bool next()=0
Iterates to next feature, returning false if no more features exist to iterate over.
virtual bool beginRender()=0
Called when rendering begins, before iteration commences.
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.
virtual int count() const =0
Returns the number of features to iterate over.
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QString sortExpression() const
Returns the expression (or field name) to use for sorting features.
bool filterFeatures() const
Returns true if features should be filtered in the coverage layer.
QString filenameExpression() const
Returns the filename expression used for generating output filenames for each atlas page.
void toggled(bool enabled)
Emitted when atlas is enabled or disabled.
bool sortAscending() const
Returns true if features should be sorted in an ascending order.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
void featureChanged(const QgsFeature &feature)
Emitted when the current atlas feature changes.
friend class AtlasFeatureSorter
QString filterExpression() const
Returns the expression used for filtering features in the coverage layer.
QgsLayout * layout() override
Returns the layout associated with the iterator.
bool enabled() const
Returns whether the atlas generation is enabled.
bool limitCoverageLayerRenderToCurrentFeature() const
Returns true if the atlas is set to limit rendering on the coverage layer to the current feature.
QString pageNameExpression() const
Returns the expression (or field name) used for calculating the page name.
QgsLayoutAtlas(QgsLayout *layout)
Constructor for new QgsLayoutAtlas.
void numberFeaturesChanged(int numFeatures)
Emitted when the number of features for the atlas changes.
void messagePushed(const QString &message)
Emitted when the atlas has an updated status bar message.
void coverageLayerChanged(QgsVectorLayer *layer)
Emitted when the coverage layer for the atlas changes.
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
void renderBegun()
Emitted when atlas rendering has begun.
void renderEnded()
Emitted when atlas rendering has ended.
void changed()
Emitted when one of the atlas parameters changes.
bool sortFeatures() const
Returns true if features should be sorted in the atlas.
int currentFeatureNumber() const
Returns the current feature number, where a value of 0 corresponds to the first feature.
An interface for layout objects which can be stored and read from DOM elements.
virtual bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const =0
Stores the objects's state in a DOM element.
virtual bool readXml(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)=0
Sets the objects's state from a DOM element.
virtual QString stringType() const =0
Returns the object type as a string.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:50
A container for the context for various read/write operations on objects.
Represents a vector layer which manages a vector based dataset.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_OUT
Definition qgis_sip.h:58
_LayerRef< QgsVectorLayer > QgsVectorLayerRef