Skip to content

Commit a188d14

Browse files
committed
Remove map settings parameter from QgsComposition
Breaks the hard link between canvas and compositions! Fix #11077
1 parent b41f3a7 commit a188d14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+126
-236
lines changed

doc/api_break.dox

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,10 @@ to use the QgsProperty framework objects.
660660
QgsComposition {#qgis_api_break_3_0_QgsComposition}
661661
--------------
662662

663-
- constructor requires QgsProject instance as the second argument
663+
- The constructor no longer takes a reference to a QgsMapSettings object. This is no longer
664+
used by compositions. To set the layers to show in composer maps, the QgsComposerMap::setLayers()
665+
method should be used instead.
666+
- constructor requires QgsProject instance
664667
- addItemsFromXML() has been renamed to addItemsFromXml()
665668
- Constructor with QgsMapRenderer parameter has been removed. Use the variant with QgsMapSettings parameter.
666669
- mapRenderer() has been removed. Use mapSettings() instead.
@@ -674,6 +677,7 @@ were removed. Use setSnapTolerance() and snapTolerance() instead.
674677
- worldFileMap() and setWorldFileMap() have been renamed to referenceMap() and setReferenceMap()
675678
- dataDefinedProperty() and setDataDefinedProperty() now use the QgsProperty framework instead
676679
of QgsDataDefined objects.
680+
- mapSettings() was removed. Use QgsComposerMap::mapSettings() instead.
677681

678682

679683
QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}

python/core/composer/qgscomposition.sip

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
4040
Landscape
4141
};
4242

43-
explicit QgsComposition( const QgsMapSettings& mapSettings, QgsProject* project );
43+
explicit QgsComposition( QgsProject* project );
4444

4545
/** Composition atlas modes*/
4646
enum AtlasMode
@@ -366,10 +366,6 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
366366
/** Used to enable or disable advanced effects such as blend modes in a composition */
367367
void setUseAdvancedEffects( const bool effectsEnabled );
368368

369-
//! Return setting of QGIS map canvas
370-
//! @note added in 2.4
371-
const QgsMapSettings& mapSettings() const;
372-
373369
QgsComposition::PlotStyle plotStyle() const;
374370
void setPlotStyle( const QgsComposition::PlotStyle style );
375371

src/app/composer/qgscomposer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
547547
connect( mActionShowRulers, SIGNAL( triggered( bool ) ), this, SLOT( toggleRulers( bool ) ) );
548548

549549
//init undo/redo buttons
550-
mComposition = new QgsComposition( mQgis->mapCanvas()->mapSettings(), QgsProject::instance() );
550+
mComposition = new QgsComposition( QgsProject::instance() );
551551

552552
mActionUndo->setEnabled( false );
553553
mActionRedo->setEnabled( false );
@@ -3560,7 +3560,7 @@ void QgsComposer::readXml( const QDomElement& composerElem, const QDomDocument&
35603560
createComposerView();
35613561

35623562
//read composition settings
3563-
mComposition = new QgsComposition( mQgis->mapCanvas()->mapSettings(), QgsProject::instance() );
3563+
mComposition = new QgsComposition( QgsProject::instance() );
35643564
QDomNodeList compositionNodeList = composerElem.elementsByTagName( QStringLiteral( "Composition" ) );
35653565
if ( compositionNodeList.size() > 0 )
35663566
{

src/core/composer/qgscomposition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@
6060
#include "gdal.h"
6161
#include "cpl_conv.h"
6262

63-
QgsComposition::QgsComposition( const QgsMapSettings& mapSettings, QgsProject* project )
63+
QgsComposition::QgsComposition( QgsProject* project )
6464
: QGraphicsScene( nullptr )
65-
, mMapSettings( mapSettings )
6665
, mProject( project )
6766
, mAtlasComposition( this )
6867
{

src/core/composer/qgscomposition.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
104104
Landscape
105105
};
106106

107-
//! Construct a composition, using given map settings and project
108-
explicit QgsComposition( const QgsMapSettings& mapSettings, QgsProject* project );
107+
/**
108+
* Construct a new composition linked to the specified project.
109+
*/
110+
explicit QgsComposition( QgsProject* project );
109111

110112
//! Composition atlas modes
111113
enum AtlasMode
@@ -443,10 +445,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
443445
//! Used to enable or disable advanced effects such as blend modes in a composition
444446
void setUseAdvancedEffects( const bool effectsEnabled );
445447

446-
//! Return setting of QGIS map canvas
447-
//! @note added in 2.4
448-
const QgsMapSettings& mapSettings() const { return mMapSettings; }
449-
450448
QgsComposition::PlotStyle plotStyle() const { return mPlotStyle; }
451449
void setPlotStyle( const QgsComposition::PlotStyle style ) { mPlotStyle = style; }
452450

@@ -862,8 +860,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
862860

863861

864862
private:
865-
//! Reference to map settings of QGIS main map
866-
const QgsMapSettings& mMapSettings;
867863

868864
//! Pointer to associated project (not null)
869865
QgsProject* mProject;

src/plugins/georeferencer/qgsgeorefplugingui.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ bool QgsGeorefPluginGui::writePDFMapFile( const QString& fileName, const QgsGeor
15221522
double paperHeight = s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/HeightPDFMap" ), "420" ).toDouble();
15231523

15241524
//create composition
1525-
QgsComposition* composition = new QgsComposition( mCanvas->mapSettings(), QgsProject::instance() );
1525+
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
15261526
if ( mapRatio >= 1 )
15271527
{
15281528
composition->setPaperSize( paperHeight, paperWidth );
@@ -1589,7 +1589,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
15891589
}
15901590

15911591
//create composition A4 with 300 dpi
1592-
QgsComposition* composition = new QgsComposition( mCanvas->mapSettings(), QgsProject::instance() );
1592+
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
15931593
composition->setPaperSize( 210, 297 ); //A4
15941594
composition->setPrintResolution( 300 );
15951595
composition->setNumPages( 2 );

src/server/qgswmsprojectparser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "qgspallabeling.h"
2727
#include "qgsrenderer.h"
2828
#include "qgsvectorlayer.h"
29+
#include "qgsmapsettings.h"
2930

3031
#include "qgscomposition.h"
3132
#include "qgscomposerarrow.h"
@@ -475,7 +476,7 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem
475476
return nullptr;
476477
}
477478

478-
QgsComposition* composition = new QgsComposition( mapSettings, QgsProject::instance() ); //set resolution, paper size from composer element attributes
479+
QgsComposition* composition = new QgsComposition( QgsProject::instance() ); //set resolution, paper size from composer element attributes
479480
if ( !composition->readXml( compositionElem, *( mProjectParser->xmlDocument() ) ) )
480481
{
481482
delete composition;
@@ -503,6 +504,8 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem
503504
QgsComposerMap* map = qobject_cast< QgsComposerMap *>( *itemIt );
504505
if ( map )
505506
{
507+
if ( !map->keepLayerSet() )
508+
map->setLayers( mapSettings.layers() );
506509
mapList.push_back( map );
507510
continue;
508511
}

tests/src/core/testqgs25drenderer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ void TestQgs25DRenderer::render()
126126

127127
void TestQgs25DRenderer::renderComposition()
128128
{
129-
QgsComposition* composition = new QgsComposition( mMapSettings, QgsProject::instance() );
129+
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
130130
composition->setPaperSize( 297, 210 ); //A4 landscape
131131
QgsComposerMap* map = new QgsComposerMap( composition, 20, 20, 200, 100 );
132132
map->setFrameEnabled( true );
133+
map->setLayers( QList< QgsMapLayer* >() << mpPolysLayer );
133134
composition->addComposerMap( map );
134135

135136
map->setNewExtent( mpPolysLayer->extent() );

tests/src/core/testqgsatlascomposition.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class TestQgsAtlasComposition : public QObject
4343
, mLabel2( 0 )
4444
, mAtlasMap( 0 )
4545
, mOverview( 0 )
46-
, mMapSettings( 0 )
4746
, mVectorLayer( 0 )
4847
, mVectorLayer2( 0 )
4948
, mAtlas( 0 )
@@ -84,7 +83,6 @@ class TestQgsAtlasComposition : public QObject
8483
QgsComposerLabel* mLabel2;
8584
QgsComposerMap* mAtlasMap;
8685
QgsComposerMap* mOverview;
87-
QgsMapSettings *mMapSettings;
8886
QgsVectorLayer* mVectorLayer;
8987
QgsVectorLayer* mVectorLayer2;
9088
QgsAtlasComposition* mAtlas;
@@ -96,8 +94,6 @@ void TestQgsAtlasComposition::initTestCase()
9694
QgsApplication::init();
9795
QgsApplication::initQgis();
9896

99-
mMapSettings = new QgsMapSettings();
100-
10197
//create maplayers from testdata and add to layer registry
10298
QFileInfo vectorFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/france_parts.shp" );
10399
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
@@ -115,9 +111,7 @@ void TestQgsAtlasComposition::initTestCase()
115111
}
116112

117113
TestQgsAtlasComposition::~TestQgsAtlasComposition()
118-
{
119-
delete mMapSettings;
120-
}
114+
{}
121115

122116

123117
void TestQgsAtlasComposition::cleanupTestCase()
@@ -139,15 +133,12 @@ void TestQgsAtlasComposition::cleanupTestCase()
139133
void TestQgsAtlasComposition::init()
140134
{
141135
//create composition with composer map
142-
mMapSettings->setLayers( QList<QgsMapLayer*>() << mVectorLayer );
143-
mMapSettings->setCrsTransformEnabled( true );
144-
mMapSettings->setMapUnits( QgsUnitTypes::DistanceMeters );
145136

146137
// select epsg:2154
147138
QgsCoordinateReferenceSystem crs;
148139
crs.createFromSrid( 2154 );
149140
QgsProject::instance()->setCrs( crs );
150-
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
141+
mComposition = new QgsComposition( QgsProject::instance() );
151142
mComposition->setPaperSize( 297, 210 ); //A4 landscape
152143

153144
// fix the renderer, fill with green
@@ -163,6 +154,7 @@ void TestQgsAtlasComposition::init()
163154
// Make sure it doesn't try to render a map for caching onto a still 0-sized image
164155
mAtlasMap->setPreviewMode( QgsComposerMap::Rectangle );
165156
mComposition->addComposerMap( mAtlasMap, false );
157+
mAtlasMap->setLayers( QList<QgsMapLayer*>() << mVectorLayer );
166158

167159
mAtlas = &mComposition->atlasComposition();
168160
mAtlas->setCoverageLayer( mVectorLayer );
@@ -174,6 +166,7 @@ void TestQgsAtlasComposition::init()
174166
mOverview->setFrameEnabled( true );
175167
mOverview->overview()->setFrameMap( mAtlasMap->id() );
176168
mOverview->setPreviewMode( QgsComposerMap::Rectangle );
169+
mOverview->setLayers( QList<QgsMapLayer*>() << mVectorLayer );
177170
mComposition->addComposerMap( mOverview, false );
178171
mOverview->setNewExtent( QgsRectangle( 49670.718, 6415139.086, 699672.519, 7065140.887 ) );
179172

tests/src/core/testqgscomposerdd.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class TestQgsComposerDD : public QObject
3838
public:
3939
TestQgsComposerDD()
4040
: mComposition( 0 )
41-
, mMapSettings( 0 )
4241
, mVectorLayer( 0 )
4342
, mAtlasMap( 0 )
4443
, mAtlas( 0 )
@@ -54,7 +53,6 @@ class TestQgsComposerDD : public QObject
5453

5554
private:
5655
QgsComposition *mComposition;
57-
QgsMapSettings *mMapSettings;
5856
QgsVectorLayer* mVectorLayer;
5957
QgsComposerMap* mAtlasMap;
6058
QgsAtlasComposition* mAtlas;
@@ -66,8 +64,6 @@ void TestQgsComposerDD::initTestCase()
6664
QgsApplication::init();
6765
QgsApplication::initQgis();
6866

69-
mMapSettings = new QgsMapSettings();
70-
7167
//create maplayers from testdata and add to layer registry
7268
QFileInfo vectorFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/france_parts.shp" );
7369
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
@@ -79,15 +75,11 @@ void TestQgsComposerDD::initTestCase()
7975
mVectorLayer->setSimplifyMethod( simplifyMethod );
8076

8177
//create composition with composer map
82-
mMapSettings->setLayers( QList<QgsMapLayer*>() << mVectorLayer );
83-
mMapSettings->setCrsTransformEnabled( true );
84-
mMapSettings->setMapUnits( QgsUnitTypes::DistanceMeters );
8578

8679
// select epsg:2154
8780
QgsCoordinateReferenceSystem crs;
8881
crs.createFromSrid( 2154 );
89-
mMapSettings->setDestinationCrs( crs );
90-
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
82+
mComposition = new QgsComposition( QgsProject::instance() );
9183
mComposition->setPaperSize( 297, 210 ); //A4 landscape
9284

9385
// fix the renderer, fill with green
@@ -114,7 +106,6 @@ void TestQgsComposerDD::initTestCase()
114106
void TestQgsComposerDD::cleanupTestCase()
115107
{
116108
delete mComposition;
117-
delete mMapSettings;
118109
delete mVectorLayer;
119110

120111
QString myReportFile = QDir::tempPath() + "/qgistest.html";

tests/src/core/testqgscomposereffects.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class TestQgsComposerEffects : public QObject
3434
: mComposition( 0 )
3535
, mComposerRect1( 0 )
3636
, mComposerRect2( 0 )
37-
, mMapSettings( 0 )
3837
{}
3938

4039
private slots:
@@ -49,7 +48,6 @@ class TestQgsComposerEffects : public QObject
4948
QgsComposition* mComposition;
5049
QgsComposerShape *mComposerRect1;
5150
QgsComposerShape *mComposerRect2;
52-
QgsMapSettings *mMapSettings;
5351
QString mReport;
5452
};
5553

@@ -58,11 +56,9 @@ void TestQgsComposerEffects::initTestCase()
5856
QgsApplication::init();
5957
QgsApplication::initQgis();
6058

61-
mMapSettings = new QgsMapSettings();
62-
6359
//create composition with two rectangles
6460

65-
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
61+
mComposition = new QgsComposition( QgsProject::instance() );
6662
mComposition->setPaperSize( 297, 210 ); //A4 landscape
6763
mComposerRect1 = new QgsComposerShape( 20, 20, 150, 100, mComposition );
6864
mComposerRect1->setShapeType( QgsComposerShape::Rectangle );
@@ -79,7 +75,6 @@ void TestQgsComposerEffects::initTestCase()
7975
void TestQgsComposerEffects::cleanupTestCase()
8076
{
8177
delete mComposition;
82-
delete mMapSettings;
8378

8479
QString myReportFile = QDir::tempPath() + "/qgistest.html";
8580
QFile myFile( myReportFile );

tests/src/core/testqgscomposergroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void TestQgsComposerGroup::initTestCase()
8181
QgsApplication::initQgis();
8282

8383
mMapSettings = new QgsMapSettings();
84-
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
84+
mComposition = new QgsComposition( QgsProject::instance() );
8585
mComposition->setPaperSize( 297, 210 ); //A4 landscape
8686

8787
//create some items

tests/src/core/testqgscomposerhtml.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,12 @@ class TestQgsComposerHtml : public QObject
5151

5252
private:
5353
QgsComposition *mComposition;
54-
QgsMapSettings *mMapSettings;
5554
QString mReport;
5655
QFont mTestFont;
5756
};
5857

5958
TestQgsComposerHtml::TestQgsComposerHtml()
6059
: mComposition( 0 )
61-
, mMapSettings( 0 )
6260
{
6361

6462
}
@@ -68,8 +66,7 @@ void TestQgsComposerHtml::initTestCase()
6866
QgsApplication::init();
6967
QgsApplication::initQgis();
7068

71-
mMapSettings = new QgsMapSettings();
72-
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
69+
mComposition = new QgsComposition( QgsProject::instance() );
7370
mComposition->setPaperSize( 297, 210 ); //A4 landscape
7471

7572
mReport = QStringLiteral( "<h1>Composer HTML Tests</h1>\n" );
@@ -81,7 +78,6 @@ void TestQgsComposerHtml::initTestCase()
8178
void TestQgsComposerHtml::cleanupTestCase()
8279
{
8380
delete mComposition;
84-
delete mMapSettings;
8581

8682
QString myReportFile = QDir::tempPath() + "/qgistest.html";
8783
QFile myFile( myReportFile );

0 commit comments

Comments
 (0)