Skip to content
Permalink
Browse files

[FEATURE][composer] Allow data defined control of atlas margin for maps

  • Loading branch information
nyalldawson committed Sep 25, 2014
1 parent a9c4136 commit 89a7573fafd8b1a45f6e446fa2cfa86c17faba7d
@@ -694,12 +694,15 @@ class QgsComposerMap : QgsComposerItem
void setAtlasScalingMode( AtlasScalingMode mode );

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

/**Sets the margin size (percentage) used when the map is in atlas mode.
* @param margin size in percentage to leave around the atlas feature's extent
@@ -37,6 +37,7 @@ class QgsComposerObject : QObject
MapYMin, /*< map extent y minimum */
MapXMax, /*< map extent x maximum */
MapYMax, /*< map extent y maximum */
MapAtlasMargin, /*< map atlas margin*/
//composer picture
PictureSource /*< picture source url */
};
@@ -162,6 +162,9 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
connect( mYMaxDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );
connect( mYMaxDDBtn, SIGNAL( dataDefinedActivated( bool ) ), mYMaxLineEdit, SLOT( setDisabled( bool ) ) );

connect( mAtlasMarginDDBtn, SIGNAL( dataDefinedChanged( const QString& ) ), this, SLOT( updateDataDefinedProperty( ) ) );
connect( mAtlasMarginDDBtn, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( updateDataDefinedProperty( ) ) );

updateGuiElements();
loadGridEntries();
loadOverviewEntries();
@@ -183,6 +186,7 @@ void QgsComposerMapWidget::populateDataDefinedButtons()
mYMinDDBtn->blockSignals( true );
mXMaxDDBtn->blockSignals( true );
mYMaxDDBtn->blockSignals( true );
mAtlasMarginDDBtn->blockSignals( true );

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

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

QgsComposerObject::DataDefinedProperty QgsComposerMapWidget::ddPropertyForWidget( QgsDataDefinedButton* widget )
@@ -241,6 +248,10 @@ QgsComposerObject::DataDefinedProperty QgsComposerMapWidget::ddPropertyForWidget
{
return QgsComposerObject::MapYMax;
}
else if ( widget == mAtlasMarginDDBtn )
{
return QgsComposerObject::MapAtlasMargin;
}

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

//atlas controls
mAtlasCheckBox->setChecked( mComposerMap->atlasDriven() );
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin() * 100 ) );
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin( QgsComposerObject::OriginalValue ) * 100 ) );

mAtlasFixedScaleRadio->setEnabled( mComposerMap->atlasDriven() );
mAtlasFixedScaleRadio->setChecked( mComposerMap->atlasScalingMode() == QgsComposerMap::Fixed );
@@ -129,6 +129,7 @@ void QgsComposerMap::init()
mDataDefinedNames.insert( QgsComposerObject::MapYMin, QString( "dataDefinedMapYMin" ) );
mDataDefinedNames.insert( QgsComposerObject::MapXMax, QString( "dataDefinedMapXMax" ) );
mDataDefinedNames.insert( QgsComposerObject::MapYMax, QString( "dataDefinedMapYMax" ) );
mDataDefinedNames.insert( QgsComposerObject::MapAtlasMargin, QString( "dataDefinedMapAtlasMargin" ) );
}

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

double QgsComposerMap::atlasMargin( const QgsComposerObject::PropertyValueType valueType )
{
if ( valueType == QgsComposerObject::EvaluatedValue )
{
//evaluate data defined atlas margin

//start with user specified margin
double margin = mAtlasMargin;
QVariant exprVal;
if ( dataDefinedEvaluate( QgsComposerObject::MapAtlasMargin, exprVal ) )
{
bool ok;
double ddMargin = exprVal.toDouble( &ok );
QgsDebugMsg( QString( "exprVal Map Atlas Margin:%1" ).arg( ddMargin ) );
if ( ok )
{
//divide by 100 to convert to 0 -> 1.0 range
margin = ddMargin / 100;
}
}
return margin;
}
else
{
return mAtlasMargin;
}
}

@@ -731,12 +731,15 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setAtlasScalingMode( AtlasScalingMode mode ) { mAtlasScalingMode = mode; }

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

/**Sets the margin size (percentage) used when the map is in atlas mode.
* @param margin size in percentage to leave around the atlas feature's extent
@@ -64,6 +64,7 @@ class CORE_EXPORT QgsComposerObject: public QObject
MapYMin, /*< map extent y minimum */
MapXMax, /*< map extent x maximum */
MapYMax, /*< map extent y maximum */
MapAtlasMargin, /*< map atlas margin*/
//composer picture
PictureSource, /*< picture source url */
//html item
@@ -2975,7 +2975,7 @@ bool QgsComposition::dataDefinedEvaluate( QgsComposerObject::DataDefinedProperty
return false;
}

QVariant QgsComposition::dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties )
QVariant QgsComposition::dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields, QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties ) const
{
if ( property == QgsComposerObject::AllProperties || property == QgsComposerObject::NoProperty )
{
@@ -793,7 +793,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
* @note this method was added in version 2.5
*/
QVariant dataDefinedValue( QgsComposerObject::DataDefinedProperty property, const QgsFeature *feature, const QgsFields *fields,
QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties );
QMap<QgsComposerObject::DataDefinedProperty, QgsDataDefined *> *dataDefinedProperties ) const;


/**Prepares the expression for a data defined property, using the current atlas layer if set.
@@ -55,8 +55,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>447</width>
<height>2274</height>
<width>444</width>
<height>2238</height>
</rect>
</property>
<property name="sizePolicy">
@@ -363,28 +363,49 @@
<string notr="true">composeritem</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
<item row="0" column="0">
<widget class="QRadioButton" name="mAtlasMarginRadio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>10</number>
<property name="text">
<string>Margin around feature</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="suffix">
<string>%</string>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<widget class="QgsDataDefinedButton" name="mAtlasMarginDDBtn">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mAtlasPredefinedScaleRadio">
<property name="toolTip">
@@ -405,16 +426,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="mAtlasMarginRadio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Margin around feature</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 89a7573

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