Skip to content
Permalink
Browse files

Merge pull request #274 from Oslandia/atlas_integration

Add access to the atlas layer in the expression builder GUI for labels.
  • Loading branch information
mhugent committed Oct 6, 2012
2 parents 0d4b6f6 + 9135226 commit 9f0d8581756a2253b723427c5a297e7bd96ba4a3
@@ -253,6 +253,8 @@ class QgsComposition : QGraphicsScene
@note added in version 1.9*/
void renderPage( QPainter* p, int page );

QgsAtlasComposition& atlasComposition();

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );
@@ -22,8 +22,8 @@
#include "qgsexpressionbuilderdialog.h"
#include "qgscomposermap.h"

QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsAtlasComposition* atlas, QgsComposition* c ):
QWidget( parent ), mAtlas( atlas ), mComposition( c )
QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsComposition* c ):
QWidget( parent ), mComposition( c )
{
setupUi( this );

@@ -63,7 +63,7 @@ QgsAtlasCompositionWidget::QgsAtlasCompositionWidget( QWidget* parent, QgsAtlasC
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( onItemRemoved( QgsComposerItem* ) ) );

// connect to updates
connect( mAtlas, SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) );
connect( &mComposition->atlasComposition(), SIGNAL( parameterChanged() ), this, SLOT( updateGuiElements() ) );

updateGuiElements();
}
@@ -74,7 +74,7 @@ QgsAtlasCompositionWidget::~QgsAtlasCompositionWidget()

void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( state == Qt::Checked )
{
atlasMap->setEnabled( true );
@@ -89,6 +89,7 @@ void QgsAtlasCompositionWidget::on_mUseAtlasCheckBox_stateChanged( int state )

void QgsAtlasCompositionWidget::onLayerRemoved( QString layerName )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
// update the atlas coverage layer combo box
for ( int i = 0; i < mAtlasCoverageLayerComboBox->count(); ++i )
{
@@ -100,12 +101,13 @@ void QgsAtlasCompositionWidget::onLayerRemoved( QString layerName )
}
if ( mAtlasCoverageLayerComboBox->count() == 0 )
{
mAtlas->setCoverageLayer( 0 );
atlasMap->setCoverageLayer( 0 );
}
}

void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
// update the atlas coverage layer combo box
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( map );
if ( vectorLayer )
@@ -114,21 +116,23 @@ void QgsAtlasCompositionWidget::onLayerAdded( QgsMapLayer* map )
}
if ( mAtlasCoverageLayerComboBox->count() == 1 )
{
mAtlas->setCoverageLayer( vectorLayer );
atlasMap->setCoverageLayer( vectorLayer );
}
}

void QgsAtlasCompositionWidget::onComposerMapAdded( QgsComposerMap* map )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
mComposerMapComboBox->addItem( tr( "Map %1" ).arg( map->id() ), qVariantFromValue( (void*)map ) );
if ( mComposerMapComboBox->count() == 1 )
{
mAtlas->setComposerMap( map );
atlasMap->setComposerMap( map );
}
}

void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item )
{
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
if ( map )
{
@@ -140,13 +144,13 @@ void QgsAtlasCompositionWidget::onItemRemoved( QgsComposerItem* item )
}
if ( mComposerMapComboBox->count() == 0 )
{
mAtlas->setComposerMap( 0 );
atlasMap->setComposerMap( 0 );
}
}

void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChanged( int index )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -164,7 +168,7 @@ void QgsAtlasCompositionWidget::on_mAtlasCoverageLayerComboBox_currentIndexChang

void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int index )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -182,7 +186,7 @@ void QgsAtlasCompositionWidget::on_mComposerMapComboBox_currentIndexChanged( int

void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const QString& text )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -193,7 +197,7 @@ void QgsAtlasCompositionWidget::on_mAtlasFilenamePatternEdit_textChanged( const

void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap || !atlasMap->coverageLayer() )
{
return;
@@ -214,7 +218,7 @@ void QgsAtlasCompositionWidget::on_mAtlasFilenameExpressionButton_clicked()

void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -224,7 +228,7 @@ void QgsAtlasCompositionWidget::on_mAtlasHideCoverageCheckBox_stateChanged( int

void QgsAtlasCompositionWidget::on_mAtlasFixedScaleCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -244,7 +248,7 @@ void QgsAtlasCompositionWidget::on_mAtlasFixedScaleCheckBox_stateChanged( int st

void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int state )
{
QgsAtlasComposition* atlasMap = mAtlas;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( !atlasMap )
{
return;
@@ -254,7 +258,8 @@ void QgsAtlasCompositionWidget::on_mAtlasSingleFileCheckBox_stateChanged( int st

void QgsAtlasCompositionWidget::updateGuiElements()
{
if ( mAtlas->enabled() )
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( atlasMap->enabled() )
{
mUseAtlasCheckBox->setCheckState( Qt::Checked );
}
@@ -263,22 +268,22 @@ void QgsAtlasCompositionWidget::updateGuiElements()
mUseAtlasCheckBox->setCheckState( Qt::Unchecked );
}

int idx = mAtlasCoverageLayerComboBox->findData( qVariantFromValue( (void*)mAtlas->coverageLayer() ));
int idx = mAtlasCoverageLayerComboBox->findData( qVariantFromValue( (void*)atlasMap->coverageLayer() ));
if ( idx != -1 )
{
mAtlasCoverageLayerComboBox->setCurrentIndex( idx );
}
idx = mComposerMapComboBox->findData( qVariantFromValue( (void*)mAtlas->composerMap() ));
idx = mComposerMapComboBox->findData( qVariantFromValue( (void*)atlasMap->composerMap() ));
if ( idx != -1 )
{
mComposerMapComboBox->setCurrentIndex( idx );
}

mAtlasMarginSpinBox->setValue( static_cast<int>(mAtlas->margin() * 100) );
mAtlasFilenamePatternEdit->setText( mAtlas->filenamePattern() );
mAtlasFixedScaleCheckBox->setCheckState( mAtlas->fixedScale() ? Qt::Checked : Qt::Unchecked );
mAtlasHideCoverageCheckBox->setCheckState( mAtlas->hideCoverage() ? Qt::Checked : Qt::Unchecked );
mAtlasSingleFileCheckBox->setCheckState( mAtlas->singleFile() ? Qt::Checked : Qt::Unchecked );
mAtlasMarginSpinBox->setValue( static_cast<int>(atlasMap->margin() * 100) );
mAtlasFilenamePatternEdit->setText( atlasMap->filenamePattern() );
mAtlasFixedScaleCheckBox->setCheckState( atlasMap->fixedScale() ? Qt::Checked : Qt::Unchecked );
mAtlasHideCoverageCheckBox->setCheckState( atlasMap->hideCoverage() ? Qt::Checked : Qt::Unchecked );
mAtlasSingleFileCheckBox->setCheckState( atlasMap->singleFile() ? Qt::Checked : Qt::Unchecked );
}

void QgsAtlasCompositionWidget::blockAllSignals( bool b )
@@ -17,7 +17,6 @@
#include "ui_qgsatlascompositionwidgetbase.h"

class QgsComposition;
class QgsAtlasComposition;
class QgsMapLayer;
class QgsComposerMap;
class QgsComposerItem;
@@ -31,7 +30,7 @@ class QgsAtlasCompositionWidget:
{
Q_OBJECT
public:
QgsAtlasCompositionWidget( QWidget* parent, QgsAtlasComposition* atlas, QgsComposition* c );
QgsAtlasCompositionWidget( QWidget* parent, QgsComposition* c );
~QgsAtlasCompositionWidget();

public slots:
@@ -53,7 +52,6 @@ private slots:
void updateGuiElements();

private:
QgsAtlasComposition* mAtlas;
QgsComposition* mComposition;

void blockAllSignals( bool b );
@@ -286,8 +286,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
addDockWidget( Qt::RightDockWidgetArea, mUndoDock );
addDockWidget( Qt::RightDockWidgetArea, mAtlasDock );

mAtlasComposition = new QgsAtlasComposition( mComposition );
QgsAtlasCompositionWidget* atlasWidget = new QgsAtlasCompositionWidget( mGeneralDock, mAtlasComposition, mComposition );
QgsAtlasCompositionWidget* atlasWidget = new QgsAtlasCompositionWidget( mGeneralDock, mComposition );
mAtlasDock->setWidget( atlasWidget );

mItemDock->show();
@@ -325,7 +324,6 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
QgsComposer::~QgsComposer()
{
deleteItemWidgets();
delete mAtlasComposition;
}

void QgsComposer::setupTheme()
@@ -581,9 +579,9 @@ void QgsComposer::on_mActionExportAsPDF_triggered()
showWMSPrintingWarning();
}

bool hasAnAtlas = mAtlasComposition->enabled();
bool atlasOnASingleFile = hasAnAtlas && mAtlasComposition->singleFile();
QgsAtlasComposition* atlasMap = mAtlasComposition;
bool hasAnAtlas = mComposition->atlasComposition().enabled();
bool atlasOnASingleFile = hasAnAtlas && mComposition->atlasComposition().singleFile();
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();

QString outputFileName;
QString outputDir;
@@ -747,7 +745,7 @@ void QgsComposer::on_mActionPrint_triggered()
QApplication::setOverrideCursor( Qt::BusyCursor );
mView->setPaintingEnabled( false );

QgsAtlasComposition* atlasMap = mAtlasComposition;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( atlasMap == 0 )
{
mComposition->print( mPrinter );
@@ -831,7 +829,7 @@ void QgsComposer::on_mActionExportAsImage_triggered()
return;
}

QgsAtlasComposition* atlasMap = mAtlasComposition;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
if ( 0 == atlasMap )
{
QPair<QString, QString> fileNExt = QgisGui::getSaveAsImageName( this, tr( "Choose a file name to save the map image as" ) );
@@ -1027,7 +1025,7 @@ void QgsComposer::on_mActionExportAsSVG_triggered()
m->exec();
}

QgsAtlasComposition* atlasMap = mAtlasComposition;
QgsAtlasComposition* atlasMap = &mComposition->atlasComposition();
bool hasAnAtlas = atlasMap->enabled();

QString outputFileName;
@@ -1561,7 +1559,7 @@ void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
}

// store atlas
mAtlasComposition->writeXML( composerElem, doc );
mComposition->atlasComposition().writeXML( composerElem, doc );
}

void QgsComposer::readXML( const QDomDocument& doc )
@@ -1647,16 +1645,12 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
// atlas properties reading
QDomNodeList atlasNodeList = composerElem.elementsByTagName( "Atlas" );

// delete the old atlas object
delete mAtlasComposition;
mAtlasComposition = new QgsAtlasComposition( mComposition );

//delete old atlas composition widget
QgsAtlasCompositionWidget* oldAtlasWidget = qobject_cast<QgsAtlasCompositionWidget *>( mAtlasDock->widget() );
delete oldAtlasWidget;
mAtlasDock->setWidget( new QgsAtlasCompositionWidget( mAtlasDock, mAtlasComposition, mComposition ) );
mAtlasDock->setWidget( new QgsAtlasCompositionWidget( mAtlasDock, mComposition ) );

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

setSelectionTool();
}
@@ -312,9 +312,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Current composition
QgsComposition *mComposition;

//! Atlas map
QgsAtlasComposition* mAtlasComposition;

//! Pointer to QGIS application
QgisApp *mQgis;

@@ -113,7 +113,13 @@ void QgsComposerLabelWidget::on_mInsertExpressionButton_clicked()
if ( selText.startsWith( "[%" ) && selText.endsWith( "%]" ) )
selText = selText.mid( 2, selText.size() - 4 );

QgsExpressionBuilderDialog exprDlg( /* layer = */ 0, selText, this );
QgsVectorLayer* coverageLayer = 0;
// use the atlas coverage layer, if any
if ( mComposerLabel->composition()->atlasComposition().enabled() )
{
coverageLayer = mComposerLabel->composition()->atlasComposition().coverageLayer();
}
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this );
exprDlg.setWindowTitle( tr( "Insert expression" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
@@ -49,7 +49,8 @@

QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ) :
QGraphicsScene( 0 ), mMapRenderer( mapRenderer ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ), mSelectionTolerance( 0.0 ),
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 )
mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
mAtlasComposition( this )
{
setBackgroundBrush( Qt::gray );
addPaperItem();
@@ -60,7 +61,8 @@ QgsComposition::QgsComposition( QgsMapRenderer* mapRenderer ) :

QgsComposition::QgsComposition():
QGraphicsScene( 0 ), mMapRenderer( 0 ), mPlotStyle( QgsComposition::Preview ), mPageWidth( 297 ), mPageHeight( 210 ), mSpaceBetweenPages( 10 ), mPrintAsRaster( false ),
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 )
mSelectionTolerance( 0.0 ), mSnapToGrid( false ), mSnapGridResolution( 0.0 ), mSnapGridOffsetX( 0.0 ), mSnapGridOffsetY( 0.0 ), mActiveItemCommand( 0 ), mActiveMultiFrameCommand( 0 ),
mAtlasComposition( this )
{
loadSettings();
}
@@ -28,6 +28,7 @@

#include "qgsaddremoveitemcommand.h"
#include "qgscomposeritemcommand.h"
#include "qgsatlascomposition.h"

class QgsComposerFrame;
class QgsComposerItem;
@@ -303,6 +304,8 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
@note added in version 1.9*/
void renderPage( QPainter* p, int page );

QgsAtlasComposition& atlasComposition() { return mAtlasComposition; }

public slots:
/**Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );
@@ -344,6 +347,9 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene
QgsComposerItemCommand* mActiveItemCommand;
QgsComposerMultiFrameCommand* mActiveMultiFrameCommand;

/** The atlas composition object. It is held by the QgsComposition */
QgsAtlasComposition mAtlasComposition;

QgsComposition(); //default constructor is forbidden

/**Reset z-values of items based on position in z list*/

0 comments on commit 9f0d858

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