Skip to content

Commit 6bb9dfe

Browse files
committed
[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

+33
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

+16-1
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

-121
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

-5
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

0 commit comments

Comments
 (0)