Skip to content

Commit 007e237

Browse files
committed
[Fix 7641] Disable margin control for atlas when a point layer is selected
Change fixed scale control to radio button Fix margin size not saving
1 parent 3acfdc3 commit 007e237

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

src/app/composer/qgsatlascompositionwidget.cpp

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "qgsatlascomposition.h"
1919
#include "qgscomposition.h"
2020
#include "qgsmaplayerregistry.h"
21-
#include "qgsvectorlayer.h"
2221
#include "qgsexpressionbuilderdialog.h"
2322
#include "qgscomposermap.h"
2423

@@ -69,6 +68,8 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsCompos
6968
connect( mComposition, SIGNAL( composerMapAdded( QgsComposerMap* ) ), this, SLOT( onComposerMapAdded( QgsComposerMap* ) ) );
7069
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );
7170

71+
connect( mAtlasMarginRadio, SIGNAL( toggled( bool ) ), mAtlasMarginSpinBox, SLOT( setEnabled( bool ) ) );
72+
7273
// connect to updates
7374
connect( &mComposition->atlasComposition(), SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) );
7475

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

@@ -183,13 +185,34 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
183185
else
184186
{
185187
QgsVectorLayer* layer = reinterpret_cast<QgsVectorLayer*>( mAtlasCoverageLayerComboBox->itemData( index ).value<void*>() );
188+
189+
checkLayerType( layer );
186190
atlasMap->setCoverageLayer( layer );
187191

188192
// update sorting columns
189193
fillSortColumns();
190194
}
191195
}
192196

197+
void QgsAtlasCompositionWidget::checkLayerType( QgsVectorLayer *layer )
198+
{
199+
// enable or disable fixed scale control based on layer type
200+
switch ( layer->wkbType() )
201+
{
202+
case QGis::WKBPoint:
203+
case QGis::WKBPoint25D:
204+
case QGis::WKBMultiPoint:
205+
case QGis::WKBMultiPoint25D:
206+
//For point layers buffer setting makes no sense, so set "fixed scale" on and disable margin control
207+
mAtlasFixedScaleRadio->setChecked( true );
208+
mAtlasMarginRadio->setEnabled( false );
209+
break;
210+
default:
211+
//Not a point layer, so enable changes to fixed scale control
212+
mAtlasMarginRadio->setEnabled( true );
213+
}
214+
}
215+
193216
void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
194217
{
195218
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -250,24 +273,20 @@ void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int
250273
atlasMap->setHideCoverage( state == Qt::Checked );
251274
}
252275

253-
void QgsAtlasCompositionWidget::on_mAtlasFixedScaleCheckBox_stateChanged( int state )
276+
void QgsAtlasCompositionWidget::on_mAtlasFixedScaleRadio_toggled( bool checked )
254277
{
255278
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
256279
if ( !atlasMap )
257280
{
258281
return;
259282
}
260-
atlasMap->setFixedScale( state == Qt::Checked );
283+
atlasMap->setFixedScale( checked );
284+
}
261285

262-
// in fixed scale mode, the margin is meaningless
263-
if ( state == Qt::Checked )
264-
{
265-
mAtlasMarginSpinBox->setEnabled( false );
266-
}
267-
else
268-
{
269-
mAtlasMarginSpinBox->setEnabled( true );
270-
}
286+
void QgsAtlasCompositionWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
287+
{
288+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
289+
atlasMap->setMargin( value / 100. );
271290
}
272291

273292
void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
@@ -426,6 +445,7 @@ void QgsAtlasCompositionWidget::updateGuiElements()
426445
if ( idx != -1 )
427446
{
428447
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
448+
checkLayerType( atlasMap->coverageLayer() );
429449
}
430450
idx = mComposerMapComboBox->findData( qVariantFromValue(( void* )atlasMap->composerMap() ) );
431451
if ( idx != -1 )
@@ -435,7 +455,15 @@ void QgsAtlasCompositionWidget::updateGuiElements()
435455

436456
mAtlasMarginSpinBox->setValue( static_cast<int>( atlasMap->margin() * 100 ) );
437457
mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
438-
mAtlasFixedScaleCheckBox->setCheckState( atlasMap->fixedScale() ? Qt::Checked : Qt::Unchecked );
458+
if ( atlasMap->fixedScale() )
459+
{
460+
mAtlasFixedScaleRadio->setChecked( true );
461+
mAtlasMarginSpinBox->setEnabled( false );
462+
}
463+
else
464+
{
465+
mAtlasMarginRadio->setChecked( true );
466+
}
439467
mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
440468
mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
441469
mAtlasSortFeatureCheckBox->setCheckState( atlasMap->sortFeatures() ? Qt::Checked : Qt::Unchecked );

src/app/composer/qgsatlascompositionwidget.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
***************************************************************************/
1616

1717
#include "ui_qgsatlascompositionwidgetbase.h"
18+
#include "qgsvectorlayer.h"
1819

1920
class QgsComposition;
2021
class QgsMapLayer;
@@ -40,7 +41,7 @@ class QgsAtlasCompositionWidget:
4041
void on_mAtlasFilenamePatternEdit_textChanged( const QString& text );
4142
void on_mAtlasFilenameExpressionButton_clicked();
4243
void on_mAtlasHideCoverageCheckBox_stateChanged( int state );
43-
void on_mAtlasFixedScaleCheckBox_stateChanged( int state );
44+
void on_mAtlasFixedScaleRadio_toggled( bool checked );
4445
void on_mAtlasSingleFileCheckBox_stateChanged( int state );
4546

4647
void on_mAtlasSortFeatureCheckBox_stateChanged( int state );
@@ -49,6 +50,7 @@ class QgsAtlasCompositionWidget:
4950
void on_mAtlasFeatureFilterEdit_textChanged( const QString& text );
5051
void on_mAtlasFeatureFilterButton_clicked();
5152
void on_mAtlasFeatureFilterCheckBox_stateChanged( int state );
53+
void on_mAtlasMarginSpinBox_valueChanged( int value );
5254

5355
// extract fields from the current coverage layer and populate the corresponding combo box
5456
void fillSortColumns();
@@ -64,4 +66,5 @@ class QgsAtlasCompositionWidget:
6466
QgsComposition* mComposition;
6567

6668
void blockAllSignals( bool b );
69+
void checkLayerType( QgsVectorLayer *layer );
6770
};

src/ui/qgsatlascompositionwidgetbase.ui

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<x>0</x>
9292
<y>0</y>
9393
<width>431</width>
94-
<height>567</height>
94+
<height>568</height>
9595
</rect>
9696
</property>
9797
<layout class="QVBoxLayout" name="mainLayout">
@@ -299,7 +299,7 @@
299299
</property>
300300
<layout class="QGridLayout" name="gridLayout_2">
301301
<item row="0" column="0">
302-
<widget class="QLabel" name="label_3">
302+
<widget class="QRadioButton" name="mAtlasMarginRadio">
303303
<property name="text">
304304
<string>Margin around feature</string>
305305
</property>
@@ -324,8 +324,8 @@
324324
</property>
325325
</widget>
326326
</item>
327-
<item row="1" column="0" colspan="2">
328-
<widget class="QCheckBox" name="mAtlasFixedScaleCheckBox">
327+
<item row="1" column="0">
328+
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
329329
<property name="text">
330330
<string>Fixed scale</string>
331331
</property>

0 commit comments

Comments
 (0)