Skip to content

Commit 89a7573

Browse files
committedSep 25, 2014
[FEATURE][composer] Allow data defined control of atlas margin for maps
1 parent a9c4136 commit 89a7573

File tree

9 files changed

+93
-33
lines changed

9 files changed

+93
-33
lines changed
 

‎python/core/composer/qgscomposermap.sip

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,15 @@ class QgsComposerMap : QgsComposerItem
694694
void setAtlasScalingMode( AtlasScalingMode mode );
695695

696696
/**Returns the margin size (percentage) used when the map is in atlas mode.
697+
* @param valueType controls whether the returned value is the user specified atlas margin,
698+
* or the current evaluated atlas margin (which may be affected by data driven atlas margin
699+
* settings).
697700
* @returns margin size in percentage to leave around the atlas feature's extent
698701
* @note this is only used if atlasScalingMode() is Auto.
699702
* @see atlasScalingMode
700703
* @see setAtlasMargin
701704
*/
702-
double atlasMargin() const;
705+
double atlasMargin( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
703706

704707
/**Sets the margin size (percentage) used when the map is in atlas mode.
705708
* @param margin size in percentage to leave around the atlas feature's extent

‎python/core/composer/qgscomposerobject.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class QgsComposerObject : QObject
3737
MapYMin, /*< map extent y minimum */
3838
MapXMax, /*< map extent x maximum */
3939
MapYMax, /*< map extent y maximum */
40+
MapAtlasMargin, /*< map atlas margin*/
4041
//composer picture
4142
PictureSource /*< picture source url */
4243
};

‎src/app/composer/qgscomposermapwidget.cpp

100755100644
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
162162
connect( mYMaxDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );
163163
connect( mYMaxDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mYMaxLineEdit, SLOT( setDisabled( bool ) ) );
164164

165+
connect( mAtlasMarginDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty( ) ) );
166+
connect( mAtlasMarginDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );
167+
165168
updateGuiElements();
166169
loadGridEntries();
167170
loadOverviewEntries();
@@ -183,6 +186,7 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
183186
mYMinDDBtn->blockSignals( true );
184187
mXMaxDDBtn->blockSignals( true );
185188
mYMaxDDBtn->blockSignals( true );
189+
mAtlasMarginDDBtn->blockSignals( true );
186190

187191
//initialise buttons to use atlas coverage layer
188192
mScaleDDBtn->init( vl, mComposerMap->dataDefinedProperty( QgsComposerObject::MapScale ),
@@ -197,6 +201,8 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
197201
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
198202
mYMaxDDBtn->init( vl, mComposerMap->dataDefinedProperty( QgsComposerObject::MapYMax ),
199203
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
204+
mAtlasMarginDDBtn->init( vl, mComposerMap->dataDefinedProperty( QgsComposerObject::MapAtlasMargin ),
205+
QgsDataDefinedButton::AnyType, QgsDataDefinedButton::doubleDesc() );
200206

201207
//initial state of controls - disable related controls when dd buttons are active
202208
mScaleLineEdit->setEnabled( !mScaleDDBtn->isActive() );
@@ -213,6 +219,7 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
213219
mYMinDDBtn->blockSignals( false );
214220
mXMaxDDBtn->blockSignals( false );
215221
mYMaxDDBtn->blockSignals( false );
222+
mAtlasMarginDDBtn->blockSignals( false );
216223
}
217224

218225
QgsComposerObject::DataDefinedProperty QgsComposerMapWidget::ddPropertyForWidget( QgsDataDefinedButton* widget )
@@ -241,6 +248,10 @@ QgsComposerObject::DataDefinedProperty QgsComposerMapWidget::ddPropertyForWidget
241248
{
242249
return QgsComposerObject::MapYMax;
243250
}
251+
else if ( widget == mAtlasMarginDDBtn )
252+
{
253+
return QgsComposerObject::MapAtlasMargin;
254+
}
244255

245256
return QgsComposerObject::NoProperty;
246257
}
@@ -640,7 +651,7 @@ void QgsComposerMapWidget::updateGuiElements()
640651

641652
//atlas controls
642653
mAtlasCheckBox->setChecked( mComposerMap->atlasDriven() );
643-
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin() * 100 ) );
654+
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin( QgsComposerObject::OriginalValue ) * 100 ) );
644655

645656
mAtlasFixedScaleRadio->setEnabled( mComposerMap->atlasDriven() );
646657
mAtlasFixedScaleRadio->setChecked( mComposerMap->atlasScalingMode() == QgsComposerMap::Fixed );

‎src/core/composer/qgscomposermap.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void QgsComposerMap::init()
129129
mDataDefinedNames.insert( QgsComposerObject::MapYMin, QString( "dataDefinedMapYMin" ) );
130130
mDataDefinedNames.insert( QgsComposerObject::MapXMax, QString( "dataDefinedMapXMax" ) );
131131
mDataDefinedNames.insert( QgsComposerObject::MapYMax, QString( "dataDefinedMapYMax" ) );
132+
mDataDefinedNames.insert( QgsComposerObject::MapAtlasMargin, QString( "dataDefinedMapAtlasMargin" ) );
132133
}
133134

134135
void QgsComposerMap::adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const
@@ -2017,6 +2018,7 @@ void QgsComposerMap::refreshDataDefinedProperty( const QgsComposerObject::DataDe
20172018
if ( property == QgsComposerObject::MapRotation || property == QgsComposerObject::MapScale ||
20182019
property == QgsComposerObject::MapXMin || property == QgsComposerObject::MapYMin ||
20192020
property == QgsComposerObject::MapXMax || property == QgsComposerObject::MapYMax ||
2021+
property == QgsComposerObject::MapAtlasMargin ||
20202022
property == QgsComposerObject::AllProperties )
20212023
{
20222024
refreshMapExtents();
@@ -2303,3 +2305,31 @@ void QgsComposerMap::setAtlasFixedScale( bool fixed )
23032305
mAtlasScalingMode = fixed ? Fixed : Auto;
23042306
}
23052307

2308+
double QgsComposerMap::atlasMargin( const QgsComposerObject::PropertyValueType valueType )
2309+
{
2310+
if ( valueType == QgsComposerObject::EvaluatedValue )
2311+
{
2312+
//evaluate data defined atlas margin
2313+
2314+
//start with user specified margin
2315+
double margin = mAtlasMargin;
2316+
QVariant exprVal;
2317+
if ( dataDefinedEvaluate( QgsComposerObject::MapAtlasMargin, exprVal ) )
2318+
{
2319+
bool ok;
2320+
double ddMargin = exprVal.toDouble( &ok );
2321+
QgsDebugMsg( QString( "exprVal Map Atlas Margin:%1" ).arg( ddMargin ) );
2322+
if ( ok )
2323+
{
2324+
//divide by 100 to convert to 0 -> 1.0 range
2325+
margin = ddMargin / 100;
2326+
}
2327+
}
2328+
return margin;
2329+
}
2330+
else
2331+
{
2332+
return mAtlasMargin;
2333+
}
2334+
}
2335+

‎src/core/composer/qgscomposermap.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,15 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
731731
void setAtlasScalingMode( AtlasScalingMode mode ) { mAtlasScalingMode = mode; }
732732

733733
/**Returns the margin size (percentage) used when the map is in atlas mode.
734+
* @param valueType controls whether the returned value is the user specified atlas margin,
735+
* or the current evaluated atlas margin (which may be affected by data driven atlas margin
736+
* settings).
734737
* @returns margin size in percentage to leave around the atlas feature's extent
735738
* @note this is only used if atlasScalingMode() is Auto.
736739
* @see atlasScalingMode
737740
* @see setAtlasMargin
738741
*/
739-
double atlasMargin() const { return mAtlasMargin; }
742+
double atlasMargin( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
740743

741744
/**Sets the margin size (percentage) used when the map is in atlas mode.
742745
* @param margin size in percentage to leave around the atlas feature's extent

‎src/core/composer/qgscomposerobject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CORE_EXPORT QgsComposerObject: public QObject
6464
MapYMin, /*< map extent y minimum */
6565
MapXMax, /*< map extent x maximum */
6666
MapYMax, /*< map extent y maximum */
67+
MapAtlasMargin, /*< map atlas margin*/
6768
//composer picture
6869
PictureSource, /*< picture source url */
6970
//html item

‎src/core/composer/qgscomposition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,7 @@ bool QgsComposition::dataDefinedEvaluate( QgsComposerObject::DataDefinedProperty
29752975
return false;
29762976
}
29772977

2978-
QVariant QgsComposition::dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
2978+
QVariant QgsComposition::dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties ) const
29792979
{
29802980
if ( property == QgsComposerObject::AllProperties || property == QgsComposerObject::NoProperty )
29812981
{

‎src/core/composer/qgscomposition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
793793
* @note this method was added in version 2.5
794794
*/
795795
QVariant dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields,
796-
QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties );
796+
QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties ) const;
797797

798798

799799
/**Prepares the expression for a data defined property, using the current atlas layer if set.

‎src/ui/qgscomposermapwidgetbase.ui

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555
<rect>
5656
<x>0</x>
5757
<y>0</y>
58-
<width>447</width>
59-
<height>2274</height>
58+
<width>444</width>
59+
<height>2238</height>
6060
</rect>
6161
</property>
6262
<property name="sizePolicy">
@@ -363,28 +363,49 @@
363363
<string notr="true">composeritem</string>
364364
</property>
365365
<layout class="QGridLayout" name="gridLayout_2">
366-
<item row="0" column="1">
367-
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
366+
<item row="0" column="0">
367+
<widget class="QRadioButton" name="mAtlasMarginRadio">
368368
<property name="enabled">
369369
<bool>false</bool>
370370
</property>
371-
<property name="sizePolicy">
372-
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
373-
<horstretch>0</horstretch>
374-
<verstretch>0</verstretch>
375-
</sizepolicy>
376-
</property>
377-
<property name="suffix">
378-
<string>%</string>
379-
</property>
380-
<property name="maximum">
381-
<number>9999</number>
382-
</property>
383-
<property name="value">
384-
<number>10</number>
371+
<property name="text">
372+
<string>Margin around feature</string>
385373
</property>
386374
</widget>
387375
</item>
376+
<item row="0" column="1">
377+
<layout class="QHBoxLayout" name="horizontalLayout_11">
378+
<item>
379+
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
380+
<property name="enabled">
381+
<bool>false</bool>
382+
</property>
383+
<property name="sizePolicy">
384+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
385+
<horstretch>0</horstretch>
386+
<verstretch>0</verstretch>
387+
</sizepolicy>
388+
</property>
389+
<property name="suffix">
390+
<string>%</string>
391+
</property>
392+
<property name="maximum">
393+
<number>9999</number>
394+
</property>
395+
<property name="value">
396+
<number>10</number>
397+
</property>
398+
</widget>
399+
</item>
400+
<item>
401+
<widget class="QgsDataDefinedButton" name="mAtlasMarginDDBtn">
402+
<property name="text">
403+
<string>...</string>
404+
</property>
405+
</widget>
406+
</item>
407+
</layout>
408+
</item>
388409
<item row="1" column="0">
389410
<widget class="QRadioButton" name="mAtlasPredefinedScaleRadio">
390411
<property name="toolTip">
@@ -405,16 +426,6 @@
405426
</property>
406427
</widget>
407428
</item>
408-
<item row="0" column="0">
409-
<widget class="QRadioButton" name="mAtlasMarginRadio">
410-
<property name="enabled">
411-
<bool>false</bool>
412-
</property>
413-
<property name="text">
414-
<string>Margin around feature</string>
415-
</property>
416-
</widget>
417-
</item>
418429
</layout>
419430
</widget>
420431
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.