2012-10-05 16:25:11 +02:00
|
|
|
/** \ingroup MapComposer
|
|
|
|
* Class used to render an Atlas, iterating over geometry features.
|
|
|
|
* prepareForFeature() modifies the atlas map's extent to zoom on the given feature.
|
|
|
|
* This class is used for printing, exporting to PDF and images.
|
2014-04-28 19:11:11 +10:00
|
|
|
* @note This class should not be created directly. For the atlas to function correctly
|
|
|
|
* the atlasComposition() property for QgsComposition should be used to retrieve a
|
|
|
|
* QgsAtlasComposition which is automatically created and attached to the composition.
|
|
|
|
*/
|
2012-10-06 14:49:01 +03:00
|
|
|
class QgsAtlasComposition : QObject
|
2012-10-05 16:25:11 +02:00
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsatlascomposition.h>
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
|
|
|
QgsAtlasComposition( QgsComposition* composition );
|
|
|
|
~QgsAtlasComposition();
|
2012-10-06 14:49:01 +03:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns whether the atlas generation is enabled
|
2014-04-28 19:11:11 +10:00
|
|
|
* @returns true if atlas is enabled
|
|
|
|
* @see setEnabled
|
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
bool enabled() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets whether the atlas is enabled
|
2014-04-28 19:11:11 +10:00
|
|
|
* @param enabled set to true to enable to atlas
|
|
|
|
* @see enabled
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
void setEnabled( bool enabled );
|
2012-10-05 16:25:11 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns true if the atlas is set to hide the coverage layer
|
2014-04-28 19:11:11 +10:00
|
|
|
* @returns true if coverage layer is hidden
|
|
|
|
* @see setHideCoverage
|
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
bool hideCoverage() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets whether the coverage layer should be hidden in map items in the composition
|
2014-04-28 19:11:11 +10:00
|
|
|
* @param hide set to true to hide the coverage layer
|
|
|
|
* @see hideCoverage
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2015-08-16 11:56:27 +02:00
|
|
|
void setHideCoverage( bool hide );
|
2012-10-06 14:49:01 +03:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the filename expression used for generating output filenames for each
|
2014-04-28 19:11:11 +10:00
|
|
|
* atlas page.
|
|
|
|
* @returns filename pattern
|
|
|
|
* @see setFilenamePattern
|
2014-05-29 22:48:54 +10:00
|
|
|
* @see filenamePatternErrorString
|
2014-04-28 19:11:11 +10:00
|
|
|
* @note This property has no effect when exporting to PDF if singleFile() is true
|
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
QString filenamePattern() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the filename expression used for generating output filenames for each
|
2014-04-28 19:11:11 +10:00
|
|
|
* atlas page.
|
2014-05-29 22:48:54 +10:00
|
|
|
* @returns true if filename expression could be successful set, false if expression is invalid
|
2014-04-28 19:11:11 +10:00
|
|
|
* @param pattern expression to use for output filenames
|
|
|
|
* @see filenamePattern
|
2014-05-29 22:48:54 +10:00
|
|
|
* @see filenamePatternErrorString
|
2014-04-28 19:11:11 +10:00
|
|
|
* @note This method has no effect when exporting to PDF if singleFile() is true
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2014-05-29 22:48:54 +10:00
|
|
|
bool setFilenamePattern( const QString& pattern );
|
2014-06-02 21:00:51 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns an error string from parsing the filename expression.
|
2014-05-29 22:48:54 +10:00
|
|
|
* @returns filename pattern parser error
|
|
|
|
* @see setFilenamePattern
|
|
|
|
* @see filenamePattern
|
|
|
|
*/
|
|
|
|
QString filenamePatternErrorString() const;
|
2012-10-06 14:49:01 +03:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the coverage layer used for the atlas features
|
2014-04-28 19:11:11 +10:00
|
|
|
* @returns atlas coverage layer
|
|
|
|
* @see setCoverageLayer
|
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
QgsVectorLayer* coverageLayer() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the coverage layer to use for the atlas features
|
2014-04-28 19:11:11 +10:00
|
|
|
* @param layer vector coverage layer
|
|
|
|
* @see coverageLayer
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
void setCoverageLayer( QgsVectorLayer* layer );
|
2015-08-16 11:56:27 +02:00
|
|
|
|
2015-08-03 16:05:39 +10:00
|
|
|
/** Returns the expression used for calculating the page name.
|
|
|
|
* @returns expression string, or field name from coverage layer
|
|
|
|
* @see setPageNameExpression
|
|
|
|
* @see nameForPage
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QString pageNameExpression() const;
|
|
|
|
|
|
|
|
/** Sets the expression used for calculating the page name.
|
|
|
|
* @param pageNameExpression expression string, or field name from coverage layer
|
|
|
|
* @see pageNameExpression
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setPageNameExpression( const QString& pageNameExpression );
|
|
|
|
|
|
|
|
/** Returns the calculated name for a specified atlas page number.
|
|
|
|
* @param pageNumber number of page, where 0 = first page
|
|
|
|
* @returns page name
|
|
|
|
* @see pageNameExpression
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QString nameForPage( int pageNumber ) const;
|
2012-10-06 14:49:01 +03:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns whether the atlas will be exported to a single file. This is only
|
2014-04-28 19:11:11 +10:00
|
|
|
* applicable for PDF exports.
|
|
|
|
* @returns true if atlas will be exported to a single file
|
|
|
|
* @see setSingleFile
|
|
|
|
* @note This property is only used for PDF exports.
|
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
bool singleFile() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets whether the atlas should be exported to a single file. This is only
|
2014-04-28 19:11:11 +10:00
|
|
|
* applicable for PDF exports.
|
|
|
|
* @param single set to true to export atlas to a single file.
|
|
|
|
* @see singleFile
|
|
|
|
* @note This method is only used for PDF exports.
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2012-10-05 16:25:11 +02:00
|
|
|
void setSingleFile( bool single );
|
2012-10-06 14:49:01 +03:00
|
|
|
|
2013-02-06 15:06:59 +01:00
|
|
|
bool sortFeatures() const;
|
|
|
|
void setSortFeatures( bool doSort );
|
|
|
|
|
|
|
|
bool sortAscending() const;
|
|
|
|
void setSortAscending( bool ascending );
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
bool filterFeatures() const;
|
|
|
|
void setFilterFeatures( bool doFilter );
|
|
|
|
|
2013-02-06 15:06:59 +01:00
|
|
|
QString featureFilter() const;
|
|
|
|
void setFeatureFilter( const QString& expression );
|
2014-06-02 21:00:51 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns an error string from parsing the feature filter expression.
|
2014-05-29 22:48:54 +10:00
|
|
|
* @returns filename pattern parser error
|
|
|
|
* @see setFilenamePattern
|
|
|
|
* @see filenamePattern
|
|
|
|
*/
|
|
|
|
QString featureFilterErrorString() const;
|
2013-02-06 15:06:59 +01:00
|
|
|
|
2014-03-24 22:53:10 +01:00
|
|
|
QString sortKeyAttributeName() const;
|
2015-10-07 11:55:34 +11:00
|
|
|
void setSortKeyAttributeName( const QString& fieldName );
|
2014-04-05 01:19:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Returns the current list of predefined scales for the atlas. This is used
|
2014-05-23 11:14:01 +10:00
|
|
|
* for maps which are set to the predefined atlas scaling mode.
|
|
|
|
* @returns a vector of doubles representing predefined scales
|
|
|
|
* @see setPredefinedScales
|
|
|
|
* @see QgsComposerMap::atlasScalingMode
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2014-09-05 20:45:46 +02:00
|
|
|
const QVector<qreal>& predefinedScales() const;
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Sets the list of predefined scales for the atlas. This is used
|
2014-05-23 11:14:01 +10:00
|
|
|
* for maps which are set to the predefined atlas scaling mode.
|
|
|
|
* @param scales a vector of doubles representing predefined scales
|
|
|
|
* @see predefinedScales
|
|
|
|
* @see QgsComposerMap::atlasScalingMode
|
2014-05-19 15:10:47 +02:00
|
|
|
*/
|
2014-09-05 20:45:46 +02:00
|
|
|
void setPredefinedScales( const QVector<qreal>& scales );
|
2014-05-19 15:10:47 +02:00
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/** Begins the rendering. Returns true if successful, false if no matching atlas
|
|
|
|
features found.*/
|
|
|
|
bool beginRender();
|
2012-10-05 16:25:11 +02:00
|
|
|
/** Ends the rendering. Restores original extent */
|
|
|
|
void endRender();
|
|
|
|
|
|
|
|
/** Returns the number of features in the coverage layer */
|
2013-09-06 22:07:42 +02:00
|
|
|
int numFeatures() const;
|
2012-10-05 16:25:11 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Prepare the atlas map for the given feature. Sets the extent and context variables
|
2014-09-30 20:37:16 +10:00
|
|
|
* @param i feature number
|
|
|
|
* @param updateMaps set to true to redraw maps and recalculate their extent
|
2014-05-29 22:48:54 +10:00
|
|
|
* @returns true if feature was successfully prepared
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2014-09-30 20:37:16 +10:00
|
|
|
bool prepareForFeature( const int i, const bool updateMaps = true );
|
2012-10-05 16:25:11 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Prepare the atlas map for the given feature. Sets the extent and context variables
|
2014-05-29 22:48:54 +10:00
|
|
|
* @returns true if feature was successfully prepared
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2014-09-02 19:31:31 +10:00
|
|
|
bool prepareForFeature( const QgsFeature * feat );
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2015-08-13 00:20:02 +10:00
|
|
|
/** Returns the current filename. Must be called after prepareForFeature() */
|
2015-10-27 14:03:00 +11:00
|
|
|
QString currentFilename() const;
|
2014-01-27 09:22:24 +01:00
|
|
|
|
|
|
|
void writeXML( QDomElement& elem, QDomDocument& doc ) const;
|
2014-08-17 13:37:26 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Reads general atlas settings from xml
|
2014-07-04 23:46:43 +10:00
|
|
|
* @param elem a QDomElement holding the atlas properties.
|
|
|
|
* @param doc QDomDocument for the source xml.
|
|
|
|
* @see readXMLMapSettings
|
|
|
|
* @note This method should be called before restoring composer item properties
|
|
|
|
*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void readXML( const QDomElement& elem, const QDomDocument& doc );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Reads old (pre 2.2) map related atlas settings from xml
|
2014-07-04 23:46:43 +10:00
|
|
|
* @param elem a QDomElement holding the atlas map properties.
|
|
|
|
* @param doc QDomDocument for the source xml.
|
|
|
|
* @see readXMLMapSettings
|
|
|
|
* @note This method should be called after restoring composer item properties
|
|
|
|
* @note added in version 2.5
|
|
|
|
*/
|
|
|
|
void readXMLMapSettings( const QDomElement& elem, const QDomDocument& doc );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
QgsComposition* composition();
|
|
|
|
|
2014-01-14 22:20:40 +11:00
|
|
|
/** Requeries the current atlas coverage layer and applies filtering and sorting. Returns
|
2016-02-14 03:50:23 +01:00
|
|
|
* number of matching features. Must be called after prepareForFeature()
|
|
|
|
*/
|
2014-01-14 22:20:40 +11:00
|
|
|
int updateFeatures();
|
|
|
|
|
2015-08-13 00:20:02 +10:00
|
|
|
/** Returns the current atlas feature. Must be called after prepareForFeature().
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QgsFeature feature() const;
|
|
|
|
|
|
|
|
/** Returns the name of the page for the current atlas feature. Must be called after prepareForFeature().
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
QString currentPageName() const;
|
2015-07-29 11:52:14 +02:00
|
|
|
|
2015-08-13 00:20:02 +10:00
|
|
|
/** Returns the current feature number, where a value of 0 corresponds to the first feature.
|
2015-07-23 15:02:06 +10:00
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
int currentFeatureNumber() const;
|
2012-10-05 16:25:11 +02:00
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/** Recalculates the bounds of an atlas driven map */
|
|
|
|
void prepareMap( QgsComposerMap* map );
|
2015-08-16 11:56:27 +02:00
|
|
|
|
2016-02-14 03:50:23 +01:00
|
|
|
|
|
|
|
//deprecated methods
|
2015-08-16 11:56:27 +02:00
|
|
|
|
2015-08-03 16:05:39 +10:00
|
|
|
/** Returns the map used by the atlas
|
|
|
|
* @deprecated Use QgsComposerMap::atlasDriven() instead
|
|
|
|
*/
|
|
|
|
QgsComposerMap* composerMap() const /Deprecated/;
|
|
|
|
|
|
|
|
/** Sets the map used by the atlas
|
|
|
|
* @deprecated Use QgsComposerMap::setAtlasDriven( true ) instead
|
|
|
|
*/
|
|
|
|
void setComposerMap( QgsComposerMap* map ) /Deprecated/;
|
2015-08-16 11:56:27 +02:00
|
|
|
|
2015-08-03 16:05:39 +10:00
|
|
|
/** Returns whether the atlas map uses a fixed scale
|
|
|
|
* @deprecated since 2.4 Use QgsComposerMap::atlasScalingMode() instead
|
|
|
|
*/
|
|
|
|
bool fixedScale() const /Deprecated/;
|
|
|
|
|
|
|
|
/** Sets whether the atlas map should use a fixed scale
|
|
|
|
* @deprecated since 2.4 Use QgsComposerMap::setAtlasScalingMode() instead
|
|
|
|
*/
|
|
|
|
void setFixedScale( bool fixed ) /Deprecated/;
|
|
|
|
|
|
|
|
/** Returns the margin for the atlas map
|
|
|
|
* @deprecated Use QgsComposerMap::atlasMargin() instead
|
|
|
|
*/
|
|
|
|
float margin() const /Deprecated/;
|
|
|
|
|
|
|
|
/** Sets the margin for the atlas map
|
|
|
|
* @deprecated Use QgsComposerMap::setAtlasMargin( double ) instead
|
|
|
|
*/
|
|
|
|
void setMargin( float margin ) /Deprecated/;
|
2015-08-16 11:56:27 +02:00
|
|
|
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use sortKeyAttributeName instead
|
2015-08-03 16:05:39 +10:00
|
|
|
int sortKeyAttributeIndex() const /Deprecated/;
|
2015-12-07 21:54:40 +11:00
|
|
|
//! @deprecated use setSortKeyAttributeName instead
|
2015-08-03 16:05:39 +10:00
|
|
|
void setSortKeyAttributeIndex( int idx ) /Deprecated/;
|
2012-10-05 16:25:11 +02:00
|
|
|
|
2015-12-07 21:54:40 +11:00
|
|
|
/** Returns the current atlas feature. Must be called after prepareForFeature( i ).
|
|
|
|
* @deprecated use feature() instead
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2015-08-13 00:20:02 +10:00
|
|
|
QgsFeature* currentFeature() /Deprecated/;
|
|
|
|
|
2015-06-26 10:12:58 +02:00
|
|
|
/** Returns the current atlas geometry in the given projection system (default to the coverage layer's CRS) */
|
|
|
|
QgsGeometry currentGeometry( const QgsCoordinateReferenceSystem& projectedTo = QgsCoordinateReferenceSystem() ) const;
|
|
|
|
|
2014-09-30 20:37:16 +10:00
|
|
|
public slots:
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Refreshes the current atlas feature, by refetching its attributes from the vector layer provider
|
2014-09-30 20:37:16 +10:00
|
|
|
* @note added in QGIS 2.5
|
2016-02-14 03:50:23 +01:00
|
|
|
*/
|
2014-09-30 20:37:16 +10:00
|
|
|
void refreshFeature();
|
|
|
|
|
|
|
|
void nextFeature();
|
|
|
|
void prevFeature();
|
|
|
|
void lastFeature();
|
|
|
|
void firstFeature();
|
|
|
|
|
2013-06-23 16:00:16 +02:00
|
|
|
signals:
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Emitted when one of the parameters changes */
|
2012-10-05 16:25:11 +02:00
|
|
|
void parameterChanged();
|
2014-01-19 23:04:24 +11:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Emitted when atlas is enabled or disabled */
|
2014-01-19 23:04:24 +11:00
|
|
|
void toggled( bool );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Is emitted when the atlas has an updated status bar message for the composer window*/
|
2015-10-26 22:46:25 +11:00
|
|
|
void statusMsgChanged( const QString& message );
|
2014-01-27 09:22:24 +01:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Is emitted when the coverage layer for an atlas changes*/
|
2014-01-19 23:04:24 +11:00
|
|
|
void coverageLayerChanged( QgsVectorLayer* layer );
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Is emitted when atlas rendering has begun*/
|
2014-02-26 15:43:11 +01:00
|
|
|
void renderBegun();
|
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Is emitted when atlas rendering has ended*/
|
2014-02-26 15:43:11 +01:00
|
|
|
void renderEnded();
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2015-07-29 11:52:14 +02:00
|
|
|
/** Is emitted when the current atlas feature changes*/
|
2014-04-28 19:38:56 +10:00
|
|
|
void featureChanged( QgsFeature* feature );
|
2015-07-29 11:52:14 +02:00
|
|
|
|
2015-07-23 15:02:06 +10:00
|
|
|
/** Is emitted when the number of features for the atlas changes.
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void numberFeaturesChanged( int numFeatures );
|
2012-10-06 14:49:01 +03:00
|
|
|
};
|