Skip to content

Commit

Permalink
[Fix 7641] Disable margin control for atlas when a point layer is sel…
Browse files Browse the repository at this point in the history
…ected

Change fixed scale control to radio button
Fix margin size not saving
  • Loading branch information
nyalldawson committed Apr 19, 2013
1 parent 3acfdc3 commit 007e237
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
54 changes: 41 additions & 13 deletions src/app/composer/qgsatlascompositionwidget.cpp
Expand Up @@ -18,7 +18,6 @@
#include "qgsatlascomposition.h"
#include "qgscomposition.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgscomposermap.h"

Expand Down Expand Up @@ -69,6 +68,8 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
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() ) );

Expand Down Expand Up @@ -135,6 +136,7 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
if ( mAtlasCoverageLayerComboBox->count() == 1 )
{
atlasMap->setCoverageLayer( vectorLayer );
checkLayerType( vectorLayer );
}
}

Expand Down Expand Up @@ -183,13 +185,34 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
else
{
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>( mAtlasCoverageLayerComboBox->itemData( index ).value<void*>() );

checkLayerType( layer );
atlasMap->setCoverageLayer( layer );

// update sorting columns
fillSortColumns();
}
}

void QgsAtlasCompositionWidget::checkLayerType( QgsVectorLayer *layer )
{
// enable or disable fixed scale control based on layer type
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();
Expand Down Expand Up @@ -250,24 +273,20 @@ void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int
atlasMap->setHideCoverage( state == Qt::Checked );
}

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

// in fixed scale mode, the margin is meaningless
if ( state == Qt::Checked )
{
mAtlasMarginSpinBox->setEnabled( false );
}
else
{
mAtlasMarginSpinBox->setEnabled( true );
}
void QgsAtlasCompositionWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
atlasMap->setMargin( value / 100. );
}

void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
Expand Down Expand Up @@ -426,6 +445,7 @@ void QgsAtlasCompositionWidget::updateGuiElements()
if ( idx != -1 )
{
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
checkLayerType( atlasMap->coverageLayer() );
}
idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )atlasMap->composerMap() ) );
if ( idx != -1 )
Expand All @@ -435,7 +455,15 @@ void QgsAtlasCompositionWidget::updateGuiElements()

mAtlasMarginSpinBox->setValue( static_cast<int>( atlasMap->margin() * 100 ) );
mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
mAtlasFixedScaleCheckBox->setCheckState( atlasMap->fixedScale() ? Qt::Checked : Qt::Unchecked );
if ( atlasMap->fixedScale() )
{
mAtlasFixedScaleRadio->setChecked( true );
mAtlasMarginSpinBox->setEnabled( false );
}
else
{
mAtlasMarginRadio->setChecked( 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 );
Expand Down
5 changes: 4 additions & 1 deletion src/app/composer/qgsatlascompositionwidget.h
Expand Up @@ -15,6 +15,7 @@
***************************************************************************/

#include "ui_qgsatlascompositionwidgetbase.h"
#include "qgsvectorlayer.h"

class QgsComposition;
class QgsMapLayer;
Expand All @@ -40,7 +41,7 @@ class QgsAtlasCompositionWidget:
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
void on_mAtlasFilenameExpressionButton_clicked();
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
void on_mAtlasFixedScaleCheckBox_stateChanged( int state );
void on_mAtlasFixedScaleRadio_toggled( bool checked );
void on_mAtlasSingleFileCheckBox_stateChanged( int state );

void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
Expand All @@ -49,6 +50,7 @@ class QgsAtlasCompositionWidget:
void on_mAtlasFeatureFilterEdit_textChanged( const QString& text );
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();
Expand All @@ -64,4 +66,5 @@ class QgsAtlasCompositionWidget:
QgsComposition* mComposition;

void blockAllSignals( bool b );
void checkLayerType( QgsVectorLayer *layer );
};
8 changes: 4 additions & 4 deletions src/ui/qgsatlascompositionwidgetbase.ui
Expand Up @@ -91,7 +91,7 @@
<x>0</x>
<y>0</y>
<width>431</width>
<height>567</height>
<height>568</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -299,7 +299,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<widget class="QRadioButton" name="mAtlasMarginRadio">
<property name="text">
<string>Margin around feature</string>
</property>
Expand All @@ -324,8 +324,8 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QCheckBox" name="mAtlasFixedScaleCheckBox">
<item row="1" column="0">
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
<property name="text">
<string>Fixed scale</string>
</property>
Expand Down

0 comments on commit 007e237

Please sign in to comment.