mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[composer] Disable atlas if coverage layer is removed from project
This commit is contained in:
parent
46c75994a5
commit
808464fed6
@ -47,6 +47,9 @@ QgsAtlasComposition::QgsAtlasComposition( QgsComposition* composition ) :
|
||||
QgsExpression::setSpecialColumn( "$atlasfeatureid", QVariant(( int )0 ) );
|
||||
QgsExpression::setSpecialColumn( "$atlasfeature", QVariant::fromValue( QgsFeature() ) );
|
||||
QgsExpression::setSpecialColumn( "$atlasgeometry", QVariant::fromValue( QgsGeometry() ) );
|
||||
|
||||
//listen out for layer removal
|
||||
connect( QgsMapLayerRegistry::instance(), SIGNAL( layersWillBeRemoved( QStringList ) ), this, SLOT( removeLayers( QStringList ) ) );
|
||||
}
|
||||
|
||||
QgsAtlasComposition::~QgsAtlasComposition()
|
||||
@ -55,13 +58,43 @@ QgsAtlasComposition::~QgsAtlasComposition()
|
||||
|
||||
void QgsAtlasComposition::setEnabled( bool enabled )
|
||||
{
|
||||
if ( enabled == mEnabled )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mEnabled = enabled;
|
||||
mComposition->setAtlasMode( QgsComposition::AtlasOff );
|
||||
emit toggled( enabled );
|
||||
emit parameterChanged();
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::removeLayers( QStringList layers )
|
||||
{
|
||||
if ( !mCoverageLayer )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( QString layerId, layers )
|
||||
{
|
||||
if ( layerId == mCoverageLayer->id() )
|
||||
{
|
||||
//current coverage layer removed
|
||||
mCoverageLayer = 0;
|
||||
setEnabled( false );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsAtlasComposition::setCoverageLayer( QgsVectorLayer* layer )
|
||||
{
|
||||
if ( layer == mCoverageLayer )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mCoverageLayer = layer;
|
||||
|
||||
// update the number of features
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QString>
|
||||
#include <QDomElement>
|
||||
#include <QDomDocument>
|
||||
#include <QStringList>
|
||||
|
||||
class QgsComposerMap;
|
||||
class QgsComposition;
|
||||
@ -305,6 +306,9 @@ class CORE_EXPORT QgsAtlasComposition : public QObject
|
||||
public:
|
||||
typedef QMap< QgsFeatureId, QVariant > SorterKeys;
|
||||
|
||||
private slots:
|
||||
void removeLayers( QStringList layers );
|
||||
|
||||
private:
|
||||
// value of field that is used for ordering of features
|
||||
SorterKeys mFeatureKeys;
|
||||
|
@ -63,6 +63,8 @@ class TestQgsAtlasComposition: public QObject
|
||||
void filtering_render();
|
||||
// test render signals
|
||||
void test_signals();
|
||||
// test removing coverage layer while atlas is enabled
|
||||
void test_remove_layer();
|
||||
|
||||
private:
|
||||
QgsComposition* mComposition;
|
||||
@ -73,6 +75,7 @@ class TestQgsAtlasComposition: public QObject
|
||||
//QgsMapRenderer* mMapRenderer;
|
||||
QgsMapSettings mMapSettings;
|
||||
QgsVectorLayer* mVectorLayer;
|
||||
QgsVectorLayer* mVectorLayer2;
|
||||
QgsAtlasComposition* mAtlas;
|
||||
QString mReport;
|
||||
};
|
||||
@ -87,6 +90,9 @@ void TestQgsAtlasComposition::initTestCase()
|
||||
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
|
||||
vectorFileInfo.completeBaseName(),
|
||||
"ogr" );
|
||||
mVectorLayer2 = new QgsVectorLayer( vectorFileInfo.filePath(),
|
||||
vectorFileInfo.completeBaseName(),
|
||||
"ogr" );
|
||||
|
||||
QgsVectorSimplifyMethod simplifyMethod;
|
||||
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::NoSimplification );
|
||||
@ -441,5 +447,24 @@ void TestQgsAtlasComposition::test_signals()
|
||||
QVERIFY( spyRenderEnded.count() == 1 );
|
||||
}
|
||||
|
||||
void TestQgsAtlasComposition::test_remove_layer()
|
||||
{
|
||||
mAtlas->setCoverageLayer( mVectorLayer2 );
|
||||
mAtlas->setEnabled( true );
|
||||
|
||||
QSignalSpy spyToggled( mAtlas, SIGNAL( toggled( bool ) ) );
|
||||
|
||||
//remove coverage layer while atlas is enabled
|
||||
QgsMapLayerRegistry::instance()->removeMapLayer( mVectorLayer2->id() );
|
||||
mVectorLayer2 = 0;
|
||||
|
||||
QVERIFY( !mAtlas->enabled() );
|
||||
QVERIFY( spyToggled.count() == 1 );
|
||||
|
||||
//clean up
|
||||
mAtlas->setCoverageLayer( mVectorLayer );
|
||||
mAtlas->setEnabled( true );
|
||||
}
|
||||
|
||||
QTEST_MAIN( TestQgsAtlasComposition )
|
||||
#include "moc_testqgsatlascomposition.cxx"
|
||||
|
Loading…
x
Reference in New Issue
Block a user