195 changes: 195 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,21 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
connect( mGridCheckBox, SIGNAL( toggled( bool ) ),
mDrawAnnotationCheckableGroupBox, SLOT( setEnabled( bool ) ) );

connect( mAtlasCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( atlasToggled( bool ) ) );

if ( composerMap )
{
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );

//get composition
QgsComposition* composition = mComposerMap->composition();
if ( composition )
{
QgsAtlasComposition* atlas = &composition->atlasComposition();
connect( atlas, SIGNAL( coverageLayerChanged( QgsVectorLayer* ) ),
this, SLOT( atlasLayerChanged( QgsVectorLayer* ) ) );
connect( atlas, SIGNAL( toggled( bool ) ), this, SLOT( compositionAtlasToggled( bool ) ) );
}
}

updateOverviewSymbolMarker();
Expand All @@ -106,6 +118,111 @@ QgsComposerMapWidget::~QgsComposerMapWidget()
{
}

void QgsComposerMapWidget::compositionAtlasToggled( bool atlasEnabled )
{
if ( atlasEnabled )
{
mAtlasCheckBox->setEnabled( true );
}
else
{
mAtlasCheckBox->setEnabled( false );
mAtlasCheckBox->setChecked( false );
}
}

void QgsComposerMapWidget::atlasToggled( bool checked )
{
if ( checked && mComposerMap )
{
//check atlas coverage layer type
QgsComposition* composition = mComposerMap->composition();
if ( composition )
{
toggleAtlasMarginByLayerType();
}
else
{
mAtlasMarginRadio->setEnabled( false );
}
}
else
{
mAtlasMarginRadio->setEnabled( false );
}

mAtlasFixedScaleRadio->setEnabled( checked );
if ( mAtlasMarginRadio->isEnabled() && mAtlasMarginRadio->isChecked() )
{
mAtlasMarginSpinBox->setEnabled( true );
}
else
{
mAtlasMarginSpinBox->setEnabled( false );
}
}


void QgsComposerMapWidget::on_mAtlasCheckBox_toggled( bool checked )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setAtlasDriven( checked );
updateMapForAtlas();
}

void QgsComposerMapWidget::updateMapForAtlas()
{
//update map if in atlas preview mode
QgsComposition* composition = mComposerMap->composition();
if ( !composition )
{
return;
}
if ( composition->atlasMode() == QgsComposition::AtlasOff )
{
return;
}

//update atlas based extent for map
QgsAtlasComposition* atlas = &composition->atlasComposition();
atlas->prepareMap( mComposerMap );

//redraw map
mComposerMap->cache();
mComposerMap->update();
}

void QgsComposerMapWidget::on_mAtlasMarginRadio_toggled( bool checked )
{
mAtlasMarginSpinBox->setEnabled( checked );
}

void QgsComposerMapWidget::on_mAtlasMarginSpinBox_valueChanged( int value )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setAtlasMargin( value / 100. );
updateMapForAtlas();
}

void QgsComposerMapWidget::on_mAtlasFixedScaleRadio_toggled( bool checked )
{
if ( !mComposerMap )
{
return;
}

mComposerMap->setAtlasFixedScale( checked );
updateMapForAtlas();
}

void QgsComposerMapWidget::on_mPreviewModeComboBox_activated( int i )
{
Q_UNUSED( i );
Expand Down Expand Up @@ -402,10 +519,73 @@ void QgsComposerMapWidget::updateGuiElements()

mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );

//atlas controls
mAtlasCheckBox->setChecked( mComposerMap->atlasDriven() );
mAtlasMarginSpinBox->setValue( static_cast<int>( mComposerMap->atlasMargin() * 100 ) );
if ( mComposerMap->atlasFixedScale() )
{
mAtlasFixedScaleRadio->setChecked( true );
mAtlasMarginSpinBox->setEnabled( false );
}
else
{
mAtlasMarginRadio->setChecked( true );
mAtlasMarginSpinBox->setEnabled( true );
}
if ( !mComposerMap->atlasDriven() )
{
mAtlasMarginSpinBox->setEnabled( false );
mAtlasMarginRadio->setEnabled( false );
mAtlasFixedScaleRadio->setEnabled( false );
}
else
{
mAtlasFixedScaleRadio->setEnabled( true );
toggleAtlasMarginByLayerType();
}

blockAllSignals( false );
}
}

void QgsComposerMapWidget::toggleAtlasMarginByLayerType()
{
if ( !mComposerMap )
{
return;
}

//get composition
QgsComposition* composition = mComposerMap->composition();
if ( !composition )
{
return;
}

QgsAtlasComposition* atlas = &composition->atlasComposition();

QgsVectorLayer* coverageLayer = atlas->coverageLayer();
if ( !coverageLayer )
{
return;
}

switch ( atlas->coverageLayer()->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 QgsComposerMapWidget::updateComposerExtentFromGui()
{
if ( !mComposerMap )
Expand Down Expand Up @@ -480,6 +660,10 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mOverviewBlendModeComboBox->blockSignals( b );
mOverviewInvertCheckbox->blockSignals( b );
mOverviewCenterCheckbox->blockSignals( b );
mAtlasCheckBox->blockSignals( b );
mAtlasMarginSpinBox->blockSignals( b );
mAtlasFixedScaleRadio->blockSignals( b );
mAtlasMarginRadio->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
Expand Down Expand Up @@ -1173,3 +1357,14 @@ void QgsComposerMapWidget::refreshMapComboBox()

mOverviewFrameMapComboBox->blockSignals( false );
}

void QgsComposerMapWidget::atlasLayerChanged( QgsVectorLayer* layer )
{
// enable or disable fixed scale control based on layer type
if ( !layer || !mAtlasCheckBox->isChecked() )
{
return;
}

toggleAtlasMarginByLayerType();
}
20 changes: 20 additions & 0 deletions src/app/composer/qgscomposermapwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor );
void on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor );

void atlasToggled( bool checked );
void on_mAtlasMarginRadio_toggled( bool checked );

void on_mAtlasCheckBox_toggled( bool checked );
void on_mAtlasMarginSpinBox_valueChanged( int value );
void on_mAtlasFixedScaleRadio_toggled( bool checked );

protected:
void showEvent( QShowEvent * event );

Expand All @@ -103,6 +110,12 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
/**Sets the GUI elements to the values of mPicture*/
void setGuiElementValues();

/**Enables or disables the atlas margin around feature option depending on coverage layer type*/
void atlasLayerChanged( QgsVectorLayer* layer );

/**Enables or disables the atlas controls when composer atlas is toggled on/off*/
void compositionAtlasToggled( bool atlasEnabled );

private:
QgsComposerMap* mComposerMap;

Expand All @@ -129,6 +142,13 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase

/**Enables/disables grid frame related controls*/
void toggleFrameControls( bool frameEnabled );

/**Enables or disables the atlas margin radio depending on the atlas coverage layer type*/
void toggleAtlasMarginByLayerType();

/**Recalculates the bounds for an atlas map when atlas properties change*/
void updateMapForAtlas();

};

#endif
288 changes: 215 additions & 73 deletions src/core/composer/qgsatlascomposition.cpp

Large diffs are not rendered by default.

47 changes: 37 additions & 10 deletions src/core/composer/qgsatlascomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,35 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
bool enabled() const { return mEnabled; }
void setEnabled( bool e );

QgsComposerMap* composerMap() const { return mComposerMap; }
void setComposerMap( QgsComposerMap* map ) { mComposerMap = map; }
/**Returns the map used by the atlas
* @deprecated Use QgsComposerMap::atlasDriven() instead
*/
QgsComposerMap* composerMap() const;
/**Sets the map used by the atlas
* @deprecated Use QgsComposerMap::setAtlasDriven( true ) instead
*/
void setComposerMap( QgsComposerMap* map );

bool hideCoverage() const { return mHideCoverage; }
void setHideCoverage( bool hide );

bool fixedScale() const { return mFixedScale; }
void setFixedScale( bool fixed ) { mFixedScale = fixed; }

float margin() const { return mMargin; }
void setMargin( float margin ) { mMargin = margin; }
/**Returns whether the atlas map uses a fixed scale
* @deprecated Use QgsComposerMap::atlasFixedScale() instead
*/
bool fixedScale() const;
/**Sets whether the atlas map should use a fixed scale
* @deprecated Use QgsComposerMap::setAtlasFixedScale( bool ) instead
*/
void setFixedScale( bool fixed );

/**Returns the margin for the atlas map
* @deprecated Use QgsComposerMap::atlasMargin() instead
*/
float margin() const;
/**Sets the margin for the atlas map
* @deprecated Use QgsComposerMap::setAtlasMargin( double ) instead
*/
void setMargin( float margin );

QString filenamePattern() const { return mFilenamePattern; }
void setFilenamePattern( const QString& pattern );
Expand Down Expand Up @@ -113,6 +131,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
/** Returns the current atlas feature. Must be called after prepareForFeature( i ). */
QgsFeature* currentFeature() { return &mCurrentFeature; }

/** Recalculates the bounds of an atlas driven map */
void prepareMap( QgsComposerMap* map );

signals:
/** emitted when one of the parameters changes */
void parameterChanged();
Expand All @@ -123,6 +144,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
/**Is emitted when the atlas has an updated status bar message for the composer window*/
void statusMsgChanged( QString message );

/**Is emitted when the coverage layer for an atlas changes*/
void coverageLayerChanged( QgsVectorLayer* layer );

private:
/**Updates the filename expression*/
void updateFilenameExpression();
Expand All @@ -133,10 +157,7 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
QgsComposition* mComposition;

bool mEnabled;
QgsComposerMap* mComposerMap;
bool mHideCoverage;
bool mFixedScale;
double mMargin;
QString mFilenamePattern;
QgsVectorLayer* mCoverageLayer;
bool mSingleFile;
Expand Down Expand Up @@ -170,6 +191,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
QgsFeature mCurrentFeature;
bool mRestoreLayer;
std::auto_ptr<QgsExpression> mFilenameExpr;

// bounding box of the current feature transformed into map crs
QgsRectangle mTransformedFeatureBounds;

//forces all atlas enabled maps to redraw
void updateAtlasMaps();
};

#endif
Expand Down
30 changes: 21 additions & 9 deletions src/core/composer/qgscomposermap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
{
mComposition = composition;
mOverviewFrameMapSymbol = 0;
Expand Down Expand Up @@ -106,7 +106,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ),
mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
{
mOverviewFrameMapSymbol = 0;
mGridLineSymbol = 0;
Expand Down Expand Up @@ -651,10 +651,7 @@ void QgsComposerMap::toggleAtlasPreview()
QgsRectangle* QgsComposerMap::currentMapExtent()
{
//non-const version

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();

if ( atlasMap->composerMap() == this && mComposition->atlasMode() != QgsComposition::AtlasOff )
if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
//return the current temporary atlas feature extent
Expand All @@ -670,9 +667,7 @@ QgsRectangle* QgsComposerMap::currentMapExtent()
const QgsRectangle* QgsComposerMap::currentMapExtent() const
{
//const version

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( atlasMap->composerMap() == this && mComposition->atlasMode() != QgsComposition::AtlasOff )
if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
//return the current temporary atlas feature extent
Expand Down Expand Up @@ -991,6 +986,13 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
gridElem.appendChild( annotationElem );
composerMapElem.appendChild( gridElem );

//atlas
QDomElement atlasElem = doc.createElement( "AtlasMap" );
atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
atlasElem.setAttribute( "fixedScale", mAtlasFixedScale );
atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
composerMapElem.appendChild( atlasElem );

elem.appendChild( composerMapElem );
return _writeXML( composerMapElem, doc );
}
Expand Down Expand Up @@ -1233,6 +1235,16 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
}
}

//atlas
QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
if ( atlasNodeList.size() > 0 )
{
QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
mAtlasDriven = ( atlasElem.attribute( "atlasDriven", "0" ) != "0" );
mAtlasFixedScale = ( atlasElem.attribute( "fixedScale", "0" ) != "0" );
mAtlasMargin = atlasElem.attribute( "margin", "0.1" ).toDouble();
}

//restore general composer item properties
QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
if ( composerItemList.size() > 0 )
Expand Down
22 changes: 22 additions & 0 deletions src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,21 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
*/
void sizeChangedByRotation( double& width, double& height );

/** Returns true if the map extent is set to follow the current atlas feature */
bool atlasDriven() const { return mAtlasDriven; }
/** Set to true if the map extents should be set by the current atlas feature */
void setAtlasDriven( bool enabled ) { mAtlasDriven = enabled; }

/** Returns true if the map uses a fixed scale when in atlas mode */
bool atlasFixedScale() const { return mAtlasFixedScale; }
/** Set to true if the map should use a fixed scale when in atlas mode */
void setAtlasFixedScale( bool fixed ) { mAtlasFixedScale = fixed; }

/** Returns the margin size (percentage) used when the map is in atlas mode */
double atlasMargin() const { return mAtlasMargin; }
/** Sets the margin size (percentage) used when the map is in atlas mode */
void setAtlasMargin( double margin ) { mAtlasMargin = margin; }

signals:
void extentChanged();

Expand Down Expand Up @@ -571,6 +586,13 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
* center of extent remains the same */
void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const;

/**True if map is being controlled by an atlas*/
bool mAtlasDriven;
/**True if map uses a fixed scale when controlled by an atlas*/
bool mAtlasFixedScale;
/**Margin size for atlas driven extents (percentage of feature size)*/
double mAtlasMargin;

/**Draws the map grid*/
void drawGrid( QPainter* p );
void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
Expand Down
11 changes: 9 additions & 2 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2347,9 +2347,16 @@ bool QgsComposition::setAtlasMode( QgsComposition::AtlasMode mode )
}
}

if ( mAtlasComposition.composerMap() )
QList<QgsComposerMap*> maps;
composerItems( maps );
for ( QList<QgsComposerMap*>::iterator mit = maps.begin(); mit != maps.end(); ++mit )
{
mAtlasComposition.composerMap()->toggleAtlasPreview();
QgsComposerMap* currentMap = ( *mit );
if ( !currentMap->atlasDriven() )
{
continue;
}
currentMap->toggleAtlasPreview();
}

update();
Expand Down
98 changes: 24 additions & 74 deletions src/ui/qgsatlascompositionwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand All @@ -32,15 +41,24 @@
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>0</number>
</property>
<property name="verticalSpacing">
<number>3</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QCheckBox" name="mUseAtlasCheckBox">
<property name="text">
Expand Down Expand Up @@ -91,7 +109,7 @@
<x>0</x>
<y>0</y>
<width>431</width>
<height>568</height>
<height>567</height>
</rect>
</property>
<layout class="QVBoxLayout" name="mainLayout">
Expand Down Expand Up @@ -123,27 +141,13 @@
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<item row="0" column="0">
<widget class="QLabel" name="mVerticalAlignementLabel">
<property name="text">
<string>Composer map</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="mComposerMapComboBox"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mHorizontalAlignementLabel">
<property name="text">
<string>Coverage layer</string>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QComboBox" name="mAtlasCoverageLayerComboBox"/>
Expand Down Expand Up @@ -280,60 +284,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mScalingGroup">
<property name="enabled">
<bool>false</bool>
</property>
<property name="title">
<string>Scaling</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">composeritem</string>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QRadioButton" name="mAtlasMarginRadio">
<property name="text">
<string>Margin around feature</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="mAtlasMarginSpinBox">
<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>100</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
<property name="text">
<string>Fixed scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mOutputGroup">
<property name="enabled">
Expand Down
75 changes: 72 additions & 3 deletions src/ui/qgscomposermapwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -54,9 +63,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-420</y>
<y>0</y>
<width>439</width>
<height>1509</height>
<height>1638</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -251,6 +260,66 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mAtlasCheckBox">
<property name="title">
<string>Controlled by atlas</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="collapsed" stdset="0">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<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>
<item row="0" column="1">
<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 row="1" column="0">
<widget class="QRadioButton" name="mAtlasFixedScaleRadio">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Fixed scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBoxBasic" name="mGridCheckBox">
<property name="title">
Expand Down
4 changes: 2 additions & 2 deletions tests/src/core/qgscompositionchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ QgsCompositionChecker::~QgsCompositionChecker()
{
}

bool QgsCompositionChecker::testComposition( QString &report, int page )
bool QgsCompositionChecker::testComposition( QString &report, int page, int pixelDiff )
{
if ( !mComposition )
{
Expand Down Expand Up @@ -82,7 +82,7 @@ bool QgsCompositionChecker::testComposition( QString &report, int page )

QString diffFilePath = QDir::tempPath() + QDir::separator() + QFileInfo( mTestName ).baseName() + "_result_diff.png";

bool testResult = compareImages( mTestName, 0, renderedFilePath );
bool testResult = compareImages( mTestName, pixelDiff, renderedFilePath );

QString myDashMessage = "<DartMeasurementFile name=\"Rendered Image " + mTestName + "\""
" type=\"image/png\">" + renderedFilePath +
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/qgscompositionchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class QgsCompositionChecker : public QgsRenderChecker
QgsCompositionChecker( const QString& testName, QgsComposition* composition );
~QgsCompositionChecker();

bool testComposition( QString &report, int page = 0 );
bool testComposition( QString &report, int page = 0, int pixelDiff = 0 );

private:
QgsCompositionChecker(); //forbidden
Expand Down
95 changes: 89 additions & 6 deletions tests/src/core/testqgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ class TestQgsAtlasComposition: public QObject
void filename();
// test rendering with an autoscale atlas
void autoscale_render();
// test rendering with an autoscale atlas using the old api
void autoscale_render_2_0_api();
// test rendering with a fixed scale atlas
void fixedscale_render();
// test rendering with a fixed scale atlas using the old api
void fixedscale_render_2_0_api();
// test rendering with two atlas-driven maps
void two_map_autoscale_render();
// test rendering with a hidden coverage
void hiding_render();
// test rendering with feature sorting
Expand Down Expand Up @@ -104,7 +110,6 @@ void TestQgsAtlasComposition::initTestCase()

mAtlas = &mComposition->atlasComposition();
mAtlas->setCoverageLayer( mVectorLayer );
mAtlas->setComposerMap( mAtlasMap );
mComposition->setAtlasMode( QgsComposition::ExportAtlas );

// an overview
Expand Down Expand Up @@ -180,6 +185,29 @@ void TestQgsAtlasComposition::filename()

void TestQgsAtlasComposition::autoscale_render()
{
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setAtlasFixedScale( false );
mAtlasMap->setAtlasMargin( 0.10 );

mAtlas->beginRender();

for ( int fit = 0; fit < 2; ++fit )
{
mAtlas->prepareForFeature( fit );
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_autoscale%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
}
mAtlas->endRender();
mAtlasMap->setAtlasDriven( false );
mAtlasMap->setAtlasFixedScale( false );
mAtlasMap->setAtlasMargin( 0 );
}

void TestQgsAtlasComposition::autoscale_render_2_0_api()
{
mAtlas->setComposerMap( mAtlasMap );
mAtlas->setFixedScale( false );
mAtlas->setMargin( 0.10f );

Expand All @@ -190,16 +218,20 @@ void TestQgsAtlasComposition::autoscale_render()
mAtlas->prepareForFeature( fit );
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_autoscale%1" ).arg((( int )fit ) + 1 ), mComposition );
QgsCompositionChecker checker( QString( "atlas_autoscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
}
mAtlas->endRender();
mAtlas->setComposerMap( 0 );
mAtlas->setFixedScale( false );
mAtlas->setMargin( 0 );
}

void TestQgsAtlasComposition::fixedscale_render()
{
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
mAtlas->setFixedScale( true );
mAtlasMap->setAtlasFixedScale( true );

mAtlas->beginRender();

Expand All @@ -213,12 +245,61 @@ void TestQgsAtlasComposition::fixedscale_render()
}
mAtlas->endRender();

mAtlasMap->setAtlasDriven( false );
mAtlasMap->setAtlasFixedScale( false );
}

void TestQgsAtlasComposition::hiding_render()
void TestQgsAtlasComposition::fixedscale_render_2_0_api()
{
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
mAtlas->setComposerMap( mAtlasMap );
mAtlas->setFixedScale( true );
mAtlas->beginRender();

for ( int fit = 0; fit < 2; ++fit )
{
mAtlas->prepareForFeature( fit );
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_fixedscale_old_api%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0 ) );
}
mAtlas->endRender();
mAtlas->setComposerMap( 0 );
mAtlas->setFixedScale( false );
}

void TestQgsAtlasComposition::two_map_autoscale_render()
{
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setAtlasFixedScale( false );
mAtlasMap->setAtlasMargin( 0.10 );
mOverview->setAtlasDriven( true );
mOverview->setAtlasFixedScale( false );
mOverview->setAtlasMargin( 2.0 );

mAtlas->beginRender();

for ( int fit = 0; fit < 2; ++fit )
{
mAtlas->prepareForFeature( fit );
mLabel1->adjustSizeToText();

QgsCompositionChecker checker( QString( "atlas_two_maps%1" ).arg((( int )fit ) + 1 ), mComposition );
QVERIFY( checker.testComposition( mReport, 0, 10 ) );
}
mAtlas->endRender();
mAtlasMap->setAtlasDriven( false );
mAtlasMap->setAtlasFixedScale( false );
mAtlasMap->setAtlasMargin( 0 );
mOverview->setAtlasDriven( false );
}

void TestQgsAtlasComposition::hiding_render()
{
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setAtlasFixedScale( true );
mAtlas->setHideCoverage( true );

mAtlas->beginRender();
Expand All @@ -237,7 +318,8 @@ void TestQgsAtlasComposition::hiding_render()
void TestQgsAtlasComposition::sorting_render()
{
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
mAtlas->setFixedScale( true );
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setAtlasFixedScale( true );
mAtlas->setHideCoverage( false );

mAtlas->setSortFeatures( true );
Expand All @@ -260,7 +342,8 @@ void TestQgsAtlasComposition::sorting_render()
void TestQgsAtlasComposition::filtering_render()
{
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
mAtlas->setFixedScale( true );
mAtlasMap->setAtlasDriven( true );
mAtlasMap->setAtlasFixedScale( true );
mAtlas->setHideCoverage( false );

mAtlas->setSortFeatures( false );
Expand Down
4 changes: 2 additions & 2 deletions tests/src/python/qgscompositionchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, mTestName, mComposition ):
self.mTestName = mTestName
super(QgsCompositionChecker, self).__init__()

def testComposition(self, page=0 ):
def testComposition(self, page=0, pixelDiff=0 ):
if ( self.mComposition == None):
myMessage = "Composition not valid"
return False, myMessage
Expand All @@ -53,7 +53,7 @@ def testComposition(self, page=0 ):
outputImage.save( renderedFilePath, "PNG" )

diffFilePath = QDir.tempPath() + QDir.separator() + QFileInfo(self.mTestName).baseName() + "_result_diff.png"
testResult = self.compareImages( self.mTestName, 0, renderedFilePath )
testResult = self.compareImages( self.mTestName, pixelDiff, renderedFilePath )

myDashMessage = (('<DartMeasurementFile name="Rendered Image '
'%s" type="image/png">'
Expand Down
39 changes: 33 additions & 6 deletions tests/src/python/test_qgsatlascomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def testCase(self):
# the atlas
self.mAtlas = self.mComposition.atlasComposition()
self.mAtlas.setCoverageLayer( mVectorLayer )
self.mAtlas.setComposerMap( self.mAtlasMap )
self.mComposition.setAtlasMode( QgsComposition.ExportAtlas )

# an overview
Expand Down Expand Up @@ -99,6 +98,7 @@ def testCase(self):

self.filename_test()
self.autoscale_render_test()
self.autoscale_render_test_old_api()
self.fixedscale_render_test()
self.hidden_render_test()

Expand All @@ -113,6 +113,28 @@ def filename_test( self ):
self.mAtlas.endRender()

def autoscale_render_test( self ):
self.mAtlasMap.setAtlasDriven( True )
self.mAtlasMap.setAtlasFixedScale( False )
self.mAtlasMap.setAtlasMargin( 0.10 )

self.mAtlas.beginRender()

for i in range(0, 2):
self.mAtlas.prepareForFeature( i )
self.mLabel1.adjustSizeToText()

checker = QgsCompositionChecker('atlas_autoscale%d' % (i + 1), self.mComposition)
myTestResult, myMessage = checker.testComposition(0, 10)

assert myTestResult == True
self.mAtlas.endRender()

self.mAtlasMap.setAtlasDriven( False )
self.mAtlasMap.setAtlasFixedScale( True )
self.mAtlasMap.setAtlasMargin( 0 )

def autoscale_render_test_old_api( self ):
self.mAtlas.setComposerMap( self.mAtlasMap )
self.mAtlas.setFixedScale( False )
self.mAtlas.setMargin( 0.10 )

Expand All @@ -122,15 +144,20 @@ def autoscale_render_test( self ):
self.mAtlas.prepareForFeature( i )
self.mLabel1.adjustSizeToText()

checker = QgsCompositionChecker('atlas_autoscale%d' % (i + 1), self.mComposition)
checker = QgsCompositionChecker('atlas_autoscale_old_api%d' % (i + 1), self.mComposition)
myTestResult, myMessage = checker.testComposition()

assert myTestResult == True
self.mAtlas.endRender()

self.mAtlas.setFixedScale( True )
self.mAtlas.setMargin( 0 )
self.mAtlas.setComposerMap( None )

def fixedscale_render_test( self ):
self.mAtlasMap.setAtlasDriven( True )
self.mAtlasMap.setAtlasFixedScale( True )
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )

self.mAtlas.beginRender()

Expand All @@ -146,7 +173,7 @@ def fixedscale_render_test( self ):

def hidden_render_test( self ):
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )
self.mAtlasMap.setAtlasFixedScale( True )
self.mAtlas.setHideCoverage( True )

self.mAtlas.beginRender()
Expand All @@ -163,7 +190,7 @@ def hidden_render_test( self ):

def sorting_render_test( self ):
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )
self.mAtlasMap.setAtlasFixedScale( True )
self.mAtlas.setHideCoverage( False )

self.mAtlas.setSortFeatures( True )
Expand All @@ -184,7 +211,7 @@ def sorting_render_test( self ):

def filtering_render_test( self ):
self.mAtlasMap.setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
self.mAtlas.setFixedScale( True )
self.mAtlasMap.setAtlasFixedScale( True )
self.mAtlas.setHideCoverage( False )

self.mAtlas.setSortFeatures( False )
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.