Skip to content
Permalink
Browse files

Merge pull request #1072 from nyalldawson/atlas_multimap3

[FEATURE][composer] Allow for more than one atlas controlled map in comp...
  • Loading branch information
nyalldawson committed Jan 14, 2014
2 parents 2cdc896 + 6bb9dfe commit 27f5b8d0490ae9f0ce622bf920e83271054d7175
Showing with 791 additions and 315 deletions.
  1. +33 −0 python/core/composer/qgsatlascomposition.sip
  2. +16 −1 python/core/composer/qgscomposermap.sip
  3. +0 −121 src/app/composer/qgsatlascompositionwidget.cpp
  4. +0 −5 src/app/composer/qgsatlascompositionwidget.h
  5. +195 −0 src/app/composer/qgscomposermapwidget.cpp
  6. +20 −0 src/app/composer/qgscomposermapwidget.h
  7. +215 −73 src/core/composer/qgsatlascomposition.cpp
  8. +37 −10 src/core/composer/qgsatlascomposition.h
  9. +21 −9 src/core/composer/qgscomposermap.cpp
  10. +22 −0 src/core/composer/qgscomposermap.h
  11. +9 −2 src/core/composer/qgscomposition.cpp
  12. +24 −74 src/ui/qgsatlascompositionwidgetbase.ui
  13. +72 −3 src/ui/qgscomposermapwidgetbase.ui
  14. +2 −2 tests/src/core/qgscompositionchecker.cpp
  15. +1 −1 tests/src/core/qgscompositionchecker.h
  16. +89 −6 tests/src/core/testqgsatlascomposition.cpp
  17. +2 −2 tests/src/python/qgscompositionchecker.py
  18. +33 −6 tests/src/python/test_qgsatlascomposition.py
  19. BIN ...s/testdata/control_images/expected_atlas_autoscale_old_api1/expected_atlas_autoscale_old_api1.png
  20. BIN tests/testdata/control_images/expected_atlas_autoscale_old_api1/osgeo4w_nightly.anomoly.png
  21. BIN tests/testdata/control_images/expected_atlas_autoscale_old_api1/ubuntu_13.04.anomaly.png
  22. BIN ...s/testdata/control_images/expected_atlas_autoscale_old_api2/expected_atlas_autoscale_old_api2.png
  23. BIN tests/testdata/control_images/expected_atlas_autoscale_old_api2/ubuntu_13.04.anomaly.png
  24. BIN ...testdata/control_images/expected_atlas_fixedscale_old_api1/expected_atlas_fixedscale_old_api1.png
  25. BIN tests/testdata/control_images/expected_atlas_fixedscale_old_api1/osgeo4w_nightly.anomoly.png
  26. BIN tests/testdata/control_images/expected_atlas_fixedscale_old_api1/ubuntu_12.04.anomaly.png
  27. BIN tests/testdata/control_images/expected_atlas_fixedscale_old_api1/ubuntu_13.04.anomaly.png
  28. BIN ...testdata/control_images/expected_atlas_fixedscale_old_api2/expected_atlas_fixedscale_old_api2.png
  29. BIN tests/testdata/control_images/expected_atlas_fixedscale_old_api2/ubuntu_13.04.anomaly.png
  30. BIN tests/testdata/control_images/expected_atlas_two_maps1/expected_atlas_two_maps1.png
  31. BIN tests/testdata/control_images/expected_atlas_two_maps2/expected_atlas_two_maps2.png
@@ -17,16 +17,34 @@ public:
bool enabled() const;
void setEnabled( bool e );

/**Returns the map used by the atlas
* @deprecated Use QgsComposerMap::atlasDriven() instead
*/
QgsComposerMap* composerMap() const;
/**Sets the map used by the atlas
* @deprecated Use QgsComposerMap::setAtlasDriven( true ) instead
*/
void setComposerMap( QgsComposerMap* map );

bool hideCoverage() const;
void setHideCoverage( bool hide );

/**Returns whether the atlas map uses a fixed scale
* @deprecated Use QgsComposerMap::atlasFixedScale() instead
*/
bool fixedScale() const;
/**Sets whether the atlas map should use a fixed scale
* @deprecated Use QgsComposerMap::setAtlasFixedScale( bool ) instead
*/
void setFixedScale( bool fixed );

/**Returns the margin for the atlas map
* @deprecated Use QgsComposerMap::atlasMargin() instead
*/
float margin() const;
/**Sets the margin for the atlas map
* @deprecated Use QgsComposerMap::setAtlasMargin( double ) instead
*/
void setMargin( float margin );

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

/** Returns the current filename. Must be called after prepareForFeature( i ) */
const QString& currentFilename() const;

/** Requeries the current atlas coverage layer and applies filtering and sorting. Returns
number of matching features. Must be called after prepareForFeature( i ) */
int updateFeatures();

void nextFeature();
void prevFeature();
void lastFeature();
void firstFeature();

/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature();

/** Recalculates the bounds of an atlas driven map */
void prepareMap( QgsComposerMap* map );

void writeXML( QDomElement& elem, QDomDocument& doc ) const;
void readXML( const QDomElement& elem, const QDomDocument& doc );
@@ -366,7 +366,22 @@ class QgsComposerMap : QgsComposerItem
* @deprecated Use QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
* instead
*/
void sizeChangedByRotation( double& width, double& height );
void sizeChangedByRotation( double& width, double& height );

/** Returns true if the map extent is set to follow the current atlas feature */
bool atlasDriven() const;
/** Set to true if the map extents should be set by the current atlas feature */
void setAtlasDriven( bool enabled );

/** Returns true if the map uses a fixed scale when in atlas mode */
bool atlasFixedScale() const;
/** Set to true if the map should use a fixed scale when in atlas mode */
void setAtlasFixedScale( bool fixed );

/** Returns the margin size (percentage) used when the map is in atlas mode */
double atlasMargin() const;
/** Sets the margin size (percentage) used when the map is in atlas mode */
void setAtlasMargin( double margin );

signals:
void extentChanged();
@@ -49,27 +49,10 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( onLayerAdded( QgsMapLayer* ) ) );
}

// update the composer map combo box
// populate the map list
mComposerMapComboBox->clear();
QList<const QgsComposerMap*> availableMaps = mComposition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
{
mComposerMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), qVariantFromValue(( void* )*mapItemIt ) );
}

// Sort direction
mAtlasSortFeatureDirectionButton->setEnabled( false );

mAtlasSortFeatureKeyComboBox->setEnabled( false );

// Connect to addition / removal of maps
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );

connect( mAtlasMarginRadio, SIGNAL( toggled( bool ) ), mAtlasMarginSpinBox, SLOT( setEnabled( bool ) ) );

// connect to updates
connect( &mComposition->atlasComposition(), SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) );

@@ -90,7 +73,6 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
mVisibilityGroup->setEnabled( true );
mSortingGroup->setEnabled( true );
mFilteringGroup->setEnabled( true );
mScalingGroup->setEnabled( true );
mOutputGroup->setEnabled( true );
}
else
@@ -100,7 +82,6 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
mVisibilityGroup->setEnabled( false );
mSortingGroup->setEnabled( false );
mFilteringGroup->setEnabled( false );
mScalingGroup->setEnabled( false );
mOutputGroup->setEnabled( false );
}
}
@@ -137,39 +118,10 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
{
atlasMap->setCoverageLayer( vectorLayer );
updateAtlasFeatures();
checkLayerType( vectorLayer );
}
}
}

void QgsAtlasCompositionWidget::onComposerMapAdded( QgsComposerMap* map )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), qVariantFromValue(( void* )map ) );
if ( mComposerMapComboBox->count() == 1 )
{
atlasMap->setComposerMap( map );
}
}

void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
if ( map )
{
int idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )map ) );
if ( idx != -1 )
{
mComposerMapComboBox->removeItem( idx );
}
}
if ( mComposerMapComboBox->count() == 0 )
{
atlasMap->setComposerMap( 0 );
}
}

void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -190,7 +142,6 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang

if ( layer )
{
checkLayerType( layer );
atlasMap->setCoverageLayer( layer );
updateAtlasFeatures();
}
@@ -200,44 +151,6 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
}
}

void QgsAtlasCompositionWidget::checkLayerType( QgsVectorLayer *layer )
{
// enable or disable fixed scale control based on layer type
if ( !layer ) return;
switch ( layer->wkbType() )
{
case QGis::WKBPoint:
case QGis::WKBPoint25D:
case QGis::WKBMultiPoint:
case QGis::WKBMultiPoint25D:
//For point layers buffer setting makes no sense, so set "fixed scale" on and disable margin control
mAtlasFixedScaleRadio->setChecked( true );
mAtlasMarginRadio->setEnabled( false );
break;
default:
//Not a point layer, so enable changes to fixed scale control
mAtlasMarginRadio->setEnabled( true );
}
}

void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}
if ( index == -1 )
{
atlasMap->setComposerMap( 0 );
}
else
{
QgsComposerMap* map = reinterpret_cast<QgsComposerMap*>( mComposerMapComboBox->itemData( index ).value<void*>() );
atlasMap->setComposerMap( map );
}
}

void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -280,22 +193,6 @@ void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int
atlasMap->setHideCoverage( state == Qt::Checked );
}

void QgsAtlasCompositionWidget::on_mAtlasFixedScaleRadio_toggled( bool checked )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
}
atlasMap->setFixedScale( checked );
}

void QgsAtlasCompositionWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
atlasMap->setMargin( value / 100. );
}

void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -487,26 +384,9 @@ void QgsAtlasCompositionWidget::updateGuiElements()
if ( idx != -1 )
{
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
checkLayerType( atlasMap->coverageLayer() );
}
idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )atlasMap->composerMap() ) );
if ( idx != -1 )
{
mComposerMapComboBox->setCurrentIndex( idx );
}

mAtlasMarginSpinBox->setValue( static_cast<int>( atlasMap->margin() * 100 ) );
mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
if ( atlasMap->fixedScale() )
{
mAtlasFixedScaleRadio->setChecked( true );
mAtlasMarginSpinBox->setEnabled( false );
}
else
{
mAtlasMarginRadio->setChecked( true );
mAtlasMarginSpinBox->setEnabled( true );
}
mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );
@@ -523,6 +403,5 @@ void QgsAtlasCompositionWidget::blockAllSignals( bool b )
mVisibilityGroup->blockSignals( b );
mSortingGroup->blockSignals( b );
mFilteringGroup->blockSignals( b );
mScalingGroup->blockSignals( b );
mOutputGroup->blockSignals( b );
}
@@ -36,12 +36,10 @@ class QgsAtlasCompositionWidget:

public slots:
void on_mUseAtlasCheckBox_stateChanged( int state );
void on_mComposerMapComboBox_currentIndexChanged( int index );
void on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index );
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
void on_mAtlasFilenameExpressionButton_clicked();
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
void on_mAtlasFixedScaleRadio_toggled( bool checked );
void on_mAtlasSingleFileCheckBox_stateChanged( int state );

void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
@@ -50,15 +48,12 @@ class QgsAtlasCompositionWidget:
void on_mAtlasFeatureFilterEdit_editingFinished();
void on_mAtlasFeatureFilterButton_clicked();
void on_mAtlasFeatureFilterCheckBox_stateChanged( int state );
void on_mAtlasMarginSpinBox_valueChanged( int value );

// extract fields from the current coverage layer and populate the corresponding combo box
void fillSortColumns();
private slots:
void onLayerRemoved( QString );
void onLayerAdded( QgsMapLayer* );
void onComposerMapAdded( QgsComposerMap* );
void onItemRemoved( QgsComposerItem* );

void updateGuiElements();

0 comments on commit 27f5b8d

Please sign in to comment.
You can’t perform that action at this time.