Skip to content
Permalink
Browse files

[composer] Tweak interface for atlas previews, fix occasional wrong e…

…xtent in atlas previews.
  • Loading branch information
nyalldawson committed Jan 7, 2014
1 parent dcd8bc5 commit 22514b6dc18c1a39ff0b50627bbbe967eb9110c3
@@ -27,6 +27,14 @@ class QgsComposition : QGraphicsScene
Dots,
Crosses
};

/**Composition atlas modes*/
enum AtlasMode
{
AtlasOff, // Composition is not being controlled by an atlas
PreviewAtlas, // An atlas composition is being previewed in the app
ExportAtlas // The composition is being exported as an atlas
};

QgsComposition( QgsMapRenderer* mapRenderer );
~QgsComposition();
@@ -306,6 +314,11 @@ class QgsComposition : QGraphicsScene
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;

QgsAtlasComposition& atlasComposition();

/** Returns the current atlas mode of the composition */
QgsComposition::AtlasMode atlasMode() const;
/** Sets the current atlas mode of the composition. Returns false if the mode could not be changed. */
bool setAtlasMode( QgsComposition::AtlasMode mode );

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
@@ -341,7 +341,7 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureCheckBox_stateChanged( int s
void QgsAtlasCompositionWidget::updateAtlasFeatures()
{
//only do this if composer mode is preview
if ( !mComposition->atlasPreviewEnabled() )
if ( !mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
return;
}
@@ -808,7 +808,13 @@ void QgsComposer::on_mActionOptions_triggered()
void QgsComposer::toggleAtlasControls( bool atlasEnabled )
{
//preview defaults to unchecked
mActionAtlasPreview->blockSignals( true );
mActionAtlasPreview->setChecked( false );
mActionAtlasFirst->setEnabled( false );
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
mActionAtlasPreview->blockSignals( false );
mActionAtlasPreview->setEnabled( atlasEnabled );
mActionPrintAtlas->setEnabled( atlasEnabled );
mActionExportAtlasAsImage->setEnabled( atlasEnabled );
@@ -841,7 +847,7 @@ void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
mActionAtlasNext->setEnabled( checked );
mActionAtlasPrev->setEnabled( checked );

bool previewEnabled = mComposition->setAtlasPreviewEnabled( checked );
bool previewEnabled = mComposition->setAtlasMode( checked ? QgsComposition::PreviewAtlas : QgsComposition::AtlasOff );
if ( !previewEnabled )
{
//something went wrong, eg, no matching features
@@ -1082,9 +1088,12 @@ void QgsComposer::on_mActionAtlasSettings_triggered()

void QgsComposer::on_mActionExportAtlasAsPDF_triggered()
{
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
exportCompositionAsPDF( QgsComposer::Atlas );
mComposition->setAtlasMode( previousMode );

if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -1139,7 +1148,8 @@ void QgsComposer::exportCompositionAsPDF( QgsComposer::OutputMode mode )
QString lastUsedFile = myQSettings.value( "/UI/lastSaveAsPdfFile", "qgis.pdf" ).toString();
QFileInfo file( lastUsedFile );

if ( hasAnAtlas && !atlasOnASingleFile && ( mode == QgsComposer::Atlas || mComposition->atlasPreviewEnabled() ) )
if ( hasAnAtlas && !atlasOnASingleFile &&
( mode == QgsComposer::Atlas || mComposition->atlasMode() == QgsComposition::PreviewAtlas ) )
{
outputFileName = QDir( file.path() ).filePath( atlasMap->currentFilename() ) + ".pdf";
}
@@ -1311,7 +1321,10 @@ void QgsComposer::on_mActionPrint_triggered()
void QgsComposer::on_mActionPrintAtlas_triggered()
{
//print whole atlas
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
printComposition( QgsComposer::Atlas );
mComposition->setAtlasMode( previousMode );
}

void QgsComposer::printComposition( QgsComposer::OutputMode mode )
@@ -1425,9 +1438,13 @@ void QgsComposer::printComposition( QgsComposer::OutputMode mode )

void QgsComposer::on_mActionExportAtlasAsImage_triggered()
{
//print whole atlas
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
exportCompositionAsImage( QgsComposer::Atlas );
mComposition->setAtlasMode( previousMode );

if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -1480,7 +1497,7 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )
{
QString outputFileName = QString::null;

if ( atlasMap->enabled() && mComposition->atlasPreviewEnabled() )
if ( atlasMap->enabled() && mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
QString lastUsedDir = settings.value( "/UI/lastSaveAsImageDir", "." ).toString();
outputFileName = QDir( lastUsedDir ).filePath( atlasMap->currentFilename() );
@@ -1702,9 +1719,12 @@ void QgsComposer::exportCompositionAsImage( QgsComposer::OutputMode mode )

void QgsComposer::on_mActionExportAtlasAsSVG_triggered()
{
QgsComposition::AtlasMode previousMode = mComposition->atlasMode();
mComposition->setAtlasMode( QgsComposition::ExportAtlas );
exportCompositionAsSVG( QgsComposer::Atlas );
mComposition->setAtlasMode( previousMode );

if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//after atlas output, jump back to preview first feature
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
@@ -52,6 +52,7 @@ QgsAtlasComposition::~QgsAtlasComposition()
void QgsAtlasComposition::setEnabled( bool e )
{
mEnabled = e;
mComposition->setAtlasMode( QgsComposition::AtlasOff );
emit toggled( e );
}

@@ -170,7 +171,7 @@ int QgsAtlasComposition::updateFeatures()

//jump to first feature if currently using an atlas preview
//need to do this in case filtering/layer change has altered matching features
if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
firstFeature();
}
@@ -488,7 +489,7 @@ void QgsAtlasComposition::setHideCoverage( bool hide )
{
mHideCoverage = hide;

if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//an atlas preview is enabled, so reflect changes in coverage layer visibility immediately
QStringList& layerSet = mComposition->mapRenderer()->layerSet();
@@ -541,7 +542,7 @@ void QgsAtlasComposition::updateFilenameExpression()
}

//if atlas preview is currently enabled, regenerate filename for current feature
if ( mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
evalFeatureFilename();
}
@@ -67,7 +67,7 @@ void QgsComposerLabel::paint( QPainter* painter, const QStyleOptionGraphicsItem*
QRectF painterRect( penWidth + mMargin, penWidth + mMargin, rect().width() - 2 * penWidth - 2 * mMargin, rect().height() - 2 * penWidth - 2 * mMargin );

QString textToDraw;
if ( mComposition->plotStyle() != QgsComposition::Preview || mComposition->atlasPreviewEnabled() )
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
{
//render text with expressions evaluated
textToDraw = displayText();
@@ -654,8 +654,7 @@ QgsRectangle* QgsComposerMap::currentMapExtent()

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

if ( atlasMap->enabled() && atlasMap->composerMap() == this &&
( mComposition->atlasPreviewEnabled() || mComposition->plotStyle() != QgsComposition::Preview ) )
if ( atlasMap->composerMap() == this && 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
@@ -673,8 +672,7 @@ const QgsRectangle* QgsComposerMap::currentMapExtent() const
//const version

QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( atlasMap->enabled() && atlasMap->composerMap() == this &&
( mComposition->atlasPreviewEnabled() || mComposition->plotStyle() != QgsComposition::Preview ) )
if ( atlasMap->composerMap() == this && 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
@@ -75,7 +75,7 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer )
, mActiveItemCommand( 0 )
, mActiveMultiFrameCommand( 0 )
, mAtlasComposition( this )
, mAtlasPreviewEnabled( false )
, mAtlasMode( QgsComposition::AtlasOff )
, mPreventCursorChange( false )
{
setBackgroundBrush( QColor( 215, 215, 215 ) );
@@ -121,7 +121,7 @@ QgsComposition::QgsComposition()
mActiveItemCommand( 0 ),
mActiveMultiFrameCommand( 0 ),
mAtlasComposition( this ),
mAtlasPreviewEnabled( false ),
mAtlasMode( QgsComposition::AtlasOff ),
mPreventCursorChange( false )
{
//load default composition settings
@@ -2327,11 +2327,11 @@ void QgsComposition::computeWorldFileParameters( double& a, double& b, double& c
f = r[3] * s[2] + r[4] * s[5] + r[5];
}

bool QgsComposition::setAtlasPreviewEnabled( bool e )
bool QgsComposition::setAtlasMode( QgsComposition::AtlasMode mode )
{
mAtlasPreviewEnabled = e;
mAtlasMode = mode;

if ( !mAtlasPreviewEnabled )
if ( mode == QgsComposition::AtlasOff )
{
mAtlasComposition.endRender();
}
@@ -2340,7 +2340,7 @@ bool QgsComposition::setAtlasPreviewEnabled( bool e )
bool atlasHasFeatures = mAtlasComposition.beginRender();
if ( ! atlasHasFeatures )
{
mAtlasPreviewEnabled = false;
mAtlasMode = QgsComposition::AtlasOff;
return false;
}
}
@@ -90,6 +90,14 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
ZValueAbove
};

/**Composition atlas modes*/
enum AtlasMode
{
AtlasOff, // Composition is not being controlled by an atlas
PreviewAtlas, // An atlas composition is being previewed in the app
ExportAtlas // The composition is being exported as an atlas
};

QgsComposition( QgsMapRenderer* mapRenderer );
~QgsComposition();

@@ -425,11 +433,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Returns a scaled position given a before and after range*/
static double relativePosition( double position, double beforeMin, double beforeMax, double afterMin, double afterMax );

/** Is the atlas preview enabled ? */
bool atlasPreviewEnabled() const { return mAtlasPreviewEnabled; }
/** Set atlas preview enabled. Returns false if atlas preview could not be enabled */
bool setAtlasPreviewEnabled( bool e );

/** Returns the current atlas mode of the composition */
QgsComposition::AtlasMode atlasMode() const { return mAtlasMode; }
/** Sets the current atlas mode of the composition. Returns false if the mode could not be changed. */
bool setAtlasMode( QgsComposition::AtlasMode mode );

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
@@ -497,7 +504,7 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/** The atlas composition object. It is held by the QgsComposition */
QgsAtlasComposition mAtlasComposition;

bool mAtlasPreviewEnabled;
QgsComposition::AtlasMode mAtlasMode;

QgsComposition(); //default constructor is forbidden

@@ -105,7 +105,7 @@ void TestQgsAtlasComposition::initTestCase()
mAtlas = &mComposition->atlasComposition();
mAtlas->setCoverageLayer( mVectorLayer );
mAtlas->setComposerMap( mAtlasMap );
mAtlas->setEnabled( true );
mComposition->setAtlasMode( QgsComposition::ExportAtlas );

// an overview
mOverview = new QgsComposerMap( mComposition, 180, 20, 50, 50 );
@@ -64,7 +64,7 @@ def testCase(self):
self.mAtlas = self.mComposition.atlasComposition()
self.mAtlas.setCoverageLayer( mVectorLayer )
self.mAtlas.setComposerMap( self.mAtlasMap )
self.mAtlas.setEnabled( True )
self.mComposition.setAtlasMode( QgsComposition.ExportAtlas )

# an overview
mOverview = QgsComposerMap( self.mComposition, 180, 20, 50, 50 )

0 comments on commit 22514b6

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