Skip to content
Permalink
Browse files

Remove map settings parameter from QgsComposition

Breaks the hard link between canvas and compositions!

Fix #11077
  • Loading branch information
nyalldawson committed Jan 24, 2017
1 parent b41f3a7 commit a188d14f48c1f8e03ce0b59aee96c5c9f4f7818e
Showing with 126 additions and 236 deletions.
  1. +5 −1 doc/api_break.dox
  2. +1 −5 python/core/composer/qgscomposition.sip
  3. +2 −2 src/app/composer/qgscomposer.cpp
  4. +1 −2 src/core/composer/qgscomposition.cpp
  5. +4 −8 src/core/composer/qgscomposition.h
  6. +2 −2 src/plugins/georeferencer/qgsgeorefplugingui.cpp
  7. +4 −1 src/server/qgswmsprojectparser.cpp
  8. +2 −1 tests/src/core/testqgs25drenderer.cpp
  9. +4 −11 tests/src/core/testqgsatlascomposition.cpp
  10. +1 −10 tests/src/core/testqgscomposerdd.cpp
  11. +1 −6 tests/src/core/testqgscomposereffects.cpp
  12. +1 −1 tests/src/core/testqgscomposergroup.cpp
  13. +1 −5 tests/src/core/testqgscomposerhtml.cpp
  14. +1 −8 tests/src/core/testqgscomposerlabel.cpp
  15. +9 −15 tests/src/core/testqgscomposermap.cpp
  16. +1 −1 tests/src/core/testqgscomposermapgrid.cpp
  17. +8 −8 tests/src/core/testqgscomposermapoverview.cpp
  18. +1 −5 tests/src/core/testqgscomposermodel.cpp
  19. +1 −5 tests/src/core/testqgscomposermultiframe.cpp
  20. +1 −5 tests/src/core/testqgscomposerobject.cpp
  21. +1 −5 tests/src/core/testqgscomposerpaper.cpp
  22. +1 −6 tests/src/core/testqgscomposerpicture.cpp
  23. +3 −9 tests/src/core/testqgscomposerrotation.cpp
  24. +2 −7 tests/src/core/testqgscomposerscalebar.cpp
  25. +1 −6 tests/src/core/testqgscomposershapes.cpp
  26. +1 −10 tests/src/core/testqgscomposertablev2.cpp
  27. +2 −8 tests/src/core/testqgscomposerutils.cpp
  28. +12 −26 tests/src/core/testqgscomposition.cpp
  29. +2 −4 tests/src/core/testqgspainteffect.cpp
  30. +14 −13 tests/src/python/test_qgsatlascomposition.py
  31. +1 −1 tests/src/python/test_qgscomposereffects.py
  32. +1 −1 tests/src/python/test_qgscomposerhtml.py
  33. +2 −2 tests/src/python/test_qgscomposeritem.py
  34. +1 −1 tests/src/python/test_qgscomposerlabel.py
  35. +10 −6 tests/src/python/test_qgscomposerlegend.py
  36. +8 −5 tests/src/python/test_qgscomposermap.py
  37. +1 −1 tests/src/python/test_qgscomposermapgrid.py
  38. +3 −6 tests/src/python/test_qgscomposerpicture.py
  39. +1 −3 tests/src/python/test_qgscomposerpolygon.py
  40. +1 −3 tests/src/python/test_qgscomposerpolyline.py
  41. +1 −3 tests/src/python/test_qgscomposershapes.py
  42. +4 −7 tests/src/python/test_qgscomposition.py
  43. +2 −1 tests/src/python/test_qgspallabeling_composer.py
@@ -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.
@@ -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}
@@ -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
@@ -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 );

@@ -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 );
@@ -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 )
{
@@ -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 )
{
@@ -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
@@ -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; }

@@ -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;
@@ -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 );
@@ -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 );
@@ -26,6 +26,7 @@
#include "qgspallabeling.h"
#include "qgsrenderer.h"
#include "qgsvectorlayer.h"
#include "qgsmapsettings.h"

#include "qgscomposition.h"
#include "qgscomposerarrow.h"
@@ -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;
@@ -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;
}
@@ -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() );
@@ -43,7 +43,6 @@ class TestQgsAtlasComposition : public QObject
, mLabel2( 0 )
, mAtlasMap( 0 )
, mOverview( 0 )
, mMapSettings( 0 )
, mVectorLayer( 0 )
, mVectorLayer2( 0 )
, mAtlas( 0 )
@@ -84,7 +83,6 @@ class TestQgsAtlasComposition : public QObject
QgsComposerLabel* mLabel2;
QgsComposerMap* mAtlasMap;
QgsComposerMap* mOverview;
QgsMapSettings *mMapSettings;
QgsVectorLayer* mVectorLayer;
QgsVectorLayer* mVectorLayer2;
QgsAtlasComposition* mAtlas;
@@ -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(),
@@ -115,9 +111,7 @@ void TestQgsAtlasComposition::initTestCase()
}

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


void TestQgsAtlasComposition::cleanupTestCase()
@@ -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
@@ -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 );
@@ -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 ) );

@@ -38,7 +38,6 @@ class TestQgsComposerDD : public QObject
public:
TestQgsComposerDD()
: mComposition( 0 )
, mMapSettings( 0 )
, mVectorLayer( 0 )
, mAtlasMap( 0 )
, mAtlas( 0 )
@@ -54,7 +53,6 @@ class TestQgsComposerDD : public QObject

private:
QgsComposition *mComposition;
QgsMapSettings *mMapSettings;
QgsVectorLayer* mVectorLayer;
QgsComposerMap* mAtlasMap;
QgsAtlasComposition* mAtlas;
@@ -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(),
@@ -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
@@ -114,7 +106,6 @@ void TestQgsComposerDD::initTestCase()
void TestQgsComposerDD::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;
delete mVectorLayer;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
@@ -34,7 +34,6 @@ class TestQgsComposerEffects : public QObject
: mComposition( 0 )
, mComposerRect1( 0 )
, mComposerRect2( 0 )
, mMapSettings( 0 )
{}

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

@@ -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 );
@@ -79,7 +75,6 @@ void TestQgsComposerEffects::initTestCase()
void TestQgsComposerEffects::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;

QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
@@ -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
@@ -51,14 +51,12 @@ class TestQgsComposerHtml : public QObject

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

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

}
@@ -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" );
@@ -81,7 +78,6 @@ void TestQgsComposerHtml::initTestCase()
void TestQgsComposerHtml::cleanupTestCase()
{
delete mComposition;
delete mMapSettings;

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

0 comments on commit a188d14

Please sign in to comment.
You can’t perform that action at this time.