Skip to content

Commit

Permalink
Remove map settings parameter from QgsComposition
Browse files Browse the repository at this point in the history
Breaks the hard link between canvas and compositions!

Fix #11077
  • Loading branch information
nyalldawson committed Jan 24, 2017
1 parent b41f3a7 commit a188d14
Show file tree
Hide file tree
Showing 43 changed files with 126 additions and 236 deletions.
6 changes: 5 additions & 1 deletion doc/api_break.dox
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,10 @@ to use the QgsProperty framework objects.
QgsComposition {#qgis_api_break_3_0_QgsComposition}
--------------

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


QgsCoordinateReferenceSystem {#qgis_api_break_3_0_QgsCoordinateReferenceSystem}
Expand Down
6 changes: 1 addition & 5 deletions python/core/composer/qgscomposition.sip
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class QgsComposition : QGraphicsScene, QgsExpressionContextGenerator
Landscape
};

explicit QgsComposition( const QgsMapSettings& mapSettings, QgsProject* project );
explicit QgsComposition( QgsProject* project );

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

//! Return setting of QGIS map canvas
//! @note added in 2.4
const QgsMapSettings& mapSettings() const;

QgsComposition::PlotStyle plotStyle() const;
void setPlotStyle( const QgsComposition::PlotStyle style );

Expand Down
4 changes: 2 additions & 2 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
connect( mActionShowRulers, SIGNAL( triggered( bool ) ), this, SLOT( toggleRulers( bool ) ) );

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

mActionUndo->setEnabled( false );
mActionRedo->setEnabled( false );
Expand Down Expand Up @@ -3560,7 +3560,7 @@ void QgsComposer::readXml( const QDomElement& composerElem, const QDomDocument&
createComposerView();

//read composition settings
mComposition = new QgsComposition( mQgis->mapCanvas()->mapSettings(), QgsProject::instance() );
mComposition = new QgsComposition( QgsProject::instance() );
QDomNodeList compositionNodeList = composerElem.elementsByTagName( QStringLiteral( "Composition" ) );
if ( compositionNodeList.size() > 0 )
{
Expand Down
3 changes: 1 addition & 2 deletions src/core/composer/qgscomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@
#include "gdal.h"
#include "cpl_conv.h"

QgsComposition::QgsComposition( const QgsMapSettings& mapSettings, QgsProject* project )
QgsComposition::QgsComposition( QgsProject* project )
: QGraphicsScene( nullptr )
, mMapSettings( mapSettings )
, mProject( project )
, mAtlasComposition( this )
{
Expand Down
12 changes: 4 additions & 8 deletions src/core/composer/qgscomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo
Landscape
};

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

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

//! Return setting of QGIS map canvas
//! @note added in 2.4
const QgsMapSettings& mapSettings() const { return mMapSettings; }

QgsComposition::PlotStyle plotStyle() const { return mPlotStyle; }
void setPlotStyle( const QgsComposition::PlotStyle style ) { mPlotStyle = style; }

Expand Down Expand Up @@ -862,8 +860,6 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene, public QgsExpressionCo


private:
//! Reference to map settings of QGIS main map
const QgsMapSettings& mMapSettings;

//! Pointer to associated project (not null)
QgsProject* mProject;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ bool QgsGeorefPluginGui::writePDFMapFile( const QString& fileName, const QgsGeor
double paperHeight = s.value( QStringLiteral( "/Plugin-GeoReferencer/Config/HeightPDFMap" ), "420" ).toDouble();

//create composition
QgsComposition* composition = new QgsComposition( mCanvas->mapSettings(), QgsProject::instance() );
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
if ( mapRatio >= 1 )
{
composition->setPaperSize( paperHeight, paperWidth );
Expand Down Expand Up @@ -1589,7 +1589,7 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
}

//create composition A4 with 300 dpi
QgsComposition* composition = new QgsComposition( mCanvas->mapSettings(), QgsProject::instance() );
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
composition->setPaperSize( 210, 297 ); //A4
composition->setPrintResolution( 300 );
composition->setNumPages( 2 );
Expand Down
5 changes: 4 additions & 1 deletion src/server/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgspallabeling.h"
#include "qgsrenderer.h"
#include "qgsvectorlayer.h"
#include "qgsmapsettings.h"

#include "qgscomposition.h"
#include "qgscomposerarrow.h"
Expand Down Expand Up @@ -475,7 +476,7 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem
return nullptr;
}

QgsComposition* composition = new QgsComposition( mapSettings, QgsProject::instance() ); //set resolution, paper size from composer element attributes
QgsComposition* composition = new QgsComposition( QgsProject::instance() ); //set resolution, paper size from composer element attributes
if ( !composition->readXml( compositionElem, *( mProjectParser->xmlDocument() ) ) )
{
delete composition;
Expand Down Expand Up @@ -503,6 +504,8 @@ QgsComposition* QgsWmsProjectParser::initComposition( const QString& composerTem
QgsComposerMap* map = qobject_cast< QgsComposerMap *>( *itemIt );
if ( map )
{
if ( !map->keepLayerSet() )
map->setLayers( mapSettings.layers() );
mapList.push_back( map );
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/src/core/testqgs25drenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ void TestQgs25DRenderer::render()

void TestQgs25DRenderer::renderComposition()
{
QgsComposition* composition = new QgsComposition( mMapSettings, QgsProject::instance() );
QgsComposition* composition = new QgsComposition( QgsProject::instance() );
composition->setPaperSize( 297, 210 ); //A4 landscape
QgsComposerMap* map = new QgsComposerMap( composition, 20, 20, 200, 100 );
map->setFrameEnabled( true );
map->setLayers( QList< QgsMapLayer* >() << mpPolysLayer );
composition->addComposerMap( map );

map->setNewExtent( mpPolysLayer->extent() );
Expand Down
15 changes: 4 additions & 11 deletions tests/src/core/testqgsatlascomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class TestQgsAtlasComposition : public QObject
, mLabel2( 0 )
, mAtlasMap( 0 )
, mOverview( 0 )
, mMapSettings( 0 )
, mVectorLayer( 0 )
, mVectorLayer2( 0 )
, mAtlas( 0 )
Expand Down Expand Up @@ -84,7 +83,6 @@ class TestQgsAtlasComposition : public QObject
QgsComposerLabel* mLabel2;
QgsComposerMap* mAtlasMap;
QgsComposerMap* mOverview;
QgsMapSettings *mMapSettings;
QgsVectorLayer* mVectorLayer;
QgsVectorLayer* mVectorLayer2;
QgsAtlasComposition* mAtlas;
Expand All @@ -96,8 +94,6 @@ void TestQgsAtlasComposition::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();

mMapSettings = new QgsMapSettings();

//create maplayers from testdata and add to layer registry
QFileInfo vectorFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/france_parts.shp" );
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
Expand All @@ -115,9 +111,7 @@ void TestQgsAtlasComposition::initTestCase()
}

TestQgsAtlasComposition::~TestQgsAtlasComposition()
{
delete mMapSettings;
}
{}


void TestQgsAtlasComposition::cleanupTestCase()
Expand All @@ -139,15 +133,12 @@ void TestQgsAtlasComposition::cleanupTestCase()
void TestQgsAtlasComposition::init()
{
//create composition with composer map
mMapSettings->setLayers( QList<QgsMapLayer*>() << mVectorLayer );
mMapSettings->setCrsTransformEnabled( true );
mMapSettings->setMapUnits( QgsUnitTypes::DistanceMeters );

// select epsg:2154
QgsCoordinateReferenceSystem crs;
crs.createFromSrid( 2154 );
QgsProject::instance()->setCrs( crs );
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
mComposition = new QgsComposition( QgsProject::instance() );
mComposition->setPaperSize( 297, 210 ); //A4 landscape

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

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

Expand Down
11 changes: 1 addition & 10 deletions tests/src/core/testqgscomposerdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class TestQgsComposerDD : public QObject
public:
TestQgsComposerDD()
: mComposition( 0 )
, mMapSettings( 0 )
, mVectorLayer( 0 )
, mAtlasMap( 0 )
, mAtlas( 0 )
Expand All @@ -54,7 +53,6 @@ class TestQgsComposerDD : public QObject

private:
QgsComposition *mComposition;
QgsMapSettings *mMapSettings;
QgsVectorLayer* mVectorLayer;
QgsComposerMap* mAtlasMap;
QgsAtlasComposition* mAtlas;
Expand All @@ -66,8 +64,6 @@ void TestQgsComposerDD::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();

mMapSettings = new QgsMapSettings();

//create maplayers from testdata and add to layer registry
QFileInfo vectorFileInfo( QStringLiteral( TEST_DATA_DIR ) + "/france_parts.shp" );
mVectorLayer = new QgsVectorLayer( vectorFileInfo.filePath(),
Expand All @@ -79,15 +75,11 @@ void TestQgsComposerDD::initTestCase()
mVectorLayer->setSimplifyMethod( simplifyMethod );

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

// select epsg:2154
QgsCoordinateReferenceSystem crs;
crs.createFromSrid( 2154 );
mMapSettings->setDestinationCrs( crs );
mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
mComposition = new QgsComposition( QgsProject::instance() );
mComposition->setPaperSize( 297, 210 ); //A4 landscape

// fix the renderer, fill with green
Expand All @@ -114,7 +106,6 @@ void TestQgsComposerDD::initTestCase()
void TestQgsComposerDD::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
delete mVectorLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
Expand Down
7 changes: 1 addition & 6 deletions tests/src/core/testqgscomposereffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class TestQgsComposerEffects : public QObject
: mComposition( 0 )
, mComposerRect1( 0 )
, mComposerRect2( 0 )
, mMapSettings( 0 )
{}

private slots:
Expand All @@ -49,7 +48,6 @@ class TestQgsComposerEffects : public QObject
QgsComposition* mComposition;
QgsComposerShape *mComposerRect1;
QgsComposerShape *mComposerRect2;
QgsMapSettings *mMapSettings;
QString mReport;
};

Expand All @@ -58,11 +56,9 @@ void TestQgsComposerEffects::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();

mMapSettings = new QgsMapSettings();

//create composition with two rectangles

mComposition = new QgsComposition( *mMapSettings, QgsProject::instance() );
mComposition = new QgsComposition( QgsProject::instance() );
mComposition->setPaperSize( 297, 210 ); //A4 landscape
mComposerRect1 = new QgsComposerShape( 20, 20, 150, 100, mComposition );
mComposerRect1->setShapeType( QgsComposerShape::Rectangle );
Expand All @@ -79,7 +75,6 @@ void TestQgsComposerEffects::initTestCase()
void TestQgsComposerEffects::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgscomposergroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void TestQgsComposerGroup::initTestCase()
QgsApplication::initQgis();

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

//create some items
Expand Down
6 changes: 1 addition & 5 deletions tests/src/core/testqgscomposerhtml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ class TestQgsComposerHtml : public QObject

private:
QgsComposition *mComposition;
QgsMapSettings *mMapSettings;
QString mReport;
QFont mTestFont;
};

TestQgsComposerHtml::TestQgsComposerHtml()
: mComposition( 0 )
, mMapSettings( 0 )
{

}
Expand All @@ -68,8 +66,7 @@ void TestQgsComposerHtml::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();

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

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

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

0 comments on commit a188d14

Please sign in to comment.