Skip to content
Permalink
Browse files

Merge pull request #1255 from Oslandia/atlas_signals

Atlas signals
  • Loading branch information
nyalldawson committed Mar 21, 2014
2 parents 375e0d4 + 7805bc0 commit dd4975f2853c1581ecbc61bfefb61c957b7453a8
@@ -122,4 +122,9 @@ public:
/**Is emitted when the coverage layer for an atlas changes*/
void coverageLayerChanged( QgsVectorLayer* layer );

/**Is emitted when atlas rendering has begun*/
void renderBegun();

/**Is emitted when atlas rendering has ended*/
void renderEnded();
};
@@ -407,6 +407,9 @@ class QgsComposerMap : QgsComposerItem
/**Is emitted on rotation change to notify north arrow pictures*/
void mapRotationChanged( double newRotation );

/**Is emitted when the map has been prepared for atlas rendering, just before actual rendering*/
void preparedForAtlas();

public slots:

/**Called if map canvas has changed*/
@@ -266,6 +266,8 @@ bool QgsAtlasComposition::beginRender()
return false;
}

emit renderBegun();

bool featuresUpdated = updateFeatures();
if ( !featuresUpdated )
{
@@ -296,6 +298,8 @@ void QgsAtlasComposition::endRender()
}

updateAtlasMaps();

emit renderEnded();
}

void QgsAtlasComposition::updateAtlasMaps()
@@ -150,6 +150,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
/**Is emitted when the coverage layer for an atlas changes*/
void coverageLayerChanged( QgsVectorLayer* layer );

/**Is emitted when atlas rendering has begun*/
void renderBegun();

/**Is emitted when atlas rendering has ended*/
void renderEnded();

private:
/**Updates the filename expression*/
void updateFilenameExpression();
@@ -641,6 +641,7 @@ void QgsComposerMap::setNewAtlasFeatureExtent( const QgsRectangle& extent )

mAtlasFeatureExtent = newExtent;
mCacheUpdated = false;
emit preparedForAtlas();
updateItem();
emit itemChanged();
emit extentChanged();
@@ -445,6 +445,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**Is emitted on rotation change to notify north arrow pictures*/
void mapRotationChanged( double newRotation );

/**Is emitted when the map has been prepared for atlas rendering, just before actual rendering*/
void preparedForAtlas();

public slots:

/**Called if map canvas has changed*/
@@ -2537,6 +2537,7 @@ bool QgsComposition::setAtlasMode( QgsComposition::AtlasMode mode )
if ( ! atlasHasFeatures )
{
mAtlasMode = QgsComposition::AtlasOff;
mAtlasComposition.endRender();
return false;
}
}
@@ -28,6 +28,7 @@
#include "qgssymbolv2.h"
#include "qgssinglesymbolrendererv2.h"
#include <QObject>
#include <QSignalSpy>
#include <QtTest>

class TestQgsAtlasComposition: public QObject
@@ -57,6 +58,8 @@ class TestQgsAtlasComposition: public QObject
void sorting_render();
// test rendering with feature filtering
void filtering_render();
// test render signals
void test_signals();
private:
QgsComposition* mComposition;
QgsComposerLabel* mLabel1;
@@ -365,5 +368,31 @@ void TestQgsAtlasComposition::filtering_render()
mAtlas->endRender();
}

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

QSignalSpy spyRenderBegun( mAtlas, SIGNAL(renderBegun()) );
QSignalSpy spyRenderEnded( mAtlas, SIGNAL(renderEnded()) );
QSignalSpy spyPreparedForAtlas( mAtlasMap, SIGNAL(preparedForAtlas()) );
mAtlas->beginRender();

QVERIFY( spyRenderBegun.count() == 1 );

for ( int fit = 0; fit < 2; ++fit )
{
mAtlas->prepareForFeature( fit );
mLabel1->adjustSizeToText();
}
QVERIFY( spyPreparedForAtlas.count() == 2 );
mAtlas->endRender();
QVERIFY( spyRenderEnded.count() == 1 );
}

QTEST_MAIN( TestQgsAtlasComposition )
#include "moc_testqgsatlascomposition.cxx"

0 comments on commit dd4975f

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