Skip to content

Commit

Permalink
Remove hack to get composer maps to follow canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent 041129d commit ce3c854
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 36 deletions.
17 changes: 0 additions & 17 deletions src/app/composer/qgscomposer.cpp
Expand Up @@ -853,23 +853,6 @@ bool QgsComposer::loadFromTemplate( const QDomDocument &templateDoc, bool clearE
return result;
}

void QgsComposer::onCanvasLayersChanged( const QList<QgsMapLayer *> &layers )
{
if ( !mComposition )
return;

QList< QgsComposerMap * > maps;
mComposition->composerItems( maps );

Q_FOREACH ( QgsComposerMap *map, maps )
{
if ( map->keepLayerSet() )
continue;

map->setLayers( layers );
}
}

void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
{
if ( !mComposition )
Expand Down
10 changes: 0 additions & 10 deletions src/app/composer/qgscomposer.h
Expand Up @@ -133,16 +133,6 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! @note added in 2.1
void setAtlasFeature( QgsMapLayer *layer, const QgsFeature &feat );

public slots:

/**
* Should be called whenever the app's canvas layers change (or layer order
* changes). Required to update composer maps which are synced to the canvas
* layer set with the new canvas layer set.
* @note added in QGIS 3.0
*/
void onCanvasLayersChanged( const QList< QgsMapLayer * > &layers );

protected:
//! Move event
virtual void moveEvent( QMoveEvent * ) override;
Expand Down
4 changes: 4 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -908,6 +908,10 @@ void QgsComposerMapWidget::on_mKeepLayerListCheckBox_stateChanged( int state )
// update map
storeCurrentLayerSet();
mComposerMap->setKeepLayerSet( state == Qt::Checked );
if ( state == Qt::Unchecked )
{
mComposerMap->setLayers( QList< QgsMapLayer * >() );
}

// update gui
if ( state == Qt::Checked )
Expand Down
8 changes: 6 additions & 2 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -475,12 +475,16 @@ QList<QgsMapLayer *> QgsComposerMap::layersToRender( const QgsExpressionContext
if ( mComposition->project()->mapThemeCollection()->hasMapTheme( presetName ) )
renderLayers = mComposition->project()->mapThemeCollection()->mapThemeVisibleLayers( presetName );
else // fallback to using map canvas layers
renderLayers = layers();
renderLayers = mComposition->project()->mapThemeCollection()->masterVisibleLayers();
}
else
else if ( !layers().isEmpty() )
{
renderLayers = layers();
}
else
{
renderLayers = mComposition->project()->mapThemeCollection()->masterVisibleLayers();
}

bool ok = false;
QString ddLayers = mDataDefinedProperties.valueAsString( QgsComposerObject::MapLayers, *evalContext, QString(), &ok );
Expand Down
16 changes: 10 additions & 6 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -205,31 +205,35 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

/**
* Getter for flag that determines if a stored layer set should be used
* or the current layer set of the QGIS map canvas.
* or the current layer set of the QGIS map canvas. This is just a GUI flag,
* and itself does not change which layers are rendered in the map.
* Instead, use setLayers() to control which layers are rendered.
* @see setKeepLayerSet()
* @see layers()
*/
bool keepLayerSet() const {return mKeepLayerSet;}

/**
* Setter for flag that determines if the stored layer set should be used
* or the current layer set of the QGIS map canvas.
* or the current layer set of the QGIS map canvas. This is just a GUI flag,
* and itself does not change which layers are rendered in the map.
* Instead, use setLayers() to control which layers are rendered.
* @see keepLayerSet()
* @see layers()
*/
void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}

/**
* Getter for stored layer set. This will usually be synchronized with the main app canvas
* layer set (and layer order), unless the keepLayerSet() flag is true.
* Getter for stored layer set. If empty, the current canvas layers will
* be used instead.
* @see setLayers()
* @see keepLayerSet()
*/
QList<QgsMapLayer *> layers() const;

/**
* Setter for stored layer set. This will usually be synchronized with the main app canvas
* layer set (and layer order), unless the keepLayerSet() flag is true.
* Setter for stored layer set. If empty, the current canvas layers will
* be used instead.
* @see layers()
* @see keepLayerSet()
*/
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgscomposerview.cpp
Expand Up @@ -1001,7 +1001,6 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent *e )
if ( mCanvas )
{
composerMap->zoomToExtent( mCanvas->mapSettings().visibleExtent() );
composerMap->setLayers( mCanvas->mapSettings().layers() );
}

composition()->addComposerMap( composerMap );
Expand Down

0 comments on commit ce3c854

Please sign in to comment.