Skip to content
Permalink
Browse files
Remove hack to get composer maps to follow canvas
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent 041129d commit ce3c854fd224959ebfe8b51054ec3e3c781f805d
@@ -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 )
@@ -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;
@@ -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 )
@@ -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 );
@@ -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()
*/
@@ -1001,7 +1001,6 @@ void QgsComposerView::mouseReleaseEvent( QMouseEvent *e )
if ( mCanvas )
{
composerMap->zoomToExtent( mCanvas->mapSettings().visibleExtent() );
composerMap->setLayers( mCanvas->mapSettings().layers() );
}

composition()->addComposerMap( composerMap );

0 comments on commit ce3c854

Please sign in to comment.