Skip to content

Commit 84c3391

Browse files
committed
[FEATURE] Add atlas preview toggle. Allows for navigating through atlas features and previewing the composition for each feature. Atlas maps can have their extent temporarily tweaked for each atlas feature.
1 parent a596b22 commit 84c3391

16 files changed

+513
-87
lines changed

src/app/composer/qgsatlascompositionwidget.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
136136
if ( mAtlasCoverageLayerComboBox->count() == 1 )
137137
{
138138
atlasMap->setCoverageLayer( vectorLayer );
139+
atlasMap->updateFeatures();
139140
checkLayerType( vectorLayer );
140141
}
141142
}
@@ -191,6 +192,7 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
191192
{
192193
checkLayerType( layer );
193194
atlasMap->setCoverageLayer( layer );
195+
atlasMap->updateFeatures();
194196
}
195197

196198
// update sorting columns
@@ -333,6 +335,7 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureCheckBox_stateChanged( int s
333335
mAtlasSortFeatureKeyComboBox->setEnabled( false );
334336
}
335337
atlasMap->setSortFeatures( state == Qt::Checked );
338+
atlasMap->updateFeatures();
336339
}
337340

338341
void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChanged( int index )
@@ -347,6 +350,7 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChan
347350
{
348351
atlasMap->setSortKeyAttributeIndex( index );
349352
}
353+
atlasMap->updateFeatures();
350354
}
351355

352356
void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterCheckBox_stateChanged( int state )
@@ -368,6 +372,7 @@ void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterCheckBox_stateChanged( int
368372
mAtlasFeatureFilterButton->setEnabled( false );
369373
}
370374
atlasMap->setFilterFeatures( state == Qt::Checked );
375+
atlasMap->updateFeatures();
371376
}
372377

373378
void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_textChanged( const QString& text )
@@ -379,6 +384,7 @@ void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterEdit_textChanged( const QS
379384
}
380385

381386
atlasMap->setFeatureFilter( text );
387+
atlasMap->updateFeatures();
382388
}
383389

384390
void QgsAtlasCompositionWidget::on_mAtlasFeatureFilterButton_clicked()
@@ -415,6 +421,7 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureDirectionButton_clicked()
415421
}
416422

417423
atlasMap->setSortAscending( at == Qt::UpArrow );
424+
atlasMap->updateFeatures();
418425
}
419426

420427
void QgsAtlasCompositionWidget::fillSortColumns()

src/app/composer/qgscomposer.cpp

+106
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
177177
mActionSmartGuides->setCheckable( true );
178178
mActionShowRulers->setCheckable( true );
179179

180+
mActionAtlasPreview->setCheckable( true );
181+
180182
#ifdef Q_WS_MAC
181183
mActionQuit->setText( tr( "Close" ) );
182184
mActionQuit->setShortcut( QKeySequence::Close );
@@ -467,6 +469,14 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
467469

468470
mGeneralDock->raise();
469471

472+
//set initial state of atlas controls
473+
mActionAtlasPreview->setEnabled( false );
474+
mActionAtlasPreview->setChecked( false );
475+
mActionAtlasFirst->setEnabled( false );
476+
mActionAtlasLast->setEnabled( false );
477+
mActionAtlasNext->setEnabled( false );
478+
mActionAtlasPrev->setEnabled( false );
479+
470480
// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
471481
//should not be needed now that composer has a status bar?
472482
#if 0
@@ -754,6 +764,92 @@ void QgsComposer::on_mActionOptions_triggered()
754764
mQgis->showOptionsDialog( this, QString( "mOptionsPageComposer" ) );
755765
}
756766

767+
void QgsComposer::toggleAtlasControls( bool atlasEnabled )
768+
{
769+
//preview defaults to unchecked
770+
mActionAtlasPreview->setChecked( false );
771+
mActionAtlasPreview->setEnabled( atlasEnabled );
772+
}
773+
774+
void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
775+
{
776+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
777+
778+
//check if composition has an atlas map enabled
779+
if ( checked && !atlasMap->enabled() )
780+
{
781+
//no atlas current enabled
782+
QMessageBox::warning( 0, tr( "Enable atlas preview" ),
783+
tr( "Atlas in not currently enabled for this composition!" ),
784+
QMessageBox::Ok,
785+
QMessageBox::Ok );
786+
mActionAtlasPreview->blockSignals( true );
787+
mActionAtlasPreview->setChecked( false );
788+
mActionAtlasPreview->blockSignals( false );
789+
return;
790+
}
791+
792+
//toggle other controls depending on whether atlas preview is active
793+
mActionAtlasFirst->setEnabled( checked );
794+
mActionAtlasLast->setEnabled( checked );
795+
mActionAtlasNext->setEnabled( checked );
796+
mActionAtlasPrev->setEnabled( checked );
797+
798+
mComposition->setAtlasPreviewEnabled( checked );
799+
if ( checked )
800+
{
801+
atlasMap->firstFeature();
802+
}
803+
804+
}
805+
806+
807+
void QgsComposer::on_mActionAtlasNext_triggered()
808+
{
809+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
810+
if ( !atlasMap->enabled() )
811+
{
812+
return;
813+
}
814+
815+
atlasMap->nextFeature();
816+
817+
}
818+
819+
void QgsComposer::on_mActionAtlasPrev_triggered()
820+
{
821+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
822+
if ( !atlasMap->enabled() )
823+
{
824+
return;
825+
}
826+
827+
atlasMap->prevFeature();
828+
829+
}
830+
831+
void QgsComposer::on_mActionAtlasFirst_triggered()
832+
{
833+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
834+
if ( !atlasMap->enabled() )
835+
{
836+
return;
837+
}
838+
839+
atlasMap->firstFeature();
840+
}
841+
842+
void QgsComposer::on_mActionAtlasLast_triggered()
843+
{
844+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
845+
if ( !atlasMap->enabled() )
846+
{
847+
return;
848+
}
849+
850+
atlasMap->lastFeature();
851+
}
852+
757853
QgsMapCanvas *QgsComposer::mapCanvas( void )
758854
{
759855
return mQgis->mapCanvas();
@@ -2356,6 +2452,16 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
23562452

23572453
mComposition->atlasComposition().readXML( atlasNodeList.at( 0 ).toElement(), doc );
23582454

2455+
//set state of atlas controls
2456+
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
2457+
mActionAtlasPreview->setEnabled( atlasMap->enabled() );
2458+
mActionAtlasPreview->setChecked( false );
2459+
mActionAtlasFirst->setEnabled( false );
2460+
mActionAtlasLast->setEnabled( false );
2461+
mActionAtlasNext->setEnabled( false );
2462+
mActionAtlasPrev->setEnabled( false );
2463+
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );
2464+
23592465
setSelectionTool();
23602466
}
23612467

src/app/composer/qgscomposer.h

+19
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
315315
//!Show options dialog
316316
void on_mActionOptions_triggered();
317317

318+
//!Toggle atlas preview
319+
void on_mActionAtlasPreview_triggered( bool checked );
320+
321+
//!Next atlas feature
322+
void on_mActionAtlasNext_triggered();
323+
324+
//!Previous atlas feature
325+
void on_mActionAtlasPrev_triggered();
326+
327+
//!First atlas feature
328+
void on_mActionAtlasFirst_triggered();
329+
330+
//!Last atlas feature
331+
void on_mActionAtlasLast_triggered();
332+
318333
//! Save window state
319334
void saveWindowState();
320335

@@ -518,6 +533,10 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
518533
//! Create a duplicate of a menu (for Mac)
519534
//! @note added in 1.9
520535
QMenu* mirrorOtherMenu( QMenu* otherMenu );
536+
537+
//! Toggles the state of the atlas preview and navigation controls
538+
//! @note added in 2.1
539+
void toggleAtlasControls( bool atlasEnabled );
521540
};
522541

523542
#endif

src/app/composer/qgscomposermapwidget.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()
186186

187187
//Make sure the width/height ratio is the same as in current composer map extent.
188188
//This is to keep the map item frame and the page layout fixed
189-
QgsRectangle currentMapExtent = mComposerMap->extent();
189+
QgsRectangle currentMapExtent = *( mComposerMap->currentMapExtent() );
190190
double currentWidthHeightRatio = currentMapExtent.width() / currentMapExtent.height();
191191
double newWidthHeightRatio = newExtent.width() / newExtent.height();
192192

@@ -285,7 +285,7 @@ void QgsComposerMapWidget::updateGuiElements()
285285
}
286286

287287
//composer map extent
288-
QgsRectangle composerMapExtent = mComposerMap->extent();
288+
QgsRectangle composerMapExtent = *( mComposerMap->currentMapExtent() );
289289
mXMinLineEdit->setText( QString::number( composerMapExtent.xMinimum(), 'f', 3 ) );
290290
mXMaxLineEdit->setText( QString::number( composerMapExtent.xMaximum(), 'f', 3 ) );
291291
mYMinLineEdit->setText( QString::number( composerMapExtent.yMinimum(), 'f', 3 ) );

0 commit comments

Comments
 (0)