Skip to content
Permalink
Browse files

[Fix 7641] Disable margin control for atlas when a point layer is sel…

…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 007e237f7ae4e492eab6420234d42c0e96c57a54
@@ -18,7 +18,6 @@
#include "qgsatlascomposition.h"
#include "qgscomposition.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgscomposermap.h"

@@ -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() ) );

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

@@ -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();
@@ -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 )
@@ -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 )
@@ -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 );
@@ -15,6 +15,7 @@
***************************************************************************/

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

class QgsComposition;
class QgsMapLayer;
@@ -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 );
@@ -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();
@@ -64,4 +66,5 @@ class QgsAtlasCompositionWidget:
QgsComposition* mComposition;

void blockAllSignals( bool b );
void checkLayerType( QgsVectorLayer *layer );
};
@@ -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">
@@ -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>
@@ -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>

0 comments on commit 007e237

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