Skip to content
Permalink
Browse files
[FEATURE] Add atlas preview toggle. Allows for navigating through atl…
…as features and previewing the composition for each feature. Atlas maps can have their extent temporarily tweaked for each atlas feature.
  • Loading branch information
nyalldawson committed Jan 1, 2014
1 parent a596b22 commit 84c3391
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 87 deletions.
@@ -136,6 +136,7 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
if ( mAtlasCoverageLayerComboBox->count() == 1 )
{
atlasMap->setCoverageLayer( vectorLayer );
atlasMap->updateFeatures();
checkLayerType( vectorLayer );
}
}
@@ -191,6 +192,7 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang
{
checkLayerType( layer );
atlasMap->setCoverageLayer( layer );
atlasMap->updateFeatures();
}

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

void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChanged( int index )
@@ -347,6 +350,7 @@ void QgsAtlasCompositionWidget::on_mAtlasSortFeatureKeyComboBox_currentIndexChan
{
atlasMap->setSortKeyAttributeIndex( index );
}
atlasMap->updateFeatures();
}

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

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

atlasMap->setFeatureFilter( text );
atlasMap->updateFeatures();
}

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

atlasMap->setSortAscending( at == Qt::UpArrow );
atlasMap->updateFeatures();
}

void QgsAtlasCompositionWidget::fillSortColumns()
@@ -177,6 +177,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionSmartGuides->setCheckable( true );
mActionShowRulers->setCheckable( true );

mActionAtlasPreview->setCheckable( true );

#ifdef Q_WS_MAC
mActionQuit->setText( tr( "Close" ) );
mActionQuit->setShortcut( QKeySequence::Close );
@@ -467,6 +469,14 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )

mGeneralDock->raise();

//set initial state of atlas controls
mActionAtlasPreview->setEnabled( false );
mActionAtlasPreview->setChecked( false );
mActionAtlasFirst->setEnabled( false );
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
//should not be needed now that composer has a status bar?
#if 0
@@ -754,6 +764,92 @@ void QgsComposer::on_mActionOptions_triggered()
mQgis->showOptionsDialog( this, QString( "mOptionsPageComposer" ) );
}

void QgsComposer::toggleAtlasControls( bool atlasEnabled )
{
//preview defaults to unchecked
mActionAtlasPreview->setChecked( false );
mActionAtlasPreview->setEnabled( atlasEnabled );
}

void QgsComposer::on_mActionAtlasPreview_triggered( bool checked )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();

//check if composition has an atlas map enabled
if ( checked && !atlasMap->enabled() )
{
//no atlas current enabled
QMessageBox::warning( 0, tr( "Enable atlas preview" ),
tr( "Atlas in not currently enabled for this composition!" ),
QMessageBox::Ok,
QMessageBox::Ok );
mActionAtlasPreview->blockSignals( true );
mActionAtlasPreview->setChecked( false );
mActionAtlasPreview->blockSignals( false );
return;
}

//toggle other controls depending on whether atlas preview is active
mActionAtlasFirst->setEnabled( checked );
mActionAtlasLast->setEnabled( checked );
mActionAtlasNext->setEnabled( checked );
mActionAtlasPrev->setEnabled( checked );

mComposition->setAtlasPreviewEnabled( checked );
if ( checked )
{
atlasMap->firstFeature();
}

}


void QgsComposer::on_mActionAtlasNext_triggered()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
{
return;
}

atlasMap->nextFeature();

}

void QgsComposer::on_mActionAtlasPrev_triggered()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
{
return;
}

atlasMap->prevFeature();

}

void QgsComposer::on_mActionAtlasFirst_triggered()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
{
return;
}

atlasMap->firstFeature();
}

void QgsComposer::on_mActionAtlasLast_triggered()
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap->enabled() )
{
return;
}

atlasMap->lastFeature();
}

QgsMapCanvas *QgsComposer::mapCanvas( void )
{
return mQgis->mapCanvas();
@@ -2356,6 +2452,16 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&

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

//set state of atlas controls
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
mActionAtlasPreview->setEnabled( atlasMap->enabled() );
mActionAtlasPreview->setChecked( false );
mActionAtlasFirst->setEnabled( false );
mActionAtlasLast->setEnabled( false );
mActionAtlasNext->setEnabled( false );
mActionAtlasPrev->setEnabled( false );
connect( atlasMap, SIGNAL( toggled( bool ) ), this, SLOT( toggleAtlasControls( bool ) ) );

setSelectionTool();
}

@@ -315,6 +315,21 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Show options dialog
void on_mActionOptions_triggered();

//!Toggle atlas preview
void on_mActionAtlasPreview_triggered( bool checked );

//!Next atlas feature
void on_mActionAtlasNext_triggered();

//!Previous atlas feature
void on_mActionAtlasPrev_triggered();

//!First atlas feature
void on_mActionAtlasFirst_triggered();

//!Last atlas feature
void on_mActionAtlasLast_triggered();

//! Save window state
void saveWindowState();

@@ -518,6 +533,10 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Create a duplicate of a menu (for Mac)
//! @note added in 1.9
QMenu* mirrorOtherMenu( QMenu* otherMenu );

//! Toggles the state of the atlas preview and navigation controls
//! @note added in 2.1
void toggleAtlasControls( bool atlasEnabled );
};

#endif
@@ -186,7 +186,7 @@ void QgsComposerMapWidget::on_mSetToMapCanvasExtentButton_clicked()

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

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

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

0 comments on commit 84c3391

Please sign in to comment.