QGIS API Documentation 3.99.0-Master (f78f5286a64)
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
26class QgsLayout;
27
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; // cppcheck-suppress duplInheritedMember
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 bool limitCoverageLayerRenderToCurrentFeature() const { return mLimitCoverageLayerRenderToCurrentFeature; }
93
100 void setLimitCoverageLayerRenderToCurrentFeature( bool limit );
101
108 QString filenameExpression() const { return mFilenameExpressionString; }
109
118 bool setFilenameExpression( const QString &expression, QString &errorString SIP_OUT );
119
125 QString currentFilename() const;
126
131 QgsVectorLayer *coverageLayer() const { return mCoverageLayer.get(); }
132
137 void setCoverageLayer( QgsVectorLayer *layer );
138
144 QString pageNameExpression() const { return mPageNameExpression; }
145
150 void setPageNameExpression( const QString &expression );
151
156 QString nameForPage( int page ) const;
157
164 bool sortFeatures() const { return mSortFeatures; }
165
172 void setSortFeatures( bool enabled );
173
183 bool sortAscending() const { return mSortAscending; }
184
194 void setSortAscending( bool ascending );
195
205 QString sortExpression() const { return mSortExpression; }
206
216 void setSortExpression( const QString &expression );
217
223 bool filterFeatures() const { return mFilterFeatures; }
224
230 void setFilterFeatures( bool filtered );
231
240 QString filterExpression() const { return mFilterExpression; }
241
253 bool setFilterExpression( const QString &expression, QString &errorString SIP_OUT );
254
259 int updateFeatures();
260
261 bool beginRender() override;
262 bool endRender() override;
263 int count() const override;
264 QString filePath( const QString &baseFilePath, const QString &extension ) override;
265
269 int currentFeatureNumber() const { return mCurrentFeatureNo; }
270
272
273 public slots:
274
275 bool next() override;
276
284 bool previous();
285
293 bool last();
294
302 bool first();
303
311 bool seekTo( int feature );
312
320 bool seekTo( const QgsFeature &feature );
321
325 void refreshCurrentFeature();
326
327 signals:
328
330 void changed();
331
333 void toggled( bool enabled );
334
337
339 void messagePushed( const QString &message );
340
344 void numberFeaturesChanged( int numFeatures );
345
347 void featureChanged( const QgsFeature &feature );
348
351
354
355 private slots:
356 void removeLayers( const QStringList &layers );
357
358 private:
359
364 bool updateFilenameExpression( QString &error );
365
370 bool evalFeatureFilename( const QgsExpressionContext &context );
371
377 bool prepareForFeature( int i );
378
379 QPointer< QgsLayout > mLayout;
380
381 bool mEnabled = false;
382 bool mHideCoverage = false;
383 bool mLimitCoverageLayerRenderToCurrentFeature = false;
384 QString mFilenameExpressionString;
385 QString mFilenameExpressionError;
386
387 QgsVectorLayerRef mCoverageLayer;
388
389 QString mCurrentFilename;
390 bool mSortFeatures = false;
391 bool mSortAscending = true;
392
393 typedef QMap< QgsFeatureId, QVariant > SorterKeys;
394 // value of field that is used for ordering of features
395 SorterKeys mFeatureKeys;
396
397 QString mSortExpression;
398
399 QString mPageNameExpression;
400
401 bool mFilterFeatures = false;
402 QString mFilterExpression;
403
404 QString mFilterParserError;
405
406 // id of each iterated feature (after filtering and sorting) paired with atlas page name
407 QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
408 // current atlas feature number
409 int mCurrentFeatureNo = -1;
410 QgsFeature mCurrentFeature;
411
412
413 friend class AtlasFeatureSorter;
414};
415
416#endif //QGSLAYOUTATLAS_H
417
418
419
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
Used to render QgsLayout as an atlas, by iterating over the features from an associated vector layer.
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.
QString filterExpression() const
Returns the expression used for filtering features in the coverage layer.
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.
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:49
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