Skip to content

Commit dd4975f

Browse files
committed
Merge pull request #1255 from Oslandia/atlas_signals
Atlas signals
2 parents 375e0d4 + 7805bc0 commit dd4975f

8 files changed

+52
-0
lines changed

python/core/composer/qgsatlascomposition.sip

+5
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,9 @@ public:
122122
/**Is emitted when the coverage layer for an atlas changes*/
123123
void coverageLayerChanged( QgsVectorLayer* layer );
124124

125+
/**Is emitted when atlas rendering has begun*/
126+
void renderBegun();
127+
128+
/**Is emitted when atlas rendering has ended*/
129+
void renderEnded();
125130
};

python/core/composer/qgscomposermap.sip

+3
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ class QgsComposerMap : QgsComposerItem
407407
/**Is emitted on rotation change to notify north arrow pictures*/
408408
void mapRotationChanged( double newRotation );
409409

410+
/**Is emitted when the map has been prepared for atlas rendering, just before actual rendering*/
411+
void preparedForAtlas();
412+
410413
public slots:
411414

412415
/**Called if map canvas has changed*/

src/core/composer/qgsatlascomposition.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ bool QgsAtlasComposition::beginRender()
266266
return false;
267267
}
268268

269+
emit renderBegun();
270+
269271
bool featuresUpdated = updateFeatures();
270272
if ( !featuresUpdated )
271273
{
@@ -296,6 +298,8 @@ void QgsAtlasComposition::endRender()
296298
}
297299

298300
updateAtlasMaps();
301+
302+
emit renderEnded();
299303
}
300304

301305
void QgsAtlasComposition::updateAtlasMaps()

src/core/composer/qgsatlascomposition.h

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
150150
/**Is emitted when the coverage layer for an atlas changes*/
151151
void coverageLayerChanged( QgsVectorLayer* layer );
152152

153+
/**Is emitted when atlas rendering has begun*/
154+
void renderBegun();
155+
156+
/**Is emitted when atlas rendering has ended*/
157+
void renderEnded();
158+
153159
private:
154160
/**Updates the filename expression*/
155161
void updateFilenameExpression();

src/core/composer/qgscomposermap.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ void QgsComposerMap::setNewAtlasFeatureExtent( const QgsRectangle& extent )
641641

642642
mAtlasFeatureExtent = newExtent;
643643
mCacheUpdated = false;
644+
emit preparedForAtlas();
644645
updateItem();
645646
emit itemChanged();
646647
emit extentChanged();

src/core/composer/qgscomposermap.h

+3
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
445445
/**Is emitted on rotation change to notify north arrow pictures*/
446446
void mapRotationChanged( double newRotation );
447447

448+
/**Is emitted when the map has been prepared for atlas rendering, just before actual rendering*/
449+
void preparedForAtlas();
450+
448451
public slots:
449452

450453
/**Called if map canvas has changed*/

src/core/composer/qgscomposition.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,7 @@ bool QgsComposition::setAtlasMode( QgsComposition::AtlasMode mode )
25372537
if ( ! atlasHasFeatures )
25382538
{
25392539
mAtlasMode = QgsComposition::AtlasOff;
2540+
mAtlasComposition.endRender();
25402541
return false;
25412542
}
25422543
}

tests/src/core/testqgsatlascomposition.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgssymbolv2.h"
2929
#include "qgssinglesymbolrendererv2.h"
3030
#include <QObject>
31+
#include <QSignalSpy>
3132
#include <QtTest>
3233

3334
class TestQgsAtlasComposition: public QObject
@@ -57,6 +58,8 @@ class TestQgsAtlasComposition: public QObject
5758
void sorting_render();
5859
// test rendering with feature filtering
5960
void filtering_render();
61+
// test render signals
62+
void test_signals();
6063
private:
6164
QgsComposition* mComposition;
6265
QgsComposerLabel* mLabel1;
@@ -365,5 +368,31 @@ void TestQgsAtlasComposition::filtering_render()
365368
mAtlas->endRender();
366369
}
367370

371+
void TestQgsAtlasComposition::test_signals()
372+
{
373+
mAtlasMap->setNewExtent( QgsRectangle( 209838.166, 6528781.020, 610491.166, 6920530.620 ) );
374+
mAtlasMap->setAtlasDriven( true );
375+
mAtlasMap->setAtlasFixedScale( true );
376+
mAtlas->setHideCoverage( false );
377+
mAtlas->setSortFeatures( false );
378+
mAtlas->setFilterFeatures( false );
379+
380+
QSignalSpy spyRenderBegun( mAtlas, SIGNAL(renderBegun()) );
381+
QSignalSpy spyRenderEnded( mAtlas, SIGNAL(renderEnded()) );
382+
QSignalSpy spyPreparedForAtlas( mAtlasMap, SIGNAL(preparedForAtlas()) );
383+
mAtlas->beginRender();
384+
385+
QVERIFY( spyRenderBegun.count() == 1 );
386+
387+
for ( int fit = 0; fit < 2; ++fit )
388+
{
389+
mAtlas->prepareForFeature( fit );
390+
mLabel1->adjustSizeToText();
391+
}
392+
QVERIFY( spyPreparedForAtlas.count() == 2 );
393+
mAtlas->endRender();
394+
QVERIFY( spyRenderEnded.count() == 1 );
395+
}
396+
368397
QTEST_MAIN( TestQgsAtlasComposition )
369398
#include "moc_testqgsatlascomposition.cxx"

0 commit comments

Comments
 (0)