Skip to content

Commit 6bb9dfe

Browse files
committedJan 14, 2014
[FEATURE][composer] Allow for more than one atlas controlled map in compositions (or none), by moving some atlas properties to map items (fix #9248) (fix #6484)
1 parent 2cdc896 commit 6bb9dfe

31 files changed

+791
-315
lines changed
 

‎python/core/composer/qgsatlascomposition.sip

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,34 @@ public:
1717
bool enabled() const;
1818
void setEnabled( bool e );
1919

20+
/**Returns the map used by the atlas
21+
* @deprecated Use QgsComposerMap::atlasDriven() instead
22+
*/
2023
QgsComposerMap* composerMap() const;
24+
/**Sets the map used by the atlas
25+
* @deprecated Use QgsComposerMap::setAtlasDriven( true ) instead
26+
*/
2127
void setComposerMap( QgsComposerMap* map );
2228

2329
bool hideCoverage() const;
2430
void setHideCoverage( bool hide );
2531

32+
/**Returns whether the atlas map uses a fixed scale
33+
* @deprecated Use QgsComposerMap::atlasFixedScale() instead
34+
*/
2635
bool fixedScale() const;
36+
/**Sets whether the atlas map should use a fixed scale
37+
* @deprecated Use QgsComposerMap::setAtlasFixedScale( bool ) instead
38+
*/
2739
void setFixedScale( bool fixed );
2840

41+
/**Returns the margin for the atlas map
42+
* @deprecated Use QgsComposerMap::atlasMargin() instead
43+
*/
2944
float margin() const;
45+
/**Sets the margin for the atlas map
46+
* @deprecated Use QgsComposerMap::setAtlasMargin( double ) instead
47+
*/
3048
void setMargin( float margin );
3149

3250
QString filenamePattern() const;
@@ -66,6 +84,21 @@ public:
6684

6785
/** Returns the current filename. Must be called after prepareForFeature( i ) */
6886
const QString& currentFilename() const;
87+
88+
/** Requeries the current atlas coverage layer and applies filtering and sorting. Returns
89+
number of matching features. Must be called after prepareForFeature( i ) */
90+
int updateFeatures();
91+
92+
void nextFeature();
93+
void prevFeature();
94+
void lastFeature();
95+
void firstFeature();
96+
97+
/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
98+
QgsFeature* currentFeature();
99+
100+
/** Recalculates the bounds of an atlas driven map */
101+
void prepareMap( QgsComposerMap* map );
69102

70103
void writeXML( QDomElement& elem, QDomDocument& doc ) const;
71104
void readXML( const QDomElement& elem, const QDomDocument& doc );

‎python/core/composer/qgscomposermap.sip

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,22 @@ class QgsComposerMap : QgsComposerItem
366366
* @deprecated Use QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
367367
* instead
368368
*/
369-
void sizeChangedByRotation( double& width, double& height );
369+
void sizeChangedByRotation( double& width, double& height );
370+
371+
/** Returns true if the map extent is set to follow the current atlas feature */
372+
bool atlasDriven() const;
373+
/** Set to true if the map extents should be set by the current atlas feature */
374+
void setAtlasDriven( bool enabled );
375+
376+
/** Returns true if the map uses a fixed scale when in atlas mode */
377+
bool atlasFixedScale() const;
378+
/** Set to true if the map should use a fixed scale when in atlas mode */
379+
void setAtlasFixedScale( bool fixed );
380+
381+
/** Returns the margin size (percentage) used when the map is in atlas mode */
382+
double atlasMargin() const;
383+
/** Sets the margin size (percentage) used when the map is in atlas mode */
384+
void setAtlasMargin( double margin );
370385

371386
signals:
372387
void extentChanged();

‎src/app/composer/qgsatlascompositionwidget.cpp

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,10 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
4949
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerAdded( QgsMapLayer* ) ) );
5050
}
5151

52-
// update the composer map combo box
53-
// populate the map list
54-
mComposerMapComboBox->clear();
55-
QList<const QgsComposerMap*> availableMaps = mComposition->composerMapItems();
56-
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
57-
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
58-
{
59-
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), qVariantFromValue(( void* )*mapItemIt ) );
60-
}
61-
6252
// Sort direction
6353
mAtlasSortFeatureDirectionButton->setEnabled( false );
64-
6554
mAtlasSortFeatureKeyComboBox->setEnabled( false );
6655

67-
// Connect to addition / removal of maps
68-
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
69-
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );
70-
71-
connect( mAtlasMarginRadio, SIGNAL( toggled( bool ) ), mAtlasMarginSpinBox, SLOT( setEnabled( bool ) ) );
72-
7356
// connect to updates
7457
connect( &mComposition->atlasComposition(), SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) );
7558

@@ -90,7 +73,6 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
9073
mVisibilityGroup->setEnabled( true );
9174
mSortingGroup->setEnabled( true );
9275
mFilteringGroup->setEnabled( true );
93-
mScalingGroup->setEnabled( true );
9476
mOutputGroup->setEnabled( true );
9577
}
9678
else
@@ -100,7 +82,6 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
10082
mVisibilityGroup->setEnabled( false );
10183
mSortingGroup->setEnabled( false );
10284
mFilteringGroup->setEnabled( false );
103-
mScalingGroup->setEnabled( false );
10485
mOutputGroup->setEnabled( false );
10586
}
10687
}
@@ -137,39 +118,10 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
137118
{
138119
atlasMap->setCoverageLayer( vectorLayer );
139120
updateAtlasFeatures();
140-
checkLayerType( vectorLayer );
141121
}
142122
}
143123
}
144124

145-
void QgsAtlasCompositionWidget::onComposerMapAdded( QgsComposerMap* map )
146-
{
147-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
148-
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), qVariantFromValue(( void* )map ) );
149-
if ( mComposerMapComboBox->count() == 1 )
150-
{
151-
atlasMap->setComposerMap( map );
152-
}
153-
}
154-
155-
void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item )
156-
{
157-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
158-
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
159-
if ( map )
160-
{
161-
int idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )map ) );
162-
if ( idx != -1 )
163-
{
164-
mComposerMapComboBox->removeItem( idx );
165-
}
166-
}
167-
if ( mComposerMapComboBox->count() == 0 )
168-
{
169-
atlasMap->setComposerMap( 0 );
170-
}
171-
}
172-
173125
void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
174126
{
175127
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -190,7 +142,6 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
190142

191143
if ( layer )
192144
{
193-
checkLayerType( layer );
194145
atlasMap->setCoverageLayer( layer );
195146
updateAtlasFeatures();
196147
}
@@ -200,44 +151,6 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
200151
}
201152
}
202153

203-
void QgsAtlasCompositionWidget::checkLayerType( QgsVectorLayer *layer )
204-
{
205-
// enable or disable fixed scale control based on layer type
206-
if ( !layer ) return;
207-
switch ( layer->wkbType() )
208-
{
209-
case QGis::WKBPoint:
210-
case QGis::WKBPoint25D:
211-
case QGis::WKBMultiPoint:
212-
case QGis::WKBMultiPoint25D:
213-
//For point layers buffer setting makes no sense, so set "fixed scale" on and disable margin control
214-
mAtlasFixedScaleRadio->setChecked( true );
215-
mAtlasMarginRadio->setEnabled( false );
216-
break;
217-
default:
218-
//Not a point layer, so enable changes to fixed scale control
219-
mAtlasMarginRadio->setEnabled( true );
220-
}
221-
}
222-
223-
void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
224-
{
225-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
226-
if ( !atlasMap )
227-
{
228-
return;
229-
}
230-
if ( index == -1 )
231-
{
232-
atlasMap->setComposerMap( 0 );
233-
}
234-
else
235-
{
236-
QgsComposerMap* map = reinterpret_cast<QgsComposerMap*>( mComposerMapComboBox->itemData( index ).value<void*>() );
237-
atlasMap->setComposerMap( map );
238-
}
239-
}
240-
241154
void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
242155
{
243156
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -280,22 +193,6 @@ void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int
280193
atlasMap->setHideCoverage( state == Qt::Checked );
281194
}
282195

283-
void QgsAtlasCompositionWidget::on_mAtlasFixedScaleRadio_toggled( bool checked )
284-
{
285-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
286-
if ( !atlasMap )
287-
{
288-
return;
289-
}
290-
atlasMap->setFixedScale( checked );
291-
}
292-
293-
void QgsAtlasCompositionWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
294-
{
295-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
296-
atlasMap->setMargin( value / 100. );
297-
}
298-
299196
void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
300197
{
301198
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -487,26 +384,9 @@ void QgsAtlasCompositionWidget::updateGuiElements()
487384
if ( idx != -1 )
488385
{
489386
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
490-
checkLayerType( atlasMap->coverageLayer() );
491-
}
492-
idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )atlasMap->composerMap() ) );
493-
if ( idx != -1 )
494-
{
495-
mComposerMapComboBox->setCurrentIndex( idx );
496387
}
497388

498-
mAtlasMarginSpinBox->setValue( static_cast<int>( atlasMap->margin() * 100 ) );
499389
mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
500-
if ( atlasMap->fixedScale() )
501-
{
502-
mAtlasFixedScaleRadio->setChecked( true );
503-
mAtlasMarginSpinBox->setEnabled( false );
504-
}
505-
else
506-
{
507-
mAtlasMarginRadio->setChecked( true );
508-
mAtlasMarginSpinBox->setEnabled( true );
509-
}
510390
mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
511391
mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
512392
mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );
@@ -523,6 +403,5 @@ void QgsAtlasCompositionWidget::blockAllSignals( bool b )
523403
mVisibilityGroup->blockSignals( b );
524404
mSortingGroup->blockSignals( b );
525405
mFilteringGroup->blockSignals( b );
526-
mScalingGroup->blockSignals( b );
527406
mOutputGroup->blockSignals( b );
528407
}

‎src/app/composer/qgsatlascompositionwidget.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ class QgsAtlasCompositionWidget:
3636

3737
public slots:
3838
void on_mUseAtlasCheckBox_stateChanged( int state );
39-
void on_mComposerMapComboBox_currentIndexChanged( int index );
4039
void on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index );
4140
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
4241
void on_mAtlasFilenameExpressionButton_clicked();
4342
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
44-
void on_mAtlasFixedScaleRadio_toggled( bool checked );
4543
void on_mAtlasSingleFileCheckBox_stateChanged( int state );
4644

4745
void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
@@ -50,15 +48,12 @@ class QgsAtlasCompositionWidget:
5048
void on_mAtlasFeatureFilterEdit_editingFinished();
5149
void on_mAtlasFeatureFilterButton_clicked();
5250
void on_mAtlasFeatureFilterCheckBox_stateChanged( int state );
53-
void on_mAtlasMarginSpinBox_valueChanged( int value );
5451

5552
// extract fields from the current coverage layer and populate the corresponding combo box
5653
void fillSortColumns();
5754
private slots:
5855
void onLayerRemoved( QString );
5956
void onLayerAdded( QgsMapLayer* );
60-
void onComposerMapAdded( QgsComposerMap* );
61-
void onItemRemoved( QgsComposerItem* );
6257

6358
void updateGuiElements();
6459

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,21 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
9090
connect( mGridCheckBox, SIGNAL( toggled( bool ) ),
9191
mDrawAnnotationCheckableGroupBox, SLOT( setEnabled( bool ) ) );
9292

93+
connect( mAtlasCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( atlasToggled( bool ) ) );
94+
9395
if ( composerMap )
9496
{
9597
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
98+
99+
//get composition
100+
QgsComposition* composition = mComposerMap->composition();
101+
if ( composition )
102+
{
103+
QgsAtlasComposition* atlas = &composition->atlasComposition();
104+
connect( atlas, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ),
105+
this, SLOT( atlasLayerChanged( QgsVectorLayer* ) ) );
106+
connect( atlas, SIGNAL( toggled( bool ) ), this, SLOT( compositionAtlasToggled( bool ) ) );
107+
}
96108
}
97109

98110
updateOverviewSymbolMarker();
@@ -106,6 +118,111 @@ QgsComposerMapWidget::~QgsComposerMapWidget()
106118
{
107119
}
108120

121+
void QgsComposerMapWidget::compositionAtlasToggled( bool atlasEnabled )
122+
{
123+
if ( atlasEnabled )
124+
{
125+
mAtlasCheckBox->setEnabled( true );
126+
}
127+
else
128+
{
129+
mAtlasCheckBox->setEnabled( false );
130+
mAtlasCheckBox->setChecked( false );
131+
}
132+
}
133+
134+
void QgsComposerMapWidget::atlasToggled( bool checked )
135+
{
136+
if ( checked && mComposerMap )
137+
{
138+
//check atlas coverage layer type
139+
QgsComposition* composition = mComposerMap->composition();
140+
if ( composition )
141+
{
142+
toggleAtlasMarginByLayerType();
143+
}
144+
else
145+
{
146+
mAtlasMarginRadio->setEnabled( false );
147+
}
148+
}
149+
else
150+
{
151+
mAtlasMarginRadio->setEnabled( false );
152+
}
153+
154+
mAtlasFixedScaleRadio->setEnabled( checked );
155+
if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
156+
{
157+
mAtlasMarginSpinBox->setEnabled( true );
158+
}
159+
else
160+
{
161+
mAtlasMarginSpinBox->setEnabled( false );
162+
}
163+
}
164+
165+
166+
void QgsComposerMapWidget::on_mAtlasCheckBox_toggled( bool checked )
167+
{
168+
if ( !mComposerMap )
169+
{
170+
return;
171+
}
172+
173+
mComposerMap->setAtlasDriven( checked );
174+
updateMapForAtlas();
175+
}
176+
177+
void QgsComposerMapWidget::updateMapForAtlas()
178+
{
179+
//update map if in atlas preview mode
180+
QgsComposition* composition = mComposerMap->composition();
181+
if ( !composition )
182+
{
183+
return;
184+
}
185+
if ( composition->atlasMode() == QgsComposition::AtlasOff )
186+
{
187+
return;
188+
}
189+
190+
//update atlas based extent for map
191+
QgsAtlasComposition* atlas = &composition->atlasComposition();
192+
atlas->prepareMap( mComposerMap );
193+
194+
//redraw map
195+
mComposerMap->cache();
196+
mComposerMap->update();
197+
}
198+
199+
void QgsComposerMapWidget::on_mAtlasMarginRadio_toggled( bool checked )
200+
{
201+
mAtlasMarginSpinBox->setEnabled( checked );
202+
}
203+
204+
void QgsComposerMapWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
205+
{
206+
if ( !mComposerMap )
207+
{
208+
return;
209+
}
210+
211+
mComposerMap->setAtlasMargin( value / 100. );
212+
updateMapForAtlas();
213+
}
214+
215+
void QgsComposerMapWidget::on_mAtlasFixedScaleRadio_toggled( bool checked )
216+
{
217+
if ( !mComposerMap )
218+
{
219+
return;
220+
}
221+
222+
mComposerMap->setAtlasFixedScale( checked );
223+
updateMapForAtlas();
224+
}
225+
109226
void QgsComposerMapWidget::on_mPreviewModeComboBox_activated( int i )
110227
{
111228
Q_UNUSED( i );
@@ -402,10 +519,73 @@ void QgsComposerMapWidget::updateGuiElements()
402519

403520
mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );
404521

522+
//atlas controls
523+
mAtlasCheckBox->setChecked( mComposerMap->atlasDriven() );
524+
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin() * 100 ) );
525+
if ( mComposerMap->atlasFixedScale() )
526+
{
527+
mAtlasFixedScaleRadio->setChecked( true );
528+
mAtlasMarginSpinBox->setEnabled( false );
529+
}
530+
else
531+
{
532+
mAtlasMarginRadio->setChecked( true );
533+
mAtlasMarginSpinBox->setEnabled( true );
534+
}
535+
if ( !mComposerMap->atlasDriven() )
536+
{
537+
mAtlasMarginSpinBox->setEnabled( false );
538+
mAtlasMarginRadio->setEnabled( false );
539+
mAtlasFixedScaleRadio->setEnabled( false );
540+
}
541+
else
542+
{
543+
mAtlasFixedScaleRadio->setEnabled( true );
544+
toggleAtlasMarginByLayerType();
545+
}
546+
405547
blockAllSignals( false );
406548
}
407549
}
408550

551+
void QgsComposerMapWidget::toggleAtlasMarginByLayerType()
552+
{
553+
if ( !mComposerMap )
554+
{
555+
return;
556+
}
557+
558+
//get composition
559+
QgsComposition* composition = mComposerMap->composition();
560+
if ( !composition )
561+
{
562+
return;
563+
}
564+
565+
QgsAtlasComposition* atlas = &composition->atlasComposition();
566+
567+
QgsVectorLayer* coverageLayer = atlas->coverageLayer();
568+
if ( !coverageLayer )
569+
{
570+
return;
571+
}
572+
573+
switch ( atlas->coverageLayer()->wkbType() )
574+
{
575+
case QGis::WKBPoint:
576+
case QGis::WKBPoint25D:
577+
case QGis::WKBMultiPoint:
578+
case QGis::WKBMultiPoint25D:
579+
//For point layers buffer setting makes no sense, so set "fixed scale" on and disable margin control
580+
mAtlasFixedScaleRadio->setChecked( true );
581+
mAtlasMarginRadio->setEnabled( false );
582+
break;
583+
default:
584+
//Not a point layer, so enable changes to fixed scale control
585+
mAtlasMarginRadio->setEnabled( true );
586+
}
587+
}
588+
409589
void QgsComposerMapWidget::updateComposerExtentFromGui()
410590
{
411591
if ( !mComposerMap )
@@ -480,6 +660,10 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
480660
mOverviewBlendModeComboBox->blockSignals( b );
481661
mOverviewInvertCheckbox->blockSignals( b );
482662
mOverviewCenterCheckbox->blockSignals( b );
663+
mAtlasCheckBox->blockSignals( b );
664+
mAtlasMarginSpinBox->blockSignals( b );
665+
mAtlasFixedScaleRadio->blockSignals( b );
666+
mAtlasMarginRadio->blockSignals( b );
483667
}
484668

485669
void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -1173,3 +1357,14 @@ void QgsComposerMapWidget::refreshMapComboBox()
11731357

11741358
mOverviewFrameMapComboBox->blockSignals( false );
11751359
}
1360+
1361+
void QgsComposerMapWidget::atlasLayerChanged( QgsVectorLayer* layer )
1362+
{
1363+
// enable or disable fixed scale control based on layer type
1364+
if ( !layer || !mAtlasCheckBox->isChecked() )
1365+
{
1366+
return;
1367+
}
1368+
1369+
toggleAtlasMarginByLayerType();
1370+
}

‎src/app/composer/qgscomposermapwidget.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
9090
void on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor );
9191
void on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor );
9292

93+
void atlasToggled( bool checked );
94+
void on_mAtlasMarginRadio_toggled( bool checked );
95+
96+
void on_mAtlasCheckBox_toggled( bool checked );
97+
void on_mAtlasMarginSpinBox_valueChanged( int value );
98+
void on_mAtlasFixedScaleRadio_toggled( bool checked );
99+
93100
protected:
94101
void showEvent( QShowEvent * event );
95102

@@ -103,6 +110,12 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
103110
/**Sets the GUI elements to the values of mPicture*/
104111
void setGuiElementValues();
105112

113+
/**Enables or disables the atlas margin around feature option depending on coverage layer type*/
114+
void atlasLayerChanged( QgsVectorLayer* layer );
115+
116+
/**Enables or disables the atlas controls when composer atlas is toggled on/off*/
117+
void compositionAtlasToggled( bool atlasEnabled );
118+
106119
private:
107120
QgsComposerMap* mComposerMap;
108121

@@ -129,6 +142,13 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
129142

130143
/**Enables/disables grid frame related controls*/
131144
void toggleFrameControls( bool frameEnabled );
145+
146+
/**Enables or disables the atlas margin radio depending on the atlas coverage layer type*/
147+
void toggleAtlasMarginByLayerType();
148+
149+
/**Recalculates the bounds for an atlas map when atlas properties change*/
150+
void updateMapForAtlas();
151+
132152
};
133153

134154
#endif

‎src/core/composer/qgsatlascomposition.cpp

Lines changed: 215 additions & 73 deletions
Large diffs are not rendered by default.

‎src/core/composer/qgsatlascomposition.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,35 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
4545
bool enabled() const { return mEnabled; }
4646
void setEnabled( bool e );
4747

48-
QgsComposerMap* composerMap() const { return mComposerMap; }
49-
void setComposerMap( QgsComposerMap* map ) { mComposerMap = map; }
48+
/**Returns the map used by the atlas
49+
* @deprecated Use QgsComposerMap::atlasDriven() instead
50+
*/
51+
QgsComposerMap* composerMap() const;
52+
/**Sets the map used by the atlas
53+
* @deprecated Use QgsComposerMap::setAtlasDriven( true ) instead
54+
*/
55+
void setComposerMap( QgsComposerMap* map );
5056

5157
bool hideCoverage() const { return mHideCoverage; }
5258
void setHideCoverage( bool hide );
5359

54-
bool fixedScale() const { return mFixedScale; }
55-
void setFixedScale( bool fixed ) { mFixedScale = fixed; }
56-
57-
float margin() const { return mMargin; }
58-
void setMargin( float margin ) { mMargin = margin; }
60+
/**Returns whether the atlas map uses a fixed scale
61+
* @deprecated Use QgsComposerMap::atlasFixedScale() instead
62+
*/
63+
bool fixedScale() const;
64+
/**Sets whether the atlas map should use a fixed scale
65+
* @deprecated Use QgsComposerMap::setAtlasFixedScale( bool ) instead
66+
*/
67+
void setFixedScale( bool fixed );
68+
69+
/**Returns the margin for the atlas map
70+
* @deprecated Use QgsComposerMap::atlasMargin() instead
71+
*/
72+
float margin() const;
73+
/**Sets the margin for the atlas map
74+
* @deprecated Use QgsComposerMap::setAtlasMargin( double ) instead
75+
*/
76+
void setMargin( float margin );
5977

6078
QString filenamePattern() const { return mFilenamePattern; }
6179
void setFilenamePattern( const QString& pattern );
@@ -113,6 +131,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
113131
/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
114132
QgsFeature* currentFeature() { return &mCurrentFeature; }
115133

134+
/** Recalculates the bounds of an atlas driven map */
135+
void prepareMap( QgsComposerMap* map );
136+
116137
signals:
117138
/** emitted when one of the parameters changes */
118139
void parameterChanged();
@@ -123,6 +144,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
123144
/**Is emitted when the atlas has an updated status bar message for the composer window*/
124145
void statusMsgChanged( QString message );
125146

147+
/**Is emitted when the coverage layer for an atlas changes*/
148+
void coverageLayerChanged( QgsVectorLayer* layer );
149+
126150
private:
127151
/**Updates the filename expression*/
128152
void updateFilenameExpression();
@@ -133,10 +157,7 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
133157
QgsComposition* mComposition;
134158

135159
bool mEnabled;
136-
QgsComposerMap* mComposerMap;
137160
bool mHideCoverage;
138-
bool mFixedScale;
139-
double mMargin;
140161
QString mFilenamePattern;
141162
QgsVectorLayer* mCoverageLayer;
142163
bool mSingleFile;
@@ -170,6 +191,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
170191
QgsFeature mCurrentFeature;
171192
bool mRestoreLayer;
172193
std::auto_ptr<QgsExpression> mFilenameExpr;
194+
195+
// bounding box of the current feature transformed into map crs
196+
QgsRectangle mTransformedFeatureBounds;
197+
198+
//forces all atlas enabled maps to redraw
199+
void updateAtlasMaps();
173200
};
174201

175202
#endif

‎src/core/composer/qgscomposermap.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
5151
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
5252
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
5353
mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
54-
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
54+
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
5555
{
5656
mComposition = composition;
5757
mOverviewFrameMapSymbol = 0;
@@ -106,7 +106,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
106106
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
107107
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ),
108108
mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
109-
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
109+
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
110110
{
111111
mOverviewFrameMapSymbol = 0;
112112
mGridLineSymbol = 0;
@@ -651,10 +651,7 @@ void QgsComposerMap::toggleAtlasPreview()
651651
QgsRectangle* QgsComposerMap::currentMapExtent()
652652
{
653653
//non-const version
654-
655-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
656-
657-
if ( atlasMap->composerMap() == this && mComposition->atlasMode() != QgsComposition::AtlasOff )
654+
if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
658655
{
659656
//if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
660657
//return the current temporary atlas feature extent
@@ -670,9 +667,7 @@ QgsRectangle* QgsComposerMap::currentMapExtent()
670667
const QgsRectangle* QgsComposerMap::currentMapExtent() const
671668
{
672669
//const version
673-
674-
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
675-
if ( atlasMap->composerMap() == this && mComposition->atlasMode() != QgsComposition::AtlasOff )
670+
if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
676671
{
677672
//if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
678673
//return the current temporary atlas feature extent
@@ -991,6 +986,13 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
991986
gridElem.appendChild( annotationElem );
992987
composerMapElem.appendChild( gridElem );
993988

989+
//atlas
990+
QDomElement atlasElem = doc.createElement( "AtlasMap" );
991+
atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
992+
atlasElem.setAttribute( "fixedScale", mAtlasFixedScale );
993+
atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
994+
composerMapElem.appendChild( atlasElem );
995+
994996
elem.appendChild( composerMapElem );
995997
return _writeXML( composerMapElem, doc );
996998
}
@@ -1233,6 +1235,16 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
12331235
}
12341236
}
12351237

1238+
//atlas
1239+
QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
1240+
if ( atlasNodeList.size() > 0 )
1241+
{
1242+
QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1243+
mAtlasDriven = ( atlasElem.attribute( "atlasDriven", "0" ) != "0" );
1244+
mAtlasFixedScale = ( atlasElem.attribute( "fixedScale", "0" ) != "0" );
1245+
mAtlasMargin = atlasElem.attribute( "margin", "0.1" ).toDouble();
1246+
}
1247+
12361248
//restore general composer item properties
12371249
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
12381250
if ( composerItemList.size() > 0 )

‎src/core/composer/qgscomposermap.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,21 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
420420
*/
421421
void sizeChangedByRotation( double& width, double& height );
422422

423+
/** Returns true if the map extent is set to follow the current atlas feature */
424+
bool atlasDriven() const { return mAtlasDriven; }
425+
/** Set to true if the map extents should be set by the current atlas feature */
426+
void setAtlasDriven( bool enabled ) { mAtlasDriven = enabled; }
427+
428+
/** Returns true if the map uses a fixed scale when in atlas mode */
429+
bool atlasFixedScale() const { return mAtlasFixedScale; }
430+
/** Set to true if the map should use a fixed scale when in atlas mode */
431+
void setAtlasFixedScale( bool fixed ) { mAtlasFixedScale = fixed; }
432+
433+
/** Returns the margin size (percentage) used when the map is in atlas mode */
434+
double atlasMargin() const { return mAtlasMargin; }
435+
/** Sets the margin size (percentage) used when the map is in atlas mode */
436+
void setAtlasMargin( double margin ) { mAtlasMargin = margin; }
437+
423438
signals:
424439
void extentChanged();
425440

@@ -571,6 +586,13 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
571586
* center of extent remains the same */
572587
void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const;
573588

589+
/**True if map is being controlled by an atlas*/
590+
bool mAtlasDriven;
591+
/**True if map uses a fixed scale when controlled by an atlas*/
592+
bool mAtlasFixedScale;
593+
/**Margin size for atlas driven extents (percentage of feature size)*/
594+
double mAtlasMargin;
595+
574596
/**Draws the map grid*/
575597
void drawGrid( QPainter* p );
576598
void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );

‎src/core/composer/qgscomposition.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,9 +2347,16 @@ bool QgsComposition::setAtlasMode( QgsComposition::AtlasMode mode )
23472347
}
23482348
}
23492349

2350-
if ( mAtlasComposition.composerMap() )
2350+
QList<QgsComposerMap*> maps;
2351+
composerItems( maps );
2352+
for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
23512353
{
2352-
mAtlasComposition.composerMap()->toggleAtlasPreview();
2354+
QgsComposerMap* currentMap = ( *mit );
2355+
if ( !currentMap->atlasDriven() )
2356+
{
2357+
continue;
2358+
}
2359+
currentMap->toggleAtlasPreview();
23532360
}
23542361

23552362
update();

‎src/ui/qgsatlascompositionwidgetbase.ui

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@
2323
<property name="spacing">
2424
<number>0</number>
2525
</property>
26-
<property name="margin">
26+
<property name="leftMargin">
27+
<number>0</number>
28+
</property>
29+
<property name="topMargin">
30+
<number>0</number>
31+
</property>
32+
<property name="rightMargin">
33+
<number>0</number>
34+
</property>
35+
<property name="bottomMargin">
2736
<number>0</number>
2837
</property>
2938
<item>
@@ -32,15 +41,24 @@
3241
<enum>QFrame::StyledPanel</enum>
3342
</property>
3443
<layout class="QGridLayout" name="gridLayout">
44+
<property name="leftMargin">
45+
<number>0</number>
46+
</property>
47+
<property name="topMargin">
48+
<number>0</number>
49+
</property>
50+
<property name="rightMargin">
51+
<number>0</number>
52+
</property>
53+
<property name="bottomMargin">
54+
<number>0</number>
55+
</property>
3556
<property name="horizontalSpacing">
3657
<number>0</number>
3758
</property>
3859
<property name="verticalSpacing">
3960
<number>3</number>
4061
</property>
41-
<property name="margin">
42-
<number>0</number>
43-
</property>
4462
<item row="0" column="1">
4563
<widget class="QCheckBox" name="mUseAtlasCheckBox">
4664
<property name="text">
@@ -91,7 +109,7 @@
91109
<x>0</x>
92110
<y>0</y>
93111
<width>431</width>
94-
<height>568</height>
112+
<height>567</height>
95113
</rect>
96114
</property>
97115
<layout class="QVBoxLayout" name="mainLayout">
@@ -123,27 +141,13 @@
123141
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
124142
</property>
125143
<item row="0" column="0">
126-
<widget class="QLabel" name="mVerticalAlignementLabel">
127-
<property name="text">
128-
<string>Composer map</string>
129-
</property>
130-
</widget>
131-
</item>
132-
<item row="0" column="1">
133-
<layout class="QHBoxLayout" name="horizontalLayout_6">
134-
<item>
135-
<widget class="QComboBox" name="mComposerMapComboBox"/>
136-
</item>
137-
</layout>
138-
</item>
139-
<item row="1" column="0">
140144
<widget class="QLabel" name="mHorizontalAlignementLabel">
141145
<property name="text">
142146
<string>Coverage layer</string>
143147
</property>
144148
</widget>
145149
</item>
146-
<item row="1" column="1">
150+
<item row="0" column="1">
147151
<layout class="QHBoxLayout" name="horizontalLayout_5">
148152
<item>
149153
<widget class="QComboBox" name="mAtlasCoverageLayerComboBox"/>
@@ -280,60 +284,6 @@
280284
</layout>
281285
</widget>
282286
</item>
283-
<item>
284-
<widget class="QgsCollapsibleGroupBoxBasic" name="mScalingGroup">
285-
<property name="enabled">
286-
<bool>false</bool>
287-
</property>
288-
<property name="title">
289-
<string>Scaling</string>
290-
</property>
291-
<property name="checkable">
292-
<bool>false</bool>
293-
</property>
294-
<property name="syncGroup" stdset="0">
295-
<string notr="true">composeritem</string>
296-
</property>
297-
<property name="collapsed" stdset="0">
298-
<bool>false</bool>
299-
</property>
300-
<layout class="QGridLayout" name="gridLayout_2">
301-
<item row="0" column="0">
302-
<widget class="QRadioButton" name="mAtlasMarginRadio">
303-
<property name="text">
304-
<string>Margin around feature</string>
305-
</property>
306-
</widget>
307-
</item>
308-
<item row="0" column="1">
309-
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
310-
<property name="sizePolicy">
311-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
312-
<horstretch>0</horstretch>
313-
<verstretch>0</verstretch>
314-
</sizepolicy>
315-
</property>
316-
<property name="suffix">
317-
<string>%</string>
318-
</property>
319-
<property name="maximum">
320-
<number>100</number>
321-
</property>
322-
<property name="value">
323-
<number>10</number>
324-
</property>
325-
</widget>
326-
</item>
327-
<item row="1" column="0">
328-
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
329-
<property name="text">
330-
<string>Fixed scale</string>
331-
</property>
332-
</widget>
333-
</item>
334-
</layout>
335-
</widget>
336-
</item>
337287
<item>
338288
<widget class="QgsCollapsibleGroupBoxBasic" name="mOutputGroup">
339289
<property name="enabled">

‎src/ui/qgscomposermapwidgetbase.ui

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@
2323
<property name="spacing">
2424
<number>0</number>
2525
</property>
26-
<property name="margin">
26+
<property name="leftMargin">
27+
<number>0</number>
28+
</property>
29+
<property name="topMargin">
30+
<number>0</number>
31+
</property>
32+
<property name="rightMargin">
33+
<number>0</number>
34+
</property>
35+
<property name="bottomMargin">
2736
<number>0</number>
2837
</property>
2938
<item>
@@ -54,9 +63,9 @@
5463
<property name="geometry">
5564
<rect>
5665
<x>0</x>
57-
<y>-420</y>
66+
<y>0</y>
5867
<width>439</width>
59-
<height>1509</height>
68+
<height>1638</height>
6069
</rect>
6170
</property>
6271
<property name="sizePolicy">
@@ -251,6 +260,66 @@
251260
</layout>
252261
</widget>
253262
</item>
263+
<item>
264+
<widget class="QgsCollapsibleGroupBoxBasic" name="mAtlasCheckBox">
265+
<property name="title">
266+
<string>Controlled by atlas</string>
267+
</property>
268+
<property name="checkable">
269+
<bool>true</bool>
270+
</property>
271+
<property name="checked">
272+
<bool>false</bool>
273+
</property>
274+
<property name="collapsed" stdset="0">
275+
<bool>true</bool>
276+
</property>
277+
<layout class="QGridLayout" name="gridLayout_2">
278+
<item row="0" column="0">
279+
<widget class="QRadioButton" name="mAtlasMarginRadio">
280+
<property name="enabled">
281+
<bool>false</bool>
282+
</property>
283+
<property name="text">
284+
<string>Margin around feature</string>
285+
</property>
286+
</widget>
287+
</item>
288+
<item row="0" column="1">
289+
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
290+
<property name="enabled">
291+
<bool>false</bool>
292+
</property>
293+
<property name="sizePolicy">
294+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
295+
<horstretch>0</horstretch>
296+
<verstretch>0</verstretch>
297+
</sizepolicy>
298+
</property>
299+
<property name="suffix">
300+
<string>%</string>
301+
</property>
302+
<property name="maximum">
303+
<number>9999</number>
304+
</property>
305+
<property name="value">
306+
<number>10</number>
307+
</property>
308+
</widget>
309+
</item>
310+
<item row="1" column="0">
311+
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
312+
<property name="enabled">
313+
<bool>false</bool>
314+
</property>
315+
<property name="text">
316+
<string>Fixed scale</string>
317+
</property>
318+
</widget>
319+
</item>
320+
</layout>
321+
</widget>
322+
</item>
254323
<item>
255324
<widget class="QgsCollapsibleGroupBoxBasic" name="mGridCheckBox">
256325
<property name="title">

‎tests/src/core/qgscompositionchecker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ QgsCompositionChecker::~QgsCompositionChecker()
3636
{
3737
}
3838

39-
bool QgsCompositionChecker::testComposition( QString &report, int page )
39+
bool QgsCompositionChecker::testComposition( QString &report, int page, int pixelDiff )
4040
{
4141
if ( !mComposition )
4242
{
@@ -82,7 +82,7 @@ bool QgsCompositionChecker::testComposition( QString &report, int page )
8282

8383
QString diffFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_result_diff.png";
8484

85-
bool testResult = compareImages( mTestName, 0, renderedFilePath );
85+
bool testResult = compareImages( mTestName, pixelDiff, renderedFilePath );
8686

8787
QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + mTestName + "\""
8888
" type=\"image/png\">" + renderedFilePath +

‎tests/src/core/qgscompositionchecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class QgsCompositionChecker : public QgsRenderChecker
2929
QgsCompositionChecker( const QString& testName, QgsComposition* composition );
3030
~QgsCompositionChecker();
3131

32-
bool testComposition( QString &report, int page = 0 );
32+
bool testComposition( QString &report, int page = 0, int pixelDiff = 0 );
3333

3434
private:
3535
QgsCompositionChecker(); //forbidden

‎tests/src/core/testqgsatlascomposition.cpp

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ class TestQgsAtlasComposition: public QObject
4343
void filename();
4444
// test rendering with an autoscale atlas
4545
void autoscale_render();
46+
// test rendering with an autoscale atlas using the old api
47+
void autoscale_render_2_0_api();
4648
// test rendering with a fixed scale atlas
4749
void fixedscale_render();
50+
// test rendering with a fixed scale atlas using the old api
51+
void fixedscale_render_2_0_api();
52+
// test rendering with two atlas-driven maps
53+
void two_map_autoscale_render();
4854
// test rendering with a hidden coverage
4955
void hiding_render();
5056
// test rendering with feature sorting
@@ -104,7 +110,6 @@ void TestQgsAtlasComposition::initTestCase()
104110

105111
mAtlas = &mComposition->atlasComposition();
106112
mAtlas->setCoverageLayer( mVectorLayer );
107-
mAtlas->setComposerMap( mAtlasMap );
108113
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
109114

110115
// an overview
@@ -180,6 +185,29 @@ void TestQgsAtlasComposition::filename()
180185

181186
void TestQgsAtlasComposition::autoscale_render()
182187
{
188+
mAtlasMap->setAtlasDriven( true );
189+
mAtlasMap->setAtlasFixedScale( false );
190+
mAtlasMap->setAtlasMargin( 0.10 );
191+
192+
mAtlas->beginRender();
193+
194+
for ( int fit = 0; fit < 2; ++fit )
195+
{
196+
mAtlas->prepareForFeature( fit );
197+
mLabel1->adjustSizeToText();
198+
199+
QgsCompositionChecker checker( QString( "atlas_autoscale%1" ).arg((( int )fit ) + 1 ), mComposition );
200+
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
201+
}
202+
mAtlas->endRender();
203+
mAtlasMap->setAtlasDriven( false );
204+
mAtlasMap->setAtlasFixedScale( false );
205+
mAtlasMap->setAtlasMargin( 0 );
206+
}
207+
208+
void TestQgsAtlasComposition::autoscale_render_2_0_api()
209+
{
210+
mAtlas->setComposerMap( mAtlasMap );
183211
mAtlas->setFixedScale( false );
184212
mAtlas->setMargin( 0.10f );
185213

@@ -190,16 +218,20 @@ void TestQgsAtlasComposition::autoscale_render()
190218
mAtlas->prepareForFeature( fit );
191219
mLabel1->adjustSizeToText();
192220

193-
QgsCompositionChecker checker( QString( "atlas_autoscale%1" ).arg((( int )fit ) + 1 ), mComposition );
221+
QgsCompositionChecker checker( QString( "atlas_autoscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
194222
QVERIFY( checker.testComposition( mReport, 0 ) );
195223
}
196224
mAtlas->endRender();
225+
mAtlas->setComposerMap( 0 );
226+
mAtlas->setFixedScale( false );
227+
mAtlas->setMargin( 0 );
197228
}
198229

199230
void TestQgsAtlasComposition::fixedscale_render()
200231
{
232+
mAtlasMap->setAtlasDriven( true );
201233
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
202-
mAtlas->setFixedScale( true );
234+
mAtlasMap->setAtlasFixedScale( true );
203235

204236
mAtlas->beginRender();
205237

@@ -213,12 +245,61 @@ void TestQgsAtlasComposition::fixedscale_render()
213245
}
214246
mAtlas->endRender();
215247

248+
mAtlasMap->setAtlasDriven( false );
249+
mAtlasMap->setAtlasFixedScale( false );
216250
}
217251

218-
void TestQgsAtlasComposition::hiding_render()
252+
void TestQgsAtlasComposition::fixedscale_render_2_0_api()
219253
{
220254
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
255+
mAtlas->setComposerMap( mAtlasMap );
221256
mAtlas->setFixedScale( true );
257+
mAtlas->beginRender();
258+
259+
for ( int fit = 0; fit < 2; ++fit )
260+
{
261+
mAtlas->prepareForFeature( fit );
262+
mLabel1->adjustSizeToText();
263+
264+
QgsCompositionChecker checker( QString( "atlas_fixedscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
265+
QVERIFY( checker.testComposition( mReport, 0 ) );
266+
}
267+
mAtlas->endRender();
268+
mAtlas->setComposerMap( 0 );
269+
mAtlas->setFixedScale( false );
270+
}
271+
272+
void TestQgsAtlasComposition::two_map_autoscale_render()
273+
{
274+
mAtlasMap->setAtlasDriven( true );
275+
mAtlasMap->setAtlasFixedScale( false );
276+
mAtlasMap->setAtlasMargin( 0.10 );
277+
mOverview->setAtlasDriven( true );
278+
mOverview->setAtlasFixedScale( false );
279+
mOverview->setAtlasMargin( 2.0 );
280+
281+
mAtlas->beginRender();
282+
283+
for ( int fit = 0; fit < 2; ++fit )
284+
{
285+
mAtlas->prepareForFeature( fit );
286+
mLabel1->adjustSizeToText();
287+
288+
QgsCompositionChecker checker( QString( "atlas_two_maps%1" ).arg((( int )fit ) + 1 ), mComposition );
289+
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
290+
}
291+
mAtlas->endRender();
292+
mAtlasMap->setAtlasDriven( false );
293+
mAtlasMap->setAtlasFixedScale( false );
294+
mAtlasMap->setAtlasMargin( 0 );
295+
mOverview->setAtlasDriven( false );
296+
}
297+
298+
void TestQgsAtlasComposition::hiding_render()
299+
{
300+
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
301+
mAtlasMap->setAtlasDriven( true );
302+
mAtlasMap->setAtlasFixedScale( true );
222303
mAtlas->setHideCoverage( true );
223304

224305
mAtlas->beginRender();
@@ -237,7 +318,8 @@ void TestQgsAtlasComposition::hiding_render()
237318
void TestQgsAtlasComposition::sorting_render()
238319
{
239320
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
240-
mAtlas->setFixedScale( true );
321+
mAtlasMap->setAtlasDriven( true );
322+
mAtlasMap->setAtlasFixedScale( true );
241323
mAtlas->setHideCoverage( false );
242324

243325
mAtlas->setSortFeatures( true );
@@ -260,7 +342,8 @@ void TestQgsAtlasComposition::sorting_render()
260342
void TestQgsAtlasComposition::filtering_render()
261343
{
262344
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
263-
mAtlas->setFixedScale( true );
345+
mAtlasMap->setAtlasDriven( true );
346+
mAtlasMap->setAtlasFixedScale( true );
264347
mAtlas->setHideCoverage( false );
265348

266349
mAtlas->setSortFeatures( false );

‎tests/src/python/qgscompositionchecker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, mTestName, mComposition ):
2727
self.mTestName = mTestName
2828
super(QgsCompositionChecker, self).__init__()
2929

30-
def testComposition(self, page=0 ):
30+
def testComposition(self, page=0, pixelDiff=0 ):
3131
if ( self.mComposition == None):
3232
myMessage = "Composition not valid"
3333
return False, myMessage
@@ -53,7 +53,7 @@ def testComposition(self, page=0 ):
5353
outputImage.save( renderedFilePath, "PNG" )
5454

5555
diffFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_result_diff.png"
56-
testResult = self.compareImages( self.mTestName, 0, renderedFilePath )
56+
testResult = self.compareImages( self.mTestName, pixelDiff, renderedFilePath )
5757

5858
myDashMessage = (('<DartMeasurementFile name="Rendered Image '
5959
'%s" type="image/png">'

‎tests/src/python/test_qgsatlascomposition.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def testCase(self):
6363
# the atlas
6464
self.mAtlas = self.mComposition.atlasComposition()
6565
self.mAtlas.setCoverageLayer( mVectorLayer )
66-
self.mAtlas.setComposerMap( self.mAtlasMap )
6766
self.mComposition.setAtlasMode( QgsComposition.ExportAtlas )
6867

6968
# an overview
@@ -99,6 +98,7 @@ def testCase(self):
9998

10099
self.filename_test()
101100
self.autoscale_render_test()
101+
self.autoscale_render_test_old_api()
102102
self.fixedscale_render_test()
103103
self.hidden_render_test()
104104

@@ -113,6 +113,28 @@ def filename_test( self ):
113113
self.mAtlas.endRender()
114114

115115
def autoscale_render_test( self ):
116+
self.mAtlasMap.setAtlasDriven( True )
117+
self.mAtlasMap.setAtlasFixedScale( False )
118+
self.mAtlasMap.setAtlasMargin( 0.10 )
119+
120+
self.mAtlas.beginRender()
121+
122+
for i in range(0, 2):
123+
self.mAtlas.prepareForFeature( i )
124+
self.mLabel1.adjustSizeToText()
125+
126+
checker = QgsCompositionChecker('atlas_autoscale%d' % (i + 1), self.mComposition)
127+
myTestResult, myMessage = checker.testComposition(0, 10)
128+
129+
assert myTestResult == True
130+
self.mAtlas.endRender()
131+
132+
self.mAtlasMap.setAtlasDriven( False )
133+
self.mAtlasMap.setAtlasFixedScale( True )
134+
self.mAtlasMap.setAtlasMargin( 0 )
135+
136+
def autoscale_render_test_old_api( self ):
137+
self.mAtlas.setComposerMap( self.mAtlasMap )
116138
self.mAtlas.setFixedScale( False )
117139
self.mAtlas.setMargin( 0.10 )
118140

@@ -122,15 +144,20 @@ def autoscale_render_test( self ):
122144
self.mAtlas.prepareForFeature( i )
123145
self.mLabel1.adjustSizeToText()
124146

125-
checker = QgsCompositionChecker('atlas_autoscale%d' % (i + 1), self.mComposition)
147+
checker = QgsCompositionChecker('atlas_autoscale_old_api%d' % (i + 1), self.mComposition)
126148
myTestResult, myMessage = checker.testComposition()
127149

128150
assert myTestResult == True
129151
self.mAtlas.endRender()
130152

153+
self.mAtlas.setFixedScale( True )
154+
self.mAtlas.setMargin( 0 )
155+
self.mAtlas.setComposerMap( None )
156+
131157
def fixedscale_render_test( self ):
158+
self.mAtlasMap.setAtlasDriven( True )
159+
self.mAtlasMap.setAtlasFixedScale( True )
132160
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
133-
self.mAtlas.setFixedScale( True )
134161

135162
self.mAtlas.beginRender()
136163

@@ -146,7 +173,7 @@ def fixedscale_render_test( self ):
146173

147174
def hidden_render_test( self ):
148175
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
149-
self.mAtlas.setFixedScale( True )
176+
self.mAtlasMap.setAtlasFixedScale( True )
150177
self.mAtlas.setHideCoverage( True )
151178

152179
self.mAtlas.beginRender()
@@ -163,7 +190,7 @@ def hidden_render_test( self ):
163190

164191
def sorting_render_test( self ):
165192
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
166-
self.mAtlas.setFixedScale( True )
193+
self.mAtlasMap.setAtlasFixedScale( True )
167194
self.mAtlas.setHideCoverage( False )
168195

169196
self.mAtlas.setSortFeatures( True )
@@ -184,7 +211,7 @@ def sorting_render_test( self ):
184211

185212
def filtering_render_test( self ):
186213
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
187-
self.mAtlas.setFixedScale( True )
214+
self.mAtlasMap.setAtlasFixedScale( True )
188215
self.mAtlas.setHideCoverage( False )
189216

190217
self.mAtlas.setSortFeatures( False )
159 KB

Error rendering embedded code

Invalid image source.

33.5 KB
Loading
30.7 KB
Loading
194 KB
Loading
30.7 KB
Loading
169 KB
Loading
33.4 KB
Loading
33 KB
Loading
30.6 KB
Loading
186 KB
Loading
30.6 KB
Loading
161 KB
Loading
182 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.