QGIS API Documentation 3.41.0-Master (cea29feecf2)
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"
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 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 );
135
140 QString nameForPage( int page ) const;
141
148 bool sortFeatures() const { return mSortFeatures; }
149
156 void setSortFeatures( bool enabled );
157
167 bool sortAscending() const { return mSortAscending; }
168
178 void setSortAscending( bool ascending );
179
189 QString sortExpression() const { return mSortExpression; }
190
200 void setSortExpression( const QString &expression );
201
207 bool filterFeatures() const { return mFilterFeatures; }
208
214 void setFilterFeatures( bool 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() const override;
248 QString filePath( const QString &baseFilePath, const QString &extension ) override;
249
253 int currentFeatureNumber() const { return mCurrentFeatureNo; }
254
256
257 public slots:
258
259 bool next() override;
260
268 bool previous();
269
277 bool last();
278
286 bool first();
287
295 bool seekTo( int feature );
296
304 bool seekTo( const QgsFeature &feature );
305
309 void refreshCurrentFeature();
310
311 signals:
312
314 void changed();
315
317 void toggled( bool enabled );
318
321
323 void messagePushed( const QString &message );
324
328 void numberFeaturesChanged( int numFeatures );
329
331 void featureChanged( const QgsFeature &feature );
332
335
338
339 private slots:
340 void removeLayers( const QStringList &layers );
341
342 private:
343
348 bool updateFilenameExpression( QString &error );
349
354 bool evalFeatureFilename( const QgsExpressionContext &context );
355
361 bool prepareForFeature( int i );
362
363 QPointer< QgsLayout > mLayout;
364
365 bool mEnabled = false;
366 bool mHideCoverage = false;
367 QString mFilenameExpressionString;
368 QString mFilenameExpressionError;
369
370 QgsVectorLayerRef mCoverageLayer;
371
372 QString mCurrentFilename;
373 bool mSortFeatures = false;
374 bool mSortAscending = true;
375
376 typedef QMap< QgsFeatureId, QVariant > SorterKeys;
377 // value of field that is used for ordering of features
378 SorterKeys mFeatureKeys;
379
380 QString mSortExpression;
381
382 QString mPageNameExpression;
383
384 bool mFilterFeatures = false;
385 QString mFilterExpression;
386
387 QString mFilterParserError;
388
389 // id of each iterated feature (after filtering and sorting) paired with atlas page name
390 QVector< QPair<QgsFeatureId, QString> > mFeatureIds;
391 // current atlas feature number
392 int mCurrentFeatureNo = -1;
393 QgsFeature mCurrentFeature;
394
395
396 friend class AtlasFeatureSorter;
397};
398
399#endif //QGSLAYOUTATLAS_H
400
401
402
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
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
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.
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
The class is used as a container of context for various read/write operations on other objects.
Represents a vector layer which manages a vector based data sets.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_OUT
Definition qgis_sip.h:58