Skip to content

Commit

Permalink
QgsMapSettings and QgsComposerMap store layers for rendering as weak …
Browse files Browse the repository at this point in the history
…pointers

... instead of using layer IDs which need to be resolved using QgsProject
  • Loading branch information
wonder-sk committed Dec 10, 2016
1 parent 64f1356 commit c143be7
Show file tree
Hide file tree
Showing 61 changed files with 340 additions and 281 deletions.
3 changes: 3 additions & 0 deletions doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ QgsComposerLegendItem {#qgis_api_break_3_0_QgsComposerLegendItem}
QgsComposerMap {#qgis_api_break_3_0_QgsComposerMap}
--------------

- layerSet() and setLayerSet() have been replaced by layers() and setLayers() which work with list of layers instead of layer IDs
- containsWMSLayer() has been renamed to containsWmsLayer()
- mapRenderer() has been removed. Use mapSettings() instead.
- All grid style and format enums were moved to QgsComposerMapGrid.
Expand Down Expand Up @@ -1121,6 +1122,7 @@ QgsMapLayerRegistry {#qgis_api_break_3_0_QgsMapLayerRegistry}
QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
--------------------

- layerSet() and setLayerSet() have been replaced by layers() and setLayers() which work with list of layers instead of layer IDs
- destinationSrsChanged() was renamed to destinationCrsChanged()


Expand Down Expand Up @@ -1174,6 +1176,7 @@ The whole class has been refactored to stop using WKB and to use QgsAbstractGeom
QgsMapSettings {#qgis_api_break_3_0_QgsMapSettings}
--------------

- layers() and setLayers() now work with list of layers instead of layer IDs
- layerTransform() now returns a QgsCoordinateTransform object, not a pointer. An invalid QgsCoordinateTransform will
be returned instead of a null pointer if no transformation is required.
- destinationCrs() now returns a copy instead of a reference to the CRS. This has no effect on PyQGIS code, but c++
Expand Down
4 changes: 2 additions & 2 deletions python/core/composer/qgscomposermap.sip
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class QgsComposerMap : QgsComposerItem
void setKeepLayerSet( bool enabled );

/** Getter for stored layer set that is used if mKeepLayerSet is true */
QStringList layerSet() const;
QList<QgsMapLayer*> layers() const;
/** Setter for stored layer set that is used if mKeepLayerSet is true */
void setLayerSet( const QStringList& layerSet );
void setLayers( const QList<QgsMapLayer*> layers );
/** Stores the current layer set of the qgis mapcanvas in mLayerSet*/
void storeCurrentLayerSet();

Expand Down
9 changes: 6 additions & 3 deletions python/core/qgsmapsettings.sip
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ class QgsMapSettings

//! Get list of layer IDs for map rendering
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
QStringList layers() const;
//! Set list of layer IDs for map rendering. The layers must be registered in QgsProject.
QStringList layerIds() const;
//! Get list of layers for map rendering
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
void setLayers( const QStringList& layers );
QList<QgsMapLayer*> layers();
//! Set list of layers for map rendering. The layers must be registered in QgsProject.
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
void setLayers( const QList<QgsMapLayer*>& layers );

//! Get map of map layer style overrides (key: layer ID, value: style name) where a different style should be used instead of the current one
//! @note added in 2.8
Expand Down
5 changes: 3 additions & 2 deletions python/gui/qgsmapoverviewcanvas.sip
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class QgsMapOverviewCanvas : QWidget
void setBackgroundColor( const QColor& color );

//! updates layer set for overview
void setLayerSet( const QStringList& layerSet );
void setLayers( const QList<QgsMapLayer*>& layers );

QStringList layerSet() const;
//! Returns list of layers visible in the overview
QList<QgsMapLayer*> layers() const;

void enableAntiAliasing( bool flag );

Expand Down
7 changes: 3 additions & 4 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ void QgsComposerMapWidget::keepLayersVisibilityPresetSelected()
return;

QString presetName = action->text();
QStringList lst = QgsMapThemes::instance()->orderedPresetVisibleLayers( presetName );
QList<QgsMapLayer*> lst = QgsMapThemes::instance()->orderedPresetVisibleLayers2( presetName );
if ( mComposerMap )
{
mKeepLayerListCheckBox->setChecked( true );
mComposerMap->setLayerSet( lst );
mComposerMap->setLayers( lst );

mKeepLayerStylesCheckBox->setChecked( true );

Expand Down Expand Up @@ -836,8 +836,7 @@ void QgsComposerMapWidget::on_mKeepLayerListCheckBox_stateChanged( int state )
}
else
{
QStringList emptyLayerSet;
mComposerMap->setLayerSet( emptyLayerSet );
mComposerMap->setLayers( QList<QgsMapLayer*>() );
mComposerMap->setKeepLayerSet( false );

mKeepLayerStylesCheckBox->setChecked( Qt::Unchecked );
Expand Down
11 changes: 11 additions & 0 deletions src/app/qgsmapthemes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ QStringList QgsMapThemes::orderedPresetVisibleLayers( const QString& name ) cons
return order2;
}

QList<QgsMapLayer*> QgsMapThemes::orderedPresetVisibleLayers2( const QString& name ) const
{
QList<QgsMapLayer*> lst;
Q_FOREACH ( const QString& layerId, orderedPresetVisibleLayers( name ) )
{
if ( QgsMapLayer* layer = QgsProject::instance()->mapLayer( layerId ) )
lst << layer;
}
return lst;
}

QMenu* QgsMapThemes::menu()
{
return mMenu;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsmapthemes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class APP_EXPORT QgsMapThemes : public QObject
//! The order will match the layer order from the map canvas
QStringList orderedPresetVisibleLayers( const QString& name ) const;

//! Return list of layer IDs that should be visible for particular preset.
//! The order will match the layer order from the map canvas
QList<QgsMapLayer*> orderedPresetVisibleLayers2( const QString& name ) const;

//! Convenience menu that lists available presets and actions for management
QMenu* menu();

Expand Down
Loading

0 comments on commit c143be7

Please sign in to comment.