18 #include <QtAlgorithms>
32 mComposition( composition ),
34 mHideCoverage( false ), mFilenamePattern(
"'output_'||$feature" ),
35 mCoverageLayer( 0 ), mSingleFile( false ),
36 mSortFeatures( false ), mSortAscending( true ), mCurrentFeatureNo( 0 ),
37 mFilterFeatures( false ), mFeatureFilter(
"" ),
38 mFilenameParserError( QString() ),
39 mFilterParserError( QString() )
86 QList<QgsComposerMap*> maps;
88 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
127 if ( idx >= 0 && idx < fields.
count() )
147 if (
mKeys[ id1 ].type() == QVariant::Int )
149 result =
mKeys[ id1 ].toInt() <
mKeys[ id2 ].toInt();
151 else if (
mKeys[ id1 ].type() == QVariant::Double )
153 result =
mKeys[ id1 ].toDouble() <
mKeys[ id2 ].toDouble();
155 else if (
mKeys[ id1 ].type() == QVariant::String )
157 result = ( QString::localeAwareCompare(
mKeys[ id1 ].toString(),
mKeys[ id2 ].toString() ) < 0 );
181 std::auto_ptr<QgsExpression> filterExpression;
185 if ( filterExpression->hasParserError() )
204 if ( filterExpression->hasEvalError() )
210 if ( !result.toBool() )
253 if ( !featuresUpdated )
283 QList<QgsComposerMap*> maps;
285 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
316 if ( newFeatureNo < 0 )
375 QList<QgsComposerMap*> maps;
376 QList<QgsComposerMap*> atlasMaps;
378 for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
385 atlasMaps << currentMap;
391 if ( atlasMaps.isEmpty() )
403 for ( QList<QgsComposerMap*>::iterator mit = atlasMaps.begin(); mit != atlasMaps.end(); ++mit )
451 bool isPointLayer =
false;
461 isPointLayer =
false;
470 double originalScale = calc.
calculate( mOrigExtent, map->rect().width() );
471 double geomCenterX = ( xa1 + xa2 ) / 2.0;
472 double geomCenterY = ( ya1 + ya2 ) / 2.0;
477 double xMin = geomCenterX - mOrigExtent.
width() / 2.0;
478 double yMin = geomCenterY - mOrigExtent.
height() / 2.0;
481 xMin + mOrigExtent.
width(),
482 yMin + mOrigExtent.
height() );
486 double newScale = calc.
calculate( newExtent, map->rect().width() );
487 newExtent.
scale( originalScale / newScale );
492 double newWidth = mOrigExtent.
width();
493 double newHeight = mOrigExtent.
height();
495 for (
int i = 0; i < scales.size(); i++ )
497 double ratio = scales[i] / originalScale;
498 newWidth = mOrigExtent.
width() * ratio;
499 newHeight = mOrigExtent.
height() * ratio;
502 double xMin = geomCenterX - newWidth / 2.0;
503 double yMin = geomCenterY - newHeight / 2.0;
511 double newScale = calc.
calculate( newExtent, map->rect().width() );
512 newExtent.
scale( scales[i] / newScale );
527 double mapRatio = mOrigExtent.
width() / mOrigExtent.
height();
530 if ( geomRatio < mapRatio )
538 else if ( geomRatio > mapRatio )
564 QDomElement atlasElem = doc.createElement(
"Atlas" );
565 atlasElem.setAttribute(
"enabled",
mEnabled ?
"true" :
"false" );
577 atlasElem.setAttribute(
"coverageLayer",
"" );
580 atlasElem.setAttribute(
"hideCoverage",
mHideCoverage ?
"true" :
"false" );
581 atlasElem.setAttribute(
"singleFile",
mSingleFile ?
"true" :
"false" );
584 atlasElem.setAttribute(
"sortFeatures",
mSortFeatures ?
"true" :
"false" );
588 atlasElem.setAttribute(
"sortAscending",
mSortAscending ?
"true" :
"false" );
590 atlasElem.setAttribute(
"filterFeatures",
mFilterFeatures ?
"true" :
"false" );
596 elem.appendChild( atlasElem );
601 mEnabled = atlasElem.attribute(
"enabled",
"false" ) ==
"true" ?
true :
false;
612 for ( QMap<QString, QgsMapLayer*>::const_iterator it = layers.begin(); it != layers.end(); ++it )
614 if ( it.key() == atlasElem.attribute(
"coverageLayer" ) )
621 int composerMapNo = atlasElem.attribute(
"composerMap",
"-1" ).toInt();
623 if ( composerMapNo != -1 )
625 QList<QgsComposerMap*> maps;
627 for ( QList<QgsComposerMap*>::iterator it = maps.begin(); it != maps.end(); ++it )
629 if (( *it )->id() == composerMapNo )
631 composerMap = ( *it );
637 mHideCoverage = atlasElem.attribute(
"hideCoverage",
"false" ) ==
"true" ?
true :
false;
640 double margin = atlasElem.attribute(
"margin",
"0.0" ).toDouble();
641 if ( composerMap && margin != 0 )
645 bool fixedScale = atlasElem.attribute(
"fixedScale",
"false" ) ==
"true" ?
true :
false;
646 if ( composerMap && fixedScale )
651 mSingleFile = atlasElem.attribute(
"singleFile",
"false" ) ==
"true" ?
true :
false;
654 mSortFeatures = atlasElem.attribute(
"sortFeatures",
"false" ) ==
"true" ?
true :
false;
666 if ( idx >= 0 && idx < fields.
count() )
671 mSortAscending = atlasElem.attribute(
"sortAscending",
"true" ) ==
"true" ?
true :
false;
673 mFilterFeatures = atlasElem.attribute(
"filterFeatures",
"false" ) ==
"true" ?
true :
false;
QgsFeatureId id() const
Get the feature id for this feature.
Class for parsing and evaluation of expressions (formerly called "search strings").
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
QMap< QgsFeatureId, QVariant > SorterKeys
Wrapper for iterator of features from vector data provider or vector layer.
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
A rectangle specified with double values.
bool isEmpty() const
test if rectangle is empty.
void renderEnded()
Is emitted when atlas rendering has ended.
QgsVectorLayer * mCoverageLayer
QVector< QgsFeatureId > mFeatureIds
Q_DECL_DEPRECATED int sortKeyAttributeIndex() const
QString mFilenameParserError
void setNewAtlasFeatureExtent(const QgsRectangle &extent)
Sets new Extent for the current atlas preview and changes width, height (and implicitely also scale)...
QgsAtlasComposition(QgsComposition *composition)
double yMaximum() const
Get the y maximum value (top side of rectangle)
double atlasMargin() const
Returns the margin size (percentage) used when the map is in atlas mode.
Q_DECL_DEPRECATED bool fixedScale() const
Returns whether the atlas map uses a fixed scale.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void computeExtent(QgsComposerMap *map)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
void cache()
Create cache image.
QVector< double > mPredefinedScales
#define Q_NOWARN_DEPRECATED_PUSH
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
QgsComposition * composition()
bool enabled() const
Returns whether the atlas generation is enabled.
Container of fields for a vector layer.
QgsCoordinateTransform mTransform
void toggled(bool)
emitted when atlas is enabled or disabled
void setHideCoverage(bool hide)
Sets whether the coverage layer should be hidden in map items in the composition. ...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
int numPages() const
Note: added in version 1.9.
void endRender()
Ends the rendering.
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
void readXML(const QDomElement &elem, const QDomDocument &doc)
QGis::WkbType wkbType() const
Returns the WKBType or WKBUnknown in case of error.
Q_DECL_DEPRECATED void setFixedScale(bool fixed)
Sets whether the atlas map should use a fixed scale.
Q_DECL_DEPRECATED float margin() const
Returns the margin for the atlas map.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
bool setFilenamePattern(const QString &pattern)
Sets the filename expression used for generating output filenames for each atlas page.
Q_DECL_DEPRECATED void setSortKeyAttributeIndex(int idx)
QgsRectangle mTransformedFeatureBounds
void setCoverageLayer(QgsVectorLayer *layer)
Sets the coverage layer to use for the atlas features.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
bool beginRender()
Begins the rendering.
Q_DECL_DEPRECATED void setComposerMap(QgsComposerMap *map)
Sets the map used by the atlas.
QString mSortKeyAttributeName
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
void setPredefinedScales(const QVector< double > &scales)
Sets the list of predefined scales for the atlas.
void prepareMap(QgsComposerMap *map)
Recalculates the bounds of an atlas driven map.
void statusMsgChanged(QString message)
Is emitted when the atlas has an updated status bar message for the composer window.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
bool setAtlasMode(QgsComposition::AtlasMode mode)
Sets the current atlas mode of the composition.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
int numFeatures() const
Returns the number of features in the coverage layer.
const QgsAttributes & attributes() const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
int count() const
Return number of items.
Q_DECL_DEPRECATED bool atlasFixedScale() const
Returns true if the map uses a fixed scale when in atlas mode.
void setEnabled(bool enabled)
Sets whether the atlas is enabled.
int updateFeatures()
Requeries the current atlas coverage layer and applies filtering and sorting.
void writeXML(QDomElement &elem, QDomDocument &doc) const
Graphics scene for map printing.
bool prepareForFeature(int i)
Prepare the atlas map for the given feature.
Object representing map window.
QgsComposition * mComposition
void featureChanged(QgsFeature *feature)
Is emitted when the current atlas feature changes.
void coverageLayerChanged(QgsVectorLayer *layer)
Is emitted when the coverage layer for an atlas changes.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
bool operator()(const QgsFeatureId &id1, const QgsFeatureId &id2)
#define Q_NOWARN_DEPRECATED_POP
void renderBegun()
Is emitted when atlas rendering has begun.
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
QgsRectangle extent() const
FieldSorter(QgsAtlasComposition::SorterKeys &keys, bool ascending=true)
Q_DECL_DEPRECATED QgsComposerMap * composerMap() const
Returns the map used by the atlas.
Q_DECL_DEPRECATED void setMargin(float margin)
Sets the margin for the atlas map.
bool evalFeatureFilename()
Evaluates filename for current feature.
QString mFilterParserError
AtlasScalingMode atlasScalingMode() const
Returns the current atlas scaling mode.
Class for storing a coordinate reference system (CRS)
const QgsComposition * composition() const
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
void parameterChanged()
emitted when one of the parameters changes
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTranasform ct.
QgsFeature mCurrentFeature
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
const QString & currentFilename() const
Returns the current filename.
std::auto_ptr< QgsExpression > mFilenameExpr
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
static void setSpecialColumn(const QString &name, QVariant value)
Assign a special column.
void setAtlasDriven(bool enabled)
Sets whether the map extent will follow the current atlas feature.
bool nextFeature(QgsFeature &f)
void composerItems(QList< T * > &itemList)
Return composer items of a specific type.
double width() const
Width of the rectangle.
Represents a vector layer which manages a vector based data sets.
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsAtlasComposition::SorterKeys & mKeys
double height() const
Height of the rectangle.
bool updateFilenameExpression()
Updates the filename expression.
void scale(double scaleFactor, const QgsPoint *c=0)
Scale the rectangle around its center point.